package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
)

func main() {
	var a [6]int
	for i := 1; i <= 4; i++ {
		fmt.Scanf("%d", &a[i])
	}

	seq, ok := findEulerianPath(a)
	if !ok {
		fmt.Println("NO")
		return
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	fmt.Fprintf(w, "YES\n")
	for _, e := range seq {
		fmt.Fprintf(w, "%d ", e-1)
	}
	fmt.Fprintln(w)
}

func findEulerianPath(a [6]int) ([]int, bool) {
	tot := 0
	for _, e := range a {
		tot += e
	}

	for st := 1; st <= 4; st++ {
		for end := st; end <= 4; end++ {
			var in, out [6]int
			for i := 1; i <= 4; i++ {
				in[i] = a[i]
				if i == st {
					in[i]--
				}
				out[i] = a[i]
				if i == end {
					out[i]--
				}
			}
			l, r := make([]int, 6), make([]int, 6)
			for i := 1; i <= 3; i++ {
				r[i] = out[i] - l[i]
				l[i+1] = in[i] - r[i-1]
			}
			p := findPath(st, l, r)
			var b [6]int
			for _, e := range p {
				b[e]++
			}
			if reflect.DeepEqual(a, b) {
				return p, true
			}
		}
	}
	return nil, false
}

func findPath(s int, l, r []int) []int {
	var p []int
	cc := 0
	for l[s] > 0 || r[s] > 0 {
		cc++
		switch {
		case l[s] > 0 && r[s-1] > 0:
			l[s]--
			p = findPath(s-1, l, r)
		case r[s] > 0 && l[s+1] > 0:
			r[s]--
			p = findPath(s+1, l, r)
		case l[s] > 0:
			l[s]--
			p = findPath(s-1, l, r)
		case r[s] > 0:
			r[s]--
			p = findPath(s+1, l, r)
		}
	}
	p = append(p, s)
	return p
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	cnt := io.NextInts(4)

	n := cnt[0] + cnt[1] + cnt[2] + cnt[3]

	// io.Println(cnt)

	for i := 0; i < 4; i++ {
		if cnt[i] != 0 {
			T := []int{cnt[0], cnt[1], cnt[2], cnt[3]}
			T[i]--
			prv := i
			rem := n - 1
			R := []int{i}
			for rem != 0 {
				if prv > 0 && T[prv-1] != 0 {
					T[prv-1]--
					R = append(R, prv-1)
					prv--
				} else if prv < 3 && T[prv+1] != 0 {
					T[prv+1]--
					R = append(R, prv+1)
					prv++
				} else {
					break
				}
				rem--
			}
			// io.Println(i, len(R), cnt)
			if len(R) == n {
				io.Println("YES")
				for j := 0; j < n; j++ {
					io.Print(R[j], " ")
				}
				io.Println()
				return
			}
		}
	}
	io.Println("NO")
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const LEN = int(2e5)

type be struct {
	a, b, c, d, f int
}
var mp map[be]int

func r(a, b, c, d, f int) int {
	key := be{a: a, b:b, c:c, d:d, f:f}
	if v, ok := mp[key]; ok {
		return v
	}
	switch f {
	case 0:
		if a <= 0 {
			mp[key] = -2
			return -2
		}
	case 1:
		if b <= 0 {
			mp[key] = -2
			return -2
		}
	case 2:
		if c <= 0 {
			mp[key] = -2
			return -2
		}
	case 3:
		if d <= 0 {
			mp[key] = -2
			return -2
		}
	}
	if a + b + c + d == 1 {
		mp[key] = -1
		return -1
	}
	if f == 0 {
		if b < a - 1 {
			mp[key] = -2
			return -2
		}
		t := r(a - 1, b, c, d, 1)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 1
		}
		return mp[key]
	} else if f == 1 {
		t := r(a, b - 1, c, d, 0)
		if t != -2 {
			mp[key] = 0
			return 0
		}
		t = r(a, b - 1, c, d, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	} else if f == 2 {
		t := r(a, b, c - 1, d, 1)
		if t != -2 {
			mp[key] = 1
			return 1
		}
		t = r(a, b, c - 1, d, 3)

		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 3
		}
		return mp[key]
	} else {
		t := r(a, b, c, d - 1, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	}
}

func f() {
	//  0  1  2  3
	var a, b, c, d int
	scanf("%d%d%d%d\n", &a, &b, &c, &d)
	if d == 0 {
		if b == a + c - 1 {
			printf("YES\n")
			if a > 0 {
				printf("0 ")
				a--
				for a > 0 {
					printf("1 0 ")
					a--
				}
				for c > 0 {
					printf("1 2 ")
					c--
				}
			} else {
				printf("2 ")
				c--
				for c > 0 {
					printf("1 2 ")
					c--
				}
			}
			printf("\n")
		} else if b == a + c || b == a + c + 1 {
			flag := b == a + c + 1
			printf("YES\n")
			for a > 0 {
				printf("1 0 ")
				a--
			}
			for c > 0 {
				printf("1 2 ")
				c--
			}
			if flag {
				printf("1")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}

	} else if c > d {
		if c - d + a + 1 == b || c - d + a == b {
			printf("YES\n")
			for d > 0 {
				d--
				c--
				printf("3 2 ")
			}
			for c > 0 {
				c--
				b--
				printf("1 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			if b > 0 {
				printf("1")
			}
			printf("\n")
		} else if c - d - 1 + a == b {
			printf("YES\n2 ")
			c--
			for d > 0 {
				d--
				c--
				printf("3 2 ")
			}
			for c > 0 {
				b--
				c--
				printf("1 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}
	} else if c == d {
		if b == a + 1 || b == a {
			printf("YES\n")
			for d > 0 {
				d--
				printf("3 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			if b > 0 {
				printf("1")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}

	} else if c == d - 1 {
		if a + b > 0 {
			printf("NO\n")
		} else {
			printf("YES\n3 ")
			for c > 0 {
				c--
				printf("2 3 ")
			}
			printf("\n")
		}
	} else {
		printf("NO\n")
	}

}

func main() {
	defer writer.Flush()

	f()
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var A map[int]int

func main() {
	a, b, c, d := ReadInt4()
	total := a + b + c + d

	for i := 0; i < 4; i++ {
		A = make(map[int]int)
		A[0], A[1], A[2], A[3] = a, b, c, d
		answers := []int{}

		if A[i] > 0 {
			last := i
			answers = append(answers, last)
			A[last]--
			for {
				if A[last-1] > 0 {
					A[last-1]--
					answers = append(answers, last-1)
					last--
				} else if A[last+1] > 0 {
					A[last+1]--
					answers = append(answers, last+1)
					last++
				} else {
					break
				}
			}

			if len(answers) == total {
				fmt.Println("YES")
				fmt.Println(PrintIntsLine(answers...))
				return
			}
		}
	}

	fmt.Println("NO")
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func Sol1265D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	n := 0
	aa := [2][4]int{}
	for i := range aa[0] {
		Fscan(in, &aa[0][i])
		aa[1][3-i] = aa[0][i]
		n += aa[0][i]
	}
	for order, a := range aa {
		even := a[0] + a[2]
		odd := n - even
		if even != odd && even-1 != odd {
			continue
		}
		b := make([]int, n)
		for i := 0; i < n; i += 2 {
			if a[0] > 0 {
				a[0]--
			} else if a[2] > 0 {
				a[2]--
				b[i] = 2
			}
		}
		for i := 1; i < n; i += 2 {
			if a[1] > 0 {
				a[1]--
				b[i] = 1
			} else if a[3] > 0 {
				a[3]--
				b[i] = 3
			}
		}
		ok := true
		for i := 1; i < n; i++ {
			if b[i]-b[i-1] != 1 && b[i]-b[i-1] != -1 {
				ok = false
				break
			}
		}
		if ok {
			Fprintln(out, "YES")
			for _, v := range b {
				if order == 0 {
					Fprint(out, v, " ")
				} else {
					Fprint(out, 3-v, " ")
				}
			}
			return
		}
	}
	Fprint(out, "NO")
}

func main() {
	Sol1265D(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader=bufio.NewReader(os.Stdin)
var writer *bufio.Writer=bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}){fmt.Fprintf(writer,f,a...)}
func scanf(f string,a...interface{}){fmt.Fscanf(reader,f,a...)}

func abs(x int)int{if x<0 {return -x}else {return x}}

func main(){
	defer writer.Flush()
	var a,b,c,d int
	scanf("%d%d%d%d\n",&a,&b,&c,&d)
	sum:=a+b+c+d
	if abs(a-b+c-d)>1{printf("NO\n");return}
	fst:=false
	if a+c-b-d==-1{
		if b<a+1 && a!=0 {printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=b{printf("1")}else{printf("3")}
			}else{
				if i/2<=a{printf("0")}else{printf("2")}
			}
		}
		printf("\n")
	}else{
		if a>b && d!=0 {printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=a{printf("0")}else{printf("2")}
			}else{
				if i/2<=b{printf("1")}else{printf("3")}
			}
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	cnt := io.NextInts(4)

	n := cnt[0] + cnt[1] + cnt[2] + cnt[3]

	for i := 0; i < 4; i++ {
		if cnt[i] != 0 {
			T := cnt
			T[i]--
			prv := i
			rem := n - 1
			R := []int{i}
			for rem != 0 {
				if prv > 0 && T[prv-1] != 0 {
					T[prv-1]--
					R = append(R, prv-1)
					prv--
				} else if prv < 3 && T[prv+1] != 0 {
					T[prv+1]--
					R = append(R, prv+1)
					prv++
				} else {
					break
				}
				rem--
			}
			if len(R) == n {
				io.Println("YES")
				for i := 0; i < n; i++ {
					io.Print(R[i], " ")
				}
				io.Println()
				return
			}
		}
	}
	io.Println("NO")
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var a [6]int
	for i := 1; i <= 4; i++ {
		fmt.Scanf("%d", &a[i])
	}

	seq, ok := findEulerianPath(a)
	if !ok {
		fmt.Println("NO")
		return
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	fmt.Fprintf(w, "YES\n")
	for _, e := range seq {
		fmt.Fprintf(w, "%d ", e-1)
	}
	fmt.Fprintln(w)
}

func findEulerianPath(a [6]int) ([]int, bool) {
	tot := 0
	for _, e := range a {
		tot += e
	}

	for st := 1; st <= 4; st++ {
		for end := st; end <= 4; end++ {
			var in, out [6]int
			for i := 1; i <= 4; i++ {
				in[i] = a[i]
				if i == st {
					in[i]--
				}
				out[i] = a[i]
				if i == end {
					out[i]--
				}
			}
			l, r := make([]int, 6), make([]int, 6)
			for i := 1; i <= 3; i++ {
				r[i] = out[i] - l[i]
				l[i+1] = in[i] - r[i-1]
			}
			p := findPath(st, l, r)
			if len(p) == tot {
				return p, true
			}
		}
	}
	return nil, false
}

func findPath(s int, l, r []int) []int {
	var p []int
	cc := 0
	for l[s] > 0 || r[s] > 0 {
		cc++
		switch {
		case l[s] > 0 && r[s-1] > 0:
			l[s]--
			p = findPath(s-1, l, r)
		case r[s] > 0 && l[s+1] > 0:
			r[s]--
			p = findPath(s+1, l, r)
		case l[s] > 0:
			l[s]--
			p = findPath(s-1, l, r)
		case r[s] > 0:
			r[s]--
			p = findPath(s+1, l, r)
		}
	}
	p = append(p, s)
	return p
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
)

func main() {
	var a [6]int
	for i := 1; i <= 4; i++ {
		fmt.Scanf("%d", &a[i])
	}

	seq, ok := findEulerianPath(a)
	if !ok {
		fmt.Println("NO")
		return
	}

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	fmt.Fprintf(w, "YES\n")
	for _, e := range seq {
		fmt.Fprintf(w, "%d ", e-1)
	}
	fmt.Fprintln(w)
}

func findEulerianPath(a [6]int) ([]int, bool) {
	tot := 0
	for _, e := range a {
		tot += e
	}

	for st := 1; st <= 4; st++ {
		for end := st; end <= 4; end++ {
			var in, out [6]int
			for i := 1; i <= 4; i++ {
				in[i] = a[i]
				if i == st {
					in[i]--
				}
				out[i] = a[i]
				if i == end {
					out[i]--
				}
			}
			l, r := make([]int, 6), make([]int, 6)
			for i := 1; i <= 3; i++ {
				r[i] = out[i] - l[i]
				l[i+1] = in[i] - r[i-1]
			}
			p := findPath(st, l, r)
			var b [6]int
			for _, e := range b {
				b[e]++
			}
			if reflect.DeepEqual(a, b) {
				return p, true
			}
		}
	}
	return nil, false
}

func findPath(s int, l, r []int) []int {
	var p []int
	cc := 0
	for l[s] > 0 || r[s] > 0 {
		cc++
		switch {
		case l[s] > 0 && r[s-1] > 0:
			l[s]--
			p = findPath(s-1, l, r)
		case r[s] > 0 && l[s+1] > 0:
			r[s]--
			p = findPath(s+1, l, r)
		case l[s] > 0:
			l[s]--
			p = findPath(s-1, l, r)
		case r[s] > 0:
			r[s]--
			p = findPath(s+1, l, r)
		}
	}
	p = append(p, s)
	return p
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const LEN = int(2e5)

type be struct {
	a, b, c, d, f int
}
var mp map[be]int

func r(a, b, c, d, f int) int {
	key := be{a: a, b:b, c:c, d:d, f:f}
	if v, ok := mp[key]; ok {
		return v
	}
	switch f {
	case 0:
		if a <= 0 {
			mp[key] = -2
			return -2
		}
	case 1:
		if b <= 0 {
			mp[key] = -2
			return -2
		}
	case 2:
		if c <= 0 {
			mp[key] = -2
			return -2
		}
	case 3:
		if d <= 0 {
			mp[key] = -2
			return -2
		}
	}
	if a + b + c + d == 1 {
		mp[key] = -1
		return -1
	}
	if f == 0 {
		if b < a - 1 {
			mp[key] = -2
			return -2
		}
		t := r(a - 1, b, c, d, 1)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 1
		}
		return mp[key]
	} else if f == 1 {
		t := r(a, b - 1, c, d, 0)
		if t != -2 {
			mp[key] = 0
			return 0
		}
		t = r(a, b - 1, c, d, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	} else if f == 2 {
		t := r(a, b, c - 1, d, 1)
		if t != -2 {
			mp[key] = 1
			return 1
		}
		t = r(a, b, c - 1, d, 3)

		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 3
		}
		return mp[key]
	} else {
		t := r(a, b, c, d - 1, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	}
}

func f() {
	//  0  1  2  3
	var a, b, c, d int
	scanf("%d%d%d%d\n", &a, &b, &c, &d)
	if d == 0 {
		if b == a + c - 1 {
			printf("YES\n")
			if a > 0 {
				printf("0 ")
				a--
				for a > 0 {
					printf("1 0 ")
					a--
				}
				for c > 0 {
					printf("1 2 ")
					c--
				}
			} else {
				printf("2 ")
				c--
				for c > 0 {
					printf("1 2 ")
					c--
				}
			}
			printf("\n")
		} else if b == a + c || b == a + c + 1 {
			printf("YES\n")
			for a > 0 {
				printf("1 0 ")
				a--
			}
			for c > 0 {
				printf("1 2 ")
				c--
			}
			if b == a + c + 1 {
				printf("1")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}

	} else if c > d {
		if c - d + a + 1 == b || c - d + a == b {
			printf("YES\n")
			for d > 0 {
				d--
				c--
				printf("3 2 ")
			}
			for c > 0 {
				c--
				b--
				printf("1 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			if b > 0 {
				printf("1")
			}
			printf("\n")
		} else if c - d - 1 + a == b {
			printf("YES\n2 ")
			c--
			for d > 0 {
				d--
				c--
				printf("3 2 ")
			}
			for c > 0 {
				b--
				c--
				printf("1 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}
	} else if c == d {
		if b == a + 1 || b == a {
			printf("YES\n")
			for d > 0 {
				d--
				printf("3 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			if b > 0 {
				printf("1")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}

	} else if c == d - 1 {
		if a + b > 0 {
			printf("NO\n")
		} else {
			printf("YES\n3 ")
			for c > 0 {
				c--
				printf("2 3 ")
			}
			printf("\n")
		}
	} else {
		printf("NO\n")
	}

}

func main() {
	defer writer.Flush()

	f()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const LEN = int(2e5)

type be struct {
	a, b, c, d, f int
}
var mp map[be]int

func r(a, b, c, d, f int) int {
	key := be{a: a, b:b, c:c, d:d, f:f}
	if v, ok := mp[key]; ok {
		return v
	}
	switch f {
	case 0:
		if a <= 0 {
			mp[key] = -2
			return -2
		}
	case 1:
		if b <= 0 {
			mp[key] = -2
			return -2
		}
	case 2:
		if c <= 0 {
			mp[key] = -2
			return -2
		}
	case 3:
		if d <= 0 {
			mp[key] = -2
			return -2
		}
	}
	if a + b + c + d == 1 {
		mp[key] = -1
		return -1
	}
	if f == 0 {
		if b < a - 1 {
			mp[key] = -2
			return -2
		}
		t := r(a - 1, b, c, d, 1)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 1
		}
		return mp[key]
	} else if f == 1 {
		t := r(a, b - 1, c, d, 0)
		if t != -2 {
			mp[key] = 0
			return 0
		}
		t = r(a, b - 1, c, d, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	} else if f == 2 {
		t := r(a, b, c - 1, d, 1)
		if t != -2 {
			mp[key] = 1
			return 1
		}
		t = r(a, b, c - 1, d, 3)

		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 3
		}
		return mp[key]
	} else {
		t := r(a, b, c, d - 1, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	}
}

func f() {
	//  0  1  2  3
	var a, b, c, d int
	scanf("%d%d%d%d\n", &a, &b, &c, &d)
	if d == 0 {
		if b == a + c - 1 {
			printf("YES\n")
			if a > 0 {
				printf("0 ")
				a--
				for a > 0 {
					printf("1 0 ")
					a--
				}
				for c > 0 {
					printf("1 2 ")
					c--
				}
			} else {
				printf("2 ")
				c--
				for c > 0 {
					printf("1 2 ")
					c--
				}
			}
			printf("\n")
		} else if b == a + c || b == a + c + 1 {
			printf("YES\n")
			for a > 0 {
				printf("1 0 ")
				a--
			}
			for c > 0 {
				printf("1 2 ")
				c--
			}
			if b == a + c + 1 {
				printf("1")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}

	} else if c > d {
		if c - d + a + 1 == b || c - d + a == b {
			printf("YES\n")
			for d > 0 {
				d--
				c--
				printf("3 2 ")
			}
			for c > 0 {
				c--
				b--
				printf("1 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			if b > 0 {
				printf("1")
			}
			printf("\n")
		} else if c - d - 1 + a == b {
			printf("YES\n2 ")
			c--
			for d > 0 {
				d--
				c--
				printf("3 2 ")
			}
			for c > 0 {
				b--
				c--
				printf("1 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}
	} else if c == d {
		if b == a + 1 || b == a {
			printf("YES\n")
			for d > 0 {
				d--
				printf("3 2 ")
			}
			for a > 0 {
				a--
				b--
				printf("1 0 ")
			}
			if b > 0 {
				printf("1")
			}
			printf("\n")
		} else {
			printf("NO\n")
		}

	} else if c == d - 1 {
		if a + b > 0 {
			printf("NO\n")
		} else {
			printf("YES\n3")
			for c > 0 {
				c--
				printf("2 3 ")
			}
			printf("\n")
		}
	} else {
		printf("NO\n")
	}

}

func main() {
	defer writer.Flush()

	f()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const LEN = int(2e5)

type be struct {
	a, b, c, d, f int
}
var mp map[be]int

func r(a, b, c, d, f int) int {
	key := be{a: a, b:b, c:c, d:d, f:f}
	if v, ok := mp[key]; ok {
		return v
	}
	switch f {
	case 0:
		if a <= 0 {
			mp[key] = -2
			return -2
		}
	case 1:
		if b <= 0 {
			mp[key] = -2
			return -2
		}
	case 2:
		if c <= 0 {
			mp[key] = -2
			return -2
		}
	case 3:
		if d <= 0 {
			mp[key] = -2
			return -2
		}
	}
	if a + b + c + d == 1 {
		mp[key] = -1
		return -1
	}
	if f == 0 {
		if b < a - 1 {
			mp[key] = -2
			return -2
		}
		t := r(a - 1, b, c, d, 1)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 1
		}
		return mp[key]
	} else if f == 1 {
		t := r(a, b - 1, c, d, 0)
		if t != -2 {
			mp[key] = 0
			return 0
		}
		t = r(a, b - 1, c, d, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	} else if f == 2 {
		t := r(a, b, c - 1, d, 1)
		if t != -2 {
			mp[key] = 1
			return 1
		}
		t = r(a, b, c - 1, d, 3)

		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 3
		}
		return mp[key]
	} else {
		t := r(a, b, c, d - 1, 2)
		if t == -2 {
			mp[key] = -2
		} else {
			mp[key] = 2
		}
		return mp[key]
	}
}

func f() {
	mp = map[be]int{}
	var a, b, c, d int
	scanf("%d%d%d%d\n", &a, &b, &c, &d)
	if b < a - 1 || c < d - 1 || c + 1 == d && a + b > 0 || a == b + 1 && c + d > 0 {
		printf("NO\n")
		return
	}
	for i := 0; i < 4; i++ {
		fmt.Println(i)
		if r(a, b, c, d, i) != -2 {
			printf("YES\n%d", i)
			key := be{a:a, b:b, c:c, d:d, f:i}
			pre := i
			for mp[key] != -1 {
				printf(" %d", mp[key])
				nextPre := mp[key]
				switch pre {
				case 0:
					key = be{a: a - 1, b:b, c:c, d:d, f:mp[key]}
					a--
				case 1:
					key = be{a: a, b:b - 1, c:c, d:d, f:mp[key]}
					b--
				case 2:
					key = be{a: a, b:b, c:c - 1, d:d, f:mp[key]}
					c--
				case 3:
					key = be{a: a, b:b, c:c, d:d - 1, f:mp[key]}
					d--
				}
				pre = nextPre
			}
			printf("\n")
			return
		}
	}
	printf("NO\n")
}

func main() {
	defer writer.Flush()

	f()
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var A map[int]int

func main() {
	a, b, c, d := ReadInt4()
	total := a + b + c + d

	A = make(map[int]int)
	A[0], A[1], A[2], A[3] = a, b, c, d
	answers := []int{}
	if A[0] > 0 {
		last := 0
		answers = append(answers, last)
		A[last]--
		for {
			if A[last-1] > 0 {
				A[last-1]--
				answers = append(answers, last-1)
				last--
			} else if A[last+1] > 0 {
				A[last+1]--
				answers = append(answers, last+1)
				last++
			} else {
				break
			}
		}

		if len(answers) == total {
			fmt.Println("YES")
			fmt.Println(PrintIntsLine(answers...))
			return
		}
	}

	A = make(map[int]int)
	A[0], A[1], A[2], A[3] = a, b, c, d
	answers = []int{}
	if A[1] > 0 {
		last := 1
		answers = append(answers, last)
		A[last]--
		for {
			if A[last-1] > 0 {
				A[last-1]--
				answers = append(answers, last-1)
				last--
			} else if A[last+1] > 0 {
				A[last+1]--
				answers = append(answers, last+1)
				last++
			} else {
				break
			}
		}

		if len(answers) == total {
			fmt.Println("YES")
			fmt.Println(PrintIntsLine(answers...))
			return
		}
	}

	fmt.Println("NO")
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var a, b, c, d int

func main() {
	a, b, c, d = ReadInt4()

	oneNeeds := a + 1
	twoNeeds := d + 1

	// 1, 2が足りないとNO
	if a-1 > b {
		fmt.Println("NO")
		return
	}
	if d-1 > c {
		fmt.Println("NO")
		return
	}

	oneDiff := b - oneNeeds
	twoDiff := c - twoNeeds

	if oneDiff >= 0 && twoDiff >= 0 {
		// 両方とも非負
		diff := AbsInt(oneDiff - twoDiff)
		if diff < 2 {
			fmt.Println("YES")
			sub(oneDiff, twoDiff)
		} else {
			fmt.Println("NO")
		}
	} else {
		S := []int{}
		if oneDiff == -1 && twoDiff == 0 {
			fmt.Println("YES")
			for i := 0; i < a; i++ {
				S = append(S, 0, 1)
			}
			S = append(S, 2)
			for i := 0; i < d; i++ {
				S = append(S, 3, 2)
			}
			fmt.Println(PrintIntsLine(S...))
		} else if oneDiff == 0 && twoDiff == -1 {
			fmt.Println("YES")
			S = append(S, 1)
			for i := 0; i < a; i++ {
				S = append(S, 0, 1)
			}
			for i := 0; i < d; i++ {
				S = append(S, 2, 3)
			}
			fmt.Println(PrintIntsLine(S...))
		} else if oneDiff == -1 && twoDiff == -1 {
			fmt.Println("YES")
			for i := 0; i < a; i++ {
				S = append(S, 0, 1)
			}
			for i := 0; i < d; i++ {
				S = append(S, 2, 3)
			}
			fmt.Println(PrintIntsLine(S...))
		} else {
			fmt.Println("NO")
		}
	}
}

func sub(oneDiff, twoDiff int) {
	S := []int{}

	if oneDiff > twoDiff {
		// 101から
		for i := 0; i < oneDiff+twoDiff+2; i++ {
			if i%2 == 0 {
				S = append(S, 1, 0, 1)
			} else {
				S = append(S, 2, 3, 2)
			}
		}
	} else {
		// 232から
		for i := 0; i < oneDiff+twoDiff+2; i++ {
			if i%2 == 0 {
				S = append(S, 2, 3, 2)
			} else {
				S = append(S, 1, 0, 1)
			}
		}
	}

	pressed, _ := RunLengthEncoding(S)

	fmt.Println(PrintIntsLine(pressed...))
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader=bufio.NewReader(os.Stdin)
var writer *bufio.Writer=bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}){fmt.Fprintf(writer,f,a...)}
func scanf(f string,a...interface{}){fmt.Fscanf(reader,f,a...)}

func abs(x int)int{if x<0 {return -x}else {return x}}

func main(){
	defer writer.Flush()
	var a,b,c,d int
	scanf("%d%d%d%d\n",&a,&b,&c,&d)
	sum:=a+b+c+d
	if abs(a-b+c-d)>1{printf("NO\n");return}
	fst:=false
	if a+c-b-d==-1{
		if b<a+1 && a!=0 {printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=b{printf("1")}else{printf("3")}
			}else{
				if i/2<=a{printf("0")}else{printf("2")}
			}
		}
		printf("\n")
	}else{
		if a>b {printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=a{printf("0")}else{printf("2")}
			}else{
				if i/2<=b{printf("1")}else{printf("3")}
			}
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader=bufio.NewReader(os.Stdin)
var writer *bufio.Writer=bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}){fmt.Fprintf(writer,f,a...)}
func scanf(f string,a...interface{}){fmt.Fscanf(reader,f,a...)}

func abs(x int)int{if x<0 {return -x}else {return x}}

func main(){
	defer writer.Flush()
	var a,b,c,d int
	scanf("%d%d%d%d\n",&a,&b,&c,&d)
	sum:=a+b+c+d
	if abs(a-b+c-d)>1{printf("NO\n");return}
	fst:=false
	if a+c-b-d==-1{
		if b<a+1{printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=b{printf("1")}else{printf("3")}
			}else{
				if i/2<=a{printf("0")}else{printf("2")}
			}
		}
		printf("\n")
	}else{
		if a>b{printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=a{printf("0")}else{printf("2")}
			}else{
				if i/2<=b{printf("1")}else{printf("3")}
			}
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader=bufio.NewReader(os.Stdin)
var writer *bufio.Writer=bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}){fmt.Fprintf(writer,f,a...)}
func scanf(f string,a...interface{}){fmt.Fscanf(reader,f,a...)}

func abs(x int)int{if x<0 {return -x}else {return x}}

func main(){
	defer writer.Flush()
	var a,b,c,d int
	scanf("%d%d%d%d\n",&a,&b,&c,&d)
	sum:=a+b+c+d
	if abs(a-b+c-d)>1{printf("NO\n");return}
	fst:=false
	if a+c-b-d==-1{
		if b<a+1 || a!=0 {printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=b{printf("1")}else{printf("3")}
			}else{
				if i/2<=a{printf("0")}else{printf("2")}
			}
		}
		printf("\n")
	}else{
		if a>b {printf("NO\n");return}
		printf("YES\n")
		for i:=1;i<=sum;i++{
			if fst{printf(" ")}else{fst=true}
			if (i&1)==1{
				if (i+1)/2<=a{printf("0")}else{printf("2")}
			}else{
				if i/2<=b{printf("1")}else{printf("3")}
			}
		}
		printf("\n")
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		r1 := make([]int, m)
		for i := 0; i < m; i += 4 {
			r1[i] = 1
		}
		for i := 3; i < m; i += 4 {
			r1[i] = 1
		}
		r2 := make([]int, m)
		for i := 1; i < m; i += 4 {
			r2[i] = 1
		}
		for i := 2; i < m; i += 4 {
			r2[i] = 1
		}

		mat := make([][]int, n)
		mat[0] = r1
		for i := 1; i < n; i += 4 {
			mat[i] = r2
		}
		for i := 2; i < n; i += 4 {
			mat[i] = r2
		}
		for i := 3; i < n; i += 4 {
			mat[i] = r1
		}
		for i := 4; i < n; i += 4 {
			mat[i] = r1
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				fmt.Fprint(out, mat[i][j], " ")
			}
			fmt.Fprintln(out)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; return res }

func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}

func ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi()
		r0,r1 := ia(M),ia(M); for i:=0;i<M;i++ { if i%4 == 1 || i%4 == 2 { r0[i] = 1 } else { r1[i] = 1 } }
		s0 := vecintstring(r0)
		s1 := vecintstring(r1)
		for j:=0;j<N;j++ {
			if j % 4 == 0 || j % 4 == 3 { fmt.Fprintln(wrtr,s0) } else { fmt.Fprintln(wrtr,s1) }
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func Solve(testCaseIndex int, reader io.Reader) {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var (
		n int
		m int
	)
	fmt.Fscanln(reader, &n, &m)
	for k := 0; k < n; k++ {
		for j := 0; j < m; j++ {
			sqpar := (k / 2 + j / 2) % 2
			rpar := k - k / 2 * 2
			cpar := j - j / 2 * 2
			c := (rpar + cpar + sqpar) % 2
			fmt.Fprintf(writer, "%d ", c)
		}
		fmt.Fprintln(writer)
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var testCaseCount int
	fmt.Fscanln(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var a [64][64]byte
	for r := 0; r < 50; r++ {
		b := byte(r%4/2 ^ r%2)
		for c := 0; c < 50; c += 4 {
			a[r][c], a[r][c+1], a[r][c+2], a[r][c+3] = b, 1-b, 1-b, b
		}
	}

	var tc int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var rows, cols int
		fmt.Fscan(in, &rows, &cols)
		for r := 0; r < rows; r++ {
			for c := 0; c < cols; c++ {
				fmt.Fprintf(out, "%d ", a[r][c])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func solve() {
	var n, m int
	fmt.Fscan(r, &n, &m)
	ans := make([][]int, n)
	for i := range ans {
		ans[i] = make([]int, m)
	}
	ans[0][0], ans[1][1] = 1, 1
	for i := 2; i < n; i++ {
		for j := 0; j < m; j++ {
			if i%2 == 1 {
				ans[i][j] = ans[i-3][j]
			} else {
				ans[i][j] = ans[i-1][j]
			}
		}

	}
	for i := 2; i < m; i++ {
		for j := 0; j < n; j++ {
			if i%2 == 1 {
				ans[j][i] = ans[j][i-3]
			} else {
				ans[j][i] = ans[j][i-1]
			}
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j != m-1 {
				fmt.Fprintf(w, "%d ", ans[i][j])
			} else {
				fmt.Fprintf(w, "%d\n", ans[i][j])
			}
		}
	}
}
func main() {
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	ans := make([][]int, n)
	for i := range ans {
		ans[i] = make([]int, m)
	}
	for i:=0;i<n;i+=2 {
		for j:=0;j<m;j+=2 {
			if ((i/2%2) + (j/2)) % 2 == 0 {
				ans[i][j] = 1
				ans[i][j+1] = 0
				ans[i+1][j] = 0
				ans[i+1][j+1] = 1
			} else {
				ans[i][j] = 0
				ans[i][j+1] = 1
				ans[i+1][j] = 1
				ans[i+1][j+1] = 0
			}
		}
	}
	for i := range ans {
		for j := range ans[0] {
			fmt.Fprint(ww, ans[i][j], " ")
		}
		fmt.Fprintln(ww, "")
	}
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, m int
		Fscan(in, &n, &m)
		a := make([][]int, n)
		for i := 0; i < n; i++ {
			a[i] = make([]int, m)
		}
		var f = 1
		for i := 0; i < n; i += 2 {
			if (i/2)%2 == 0 {
				f = 1
			} else {
				f = 0
			}
			for j := 0; j < m; j += 2 {
				a[i][j] = f
				a[i][j+1] = 1 - f
				a[i+1][j] = 1 - f
				a[i+1][j+1] = f
				f = 1 - f
			}
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fprint(out, a[i][j], " ")
			}
			Fprintln(out)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A2() }

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

func solve() {
	var n, m int
	scan(&n, &m)
	a := [][]int{{1, 0, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 0}, {1, 0, 0, 1}}
	for i := 0; i < n; i++ {
		j := 0
		for j < m {
			id := j
			if id > 3 {
				id = id % 4
			}
			printf("%d ", a[i%4][id])
			j++
		}
		printf("\n")
	}

}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	for t := 1; t <= T; t++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if i == 0 && j == 0 {
					write_int(f, 0)
				} else {
					if i%4 == 1 || i%4 == 2 {
						if j%4 == 1 || j%4 == 2 {
							write_int(f, 0)
						} else {
							write_int(f, 1)
						}
					} else {
						if j%4 == 1 || j%4 == 2 {
							write_int(f, 1)
						} else {
							write_int(f, 0)
						}

					}
				}
				if j == m-1 {
					write_string(f, "\n")
				} else {
					write_string(f, " ")
				}
			}
		}
	}
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if i == 0 && j == 0 {
					fmt.Print(0)
				} else {
					if i%4 == 1 || i%4 == 2 {
						if j%4 == 1 || j%4 == 2 {
							fmt.Print(0)
						} else {
							fmt.Print(1)
						}
					} else {
						if j%4 == 1 || j%4 == 2 {
							fmt.Print(1)
						} else {
							fmt.Print(0)
						}

					}
				}
				if j == m-1 {
					fmt.Println()
				} else {
					fmt.Print(" ")
				}
			}
		}
	}
}

// https://codeforces.com/problemset/problem/1699/B

// 1699B - Almost Ternary Matrix

// You are given two even integers n and m. Your task is to find any binary matrix a with n rows and m columns where every cell (i,j) has exactly two neighbours with a different value than ai,j.
// Two cells in the matrix are considered neighbours if and only if they share a side. More formally, the neighbours of cell (x,y) are: (x−1,y), (x,y+1), (x+1,y) and (x,y−1).
// It can be proven that under the given constraints, an answer always exists.

// Input
// Each test contains multiple test cases. The first line of input contains a single integer t (1≤t≤100) — the number of test cases. The following lines contain the descriptions of the test cases.
// The only line of each test case contains two even integers n and m (2≤n,m≤50) — the height and width of the binary matrix, respectively.

// Output
// For each test case, print n lines, each of which contains m numbers, equal to 0 or 1 — any binary matrix which satisfies the constraints described in the statement.
// It can be proven that under the given constraints, an answer always exists.

// Example
// input
// 3
// 2 4
// 2 2
// 4 4
// output
// 1 0 0 1
// 0 1 1 0
// 1 0
// 0 1
// 1 0 1 0
// 0 0 1 1
// 1 1 0 0
// 0 1 0 1

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, t, n, m, i, j int

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &m)

			for i = 1; i <= n; i++ {
				for j = 1; j <= m; j++ {
					if (i%4 <= 1 && j%4 > 1) || (i%4 > 1 && j%4 <= 1) {
						fmt.Fprint(writer, 1)
					} else {
						fmt.Fprint(writer, 0)
					}

					fmt.Fprint(writer, " ")
				}

				fmt.Fprintln(writer)
			}
		}
	}

	writer.Flush()
}

// https://codeforces.com/problemset/problem/1699/B

// 1699B - Almost Ternary Matrix

// You are given two even integers n and m. Your task is to find any binary matrix a with n rows and m columns where every cell (i,j) has exactly two neighbours with a different value than ai,j.
// Two cells in the matrix are considered neighbours if and only if they share a side. More formally, the neighbours of cell (x,y) are: (x−1,y), (x,y+1), (x+1,y) and (x,y−1).
// It can be proven that under the given constraints, an answer always exists.

// Input
// Each test contains multiple test cases. The first line of input contains a single integer t (1≤t≤100) — the number of test cases. The following lines contain the descriptions of the test cases.
// The only line of each test case contains two even integers n and m (2≤n,m≤50) — the height and width of the binary matrix, respectively.

// Output
// For each test case, print n lines, each of which contains m numbers, equal to 0 or 1 — any binary matrix which satisfies the constraints described in the statement.
// It can be proven that under the given constraints, an answer always exists.

// Example
// input
// 3
// 2 4
// 2 2
// 4 4
// output
// 1 0 0 1
// 0 1 1 0
// 1 0
// 0 1
// 1 0 1 0
// 0 0 1 1
// 1 1 0 0
// 0 1 0 1

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, t, n, m, i, j int

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &m)

			for i = 1; i <= n; i++ {
				for j = 1; j <= m; j++ {
					if (i%4 <= 1 && j%4 > 1) || (i%4 > 1 && j%4 <= 1) {
						fmt.Fprint(writer, 1)
					} else {
						fmt.Fprint(writer, 0)
					}

					if j != m {
						fmt.Fprint(writer, " ")
					} else {
						fmt.Fprintln(writer)
					}
				}
			}
		}
	}

	writer.Flush()
}

package main

import (
	"bufio"
	"os"
	"strconv"
)

func solve() {
	n, m := get(), get()
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			put((i ^ j ^ (j / 2) ^ (i / 2)) & 1)
			putc(' ')
		}
		putc('\n')
	}
}

const (
	once       = false
	maxBufSize = 0 // 10_000_000
)

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(bufio.ScanWords)
	if maxBufSize > 0 {
		in.Buffer(make([]byte, maxBufSize), maxBufSize)
	}

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	for t := get(); t > 0; t-- {
		solve()
	}
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geti64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func gets() string {
	scan()
	return in.Text()
}

func scan() {
	in.Scan()
}

func putaln(a []int) {
	for _, v := range a {
		put(v)
		putc(' ')
	}
	putc('\n')
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func put64ln(x int64) {
	put64(x)
	putc('\n')
}

func putln(x int) {
	put(x)
	putc('\n')
}

func putc(c rune) {
	out.WriteRune(c)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(x int) int {
	if x < 0 {
		return x * -1
	}
	return x
}


package main

import "fmt"

func countBit(x int) int {
	cnt := 0
	for x > 0 {
		x &= (x-1)
		cnt++
	}
	return cnt
}

func main() {
	var n, m, k, x, y, ans int
	var arr []int
	fmt.Scan(&n)
	fmt.Scan(&m)
	fmt.Scan(&k)
	for i := 0; i < m; i++ {
		fmt.Scan(&x)
		arr = append(arr, x)
	}
	fmt.Scan(&y)
	for i := 0; i < m; i++ {
		if countBit(arr[i]^y) <= k {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	xs := make([]int, m+1)
	for i := 0; i <= m; i++ {
		fmt.Scan(&xs[i])
	}
	z := m
	for i := 0; i < m; i++ {
		x := xs[m] ^ xs[i]
		d := 0
		for x > 0 {
			x -= x & -x
			d++
			if d > k {
				z--
				break
			}
		}
	}
	fmt.Println(z)
}

package main

import "fmt"

func sumOne(x int) int {
	sum := 0
	for x > 0 {
		sum += 1
		x &= (x - 1)
	}

	return sum
}

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)

	players := make([]int, m+1)

	friends := 0
	for i := 0; i <= m; i++ {
		fmt.Scan(&players[i])
	}

	tom := players[m]
	for i := 0; i < m; i++ {
		v := tom ^ players[i]
		if sumOne(v) <= k {
			friends += 1
		}
	}

	fmt.Println(friends)
}

package main

import (
    "fmt"
)

func count(n int) int {
    a := 0
    for n != 0 {
        a++
        n &= n - 1
    }
    return a
}

func main() {
    var n, m, k int
    fmt.Scanf("%d %d %d\n", &n, &m, &k)
    sum := make([]int, m+1)
    for i := 0; i <= m; i++ {
        fmt.Scanf("%d\n", &sum[i])
    }

    a := 0
    for i := 0; i < m; i++ {
        if count(sum[m]^sum[i]) <= k {
            a++
        }
    }

    fmt.Println(a)
}

package main

import (
	"fmt"
)

func abs(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}

func count(n int) int {
	a := 1
	for n&(n-1) != 0 {
		a++
		n &= n - 1
	}
	return a
}

func main() {
	var n, m, k int
	fmt.Scanf("%d %d %d\n", &n, &m, &k)
	sum := make([]int, m+1)
	for i := 0; i <= m; i++ {
		fmt.Scanf("%d\n", &sum[i])
	}

	a := 0
	for i := 0; i < m; i++ {
		if count(sum[m]^sum[i]) <= k {
			a++
		}
	}

	fmt.Println(a)
}

package main

import (
	"bufio"
	"fmt"
	"strconv"
	"os"
)

func toBinary(a int) string {
	result := ""
	for a > 0 {
		d := a % 2
		a /= 2
		result += strconv.Itoa(d)
	}
	return result
}

func getDiff(a string, b string) int {
	result := 0
	for i, _ := range a {
		if i < len(b) {
			if a[i] != b[i] && (string(a[i]) == "1" || string(b[i]) == "1") {
				result++
			}
		} else if string(a[i]) == "1" {
			result++
		}
	}
	if len(b) > len(a) {
		for i := len(a); i < len(b); i++ {
			if string(b[i]) == "1" {
				result++
			}
		}
	}
	return result
}

func main() {
	var n, m, k int
	fmt.Scanln(&n, &m, &k)
	scanner := bufio.NewScanner(os.Stdin)

	x := make([]int, 0)
	for scanner.Scan() {
		current, _ := strconv.ParseInt(scanner.Text(), 10, 0)
		x = append(x, int(current))
	}

	base := toBinary(x[len(x) - 1])
	result := 0
	for i, v := range x {
		if i == len(x) - 1 {
			break
		}
		if k >= getDiff(base, toBinary(v)) {
			result++
		}
	}

	fmt.Println(result)
}

package main;

import (
	"fmt"
)

func OneSum(x int) int {
	sum := 0
	for x > 0 {
		sum += 1
		x &= (x-1)
	}

	return sum
}

func main() {
	var n,m,k int
	fmt.Scan(&n, &m, &k)
	x := make([]int, m)
	for i:= range x {
		fmt.Scan(&x[i])
	}

	var fedor int
	friends := 0
	fmt.Scan(&fedor)

	for i:=0;i<m;i++ {
		v := fedor ^ x[i]
		if OneSum(v) <= k {
			friends +=1
		}
	}

	fmt.Println(friends)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n,m,k,l int
	fmt.Scan(&n,&m,&k)
	a := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a[i])
	}
	var ma int
	fmt.Scan(&ma)
	for i:=0;i<m;i++ {
		if strings.Count(fmt.Sprintf("%b",a[i]^ma),"1")<=k {
			l++
		}
	}
	fmt.Println(l)
}

package main

import (
	"fmt"
)

func main() {
	var n, m, k, fed int

	fmt.Scan(&n, &m, &k)
	var arm = make([]int, m)

	for i := 0; i < m; i++ {
		fmt.Scan(&arm[i])
	}
	fmt.Scan(&fed)

	ans := 0
	for i := 0; i < m; i++ {
		c := arm[i] ^ fed

		bDiff := 0
		for c > 0 {
			if c&1 == 1 {
				bDiff++
			}
			c = c >> 1
		}

		if bDiff <= k {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	x := make([]int, m)
	for i := range x {
		fmt.Scan(&x[i])
	}
	var fedor int
	fmt.Scan(&fedor)
	ans := 0
	for _, x := range x {
		cur := 0
		for i := uint(0); int(i) < n; i++ {
			if fedor&(1<<i) != x&(1<<i) {
				cur++
			}
		}
		if cur <= k {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m, k := nextInt(), nextInt(), nextInt()
	a := make([]int, m)
	count := m
	_ = n

	for i := 0; i < m; i++ {
		a[i] = nextInt()
	}

	fedor := fmt.Sprintf("%020b", nextInt())

	for i := 0; i < m; i++ {
		s := fmt.Sprintf("%020b", a[i])
		dif := 0

		for j := 19; j >= 0; j-- {
			if s[j] != fedor[j] {
				dif++
			}
				// println(s[i], fedor[i])
		}
		// println(1, dif)
		// println(fedor)
		// println(s)
		// println()

		if dif > k {
			count--
		}
	}

	println(count)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func binary(n, digits int) []int {
	b := make([]int, digits)
	for i := 0; n > 0; i++ {
		b[i] = n % 2
		n = n / 2
	}
	return b
}

func can_befriend(
	army int, binary_fedor []int, soldiers, differ_limit int) bool {
	army_binary := binary(army, soldiers)
	var differ_count int
	for i := 0; i < soldiers; i++ {
		if army_binary[i] == binary_fedor[i] {
			continue
		}
		differ_count += 1
		if differ_count > differ_limit {
			return false
		}
	}
	return true
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var players, soldiers, differ_limit, fedor_army int
	fmt.Fscanf(reader, "%d %d %d", &soldiers, &players, &differ_limit)
	armies := make([]int, players)
	for i := 0; i < players; i++ {
		fmt.Fscanf(reader, "\n%d", &armies[i])
	}
	fmt.Fscanf(reader, "\n%d", &fedor_army)
	binary_fedor := binary(fedor_army, soldiers)
	friends := 0
	for _, army := range armies {
		if can_befriend(army, binary_fedor, soldiers, differ_limit) {
			friends += 1
		}
	}
	fmt.Fprintln(writer, friends)
}

package main

import (
	"bufio"
	"fmt"
	"strconv"
	"os"
)

func toBinary(a int) string {
	result := ""
	for a > 0 {
		d := a % 2
		a /= 2
		result = strconv.Itoa(d) + result
	}
	return result
}

func getDiff(a string, b string) int {
	result := 0
	for i, _ := range a {
		if i < len(b) {
			if a[i] != b[i] && (string(a[i]) == "1" || string(b[i]) == "1") {
				result++
			}
		} else if string(a[i]) == "1" {
			result++
		}
	}
	if len(b) > len(a) {
		for i := len(a); i < len(b); i++ {
			if string(b[i]) == "1" {
				result++
			}
		}
	}
	return result
}

func main() {
	var n, m, k int
	fmt.Scanln(&n, &m, &k)
	scanner := bufio.NewScanner(os.Stdin)

	x := make([]int, 0)
	for scanner.Scan() {
		current, _ := strconv.ParseInt(scanner.Text(), 10, 0)
		x = append(x, int(current))
	}

	base := toBinary(x[len(x) - 1])
	result := 0
	for i, v := range x {
		if i == len(x) - 1 {
			break
		}
		if k > getDiff(base, toBinary(v)) {
			result++
		}
	}

	fmt.Println(result)
}

package main

import (
	"fmt"
)

func main() {
	var n,m,k,l int
	fmt.Scan(&n,&m,&k)
	a := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a[i])
	}
	var ma int
	fmt.Scan(&ma)
	am := fmt.Sprintf("%21b",ma)
	for i:=0;i<m;i++ {
		bm := fmt.Sprintf("%21b",a[i])
		r :=0
		for j:=0;j<21;j++{
			if am[j]!=bm[j] {
				r++;
			}
		}
		if r<=k {
			l++
		}
	}
	fmt.Println(l)
}

package main

import (
	"fmt"
)

func main() {
	var n,m,k,l int
	fmt.Scan(&n,&m,&k)
	m++
	a := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a[i])
	}
	am := fmt.Sprintf("%21b",a[m-1])
	for i:=0;i<m-1;i++ {
		bm := fmt.Sprintf("%21b",a[i])
		r :=0
		for j:=0;j<21;j++{
			if am[j]!=bm[j] {
				r++;
			}
		}
		if r<=k {
			l++
		}
	}
	fmt.Println(l)
}

package main

import (
	"fmt"
)

func main() {
	var n,m,k,l int
	fmt.Scan(&n,&m,&k)
	a := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a[i])
	}
	var ma int
	fmt.Scan(&ma)
	am := fmt.Sprintf("%19b",ma)
	for i:=0;i<m;i++ {
		bm := fmt.Sprintf("%19b",a[i])
		r :=0
		for j:=0;j<19;j++{
			if am[j]!=bm[j] {
				r++;
			}
		}
		if r<=k {
			l++
		}
	}
	fmt.Println(l)
}

package main

import (
	"fmt"
)

func main() {
	var n,m,k,l int
	fmt.Scan(&n,&m,&k)
	m++
	a := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a[i])
	}
	am := fmt.Sprintf("%20b",a[m-1])
	for i:=0;i<m-1;i++ {
		bm := fmt.Sprintf("%20b",a[i])
		r :=0
		for j:=0;j<20;j++{
			if am[j]!=bm[j] {
				r++;
			}
		}
		if r<=k {
			l++
		}
	}
	fmt.Println(l)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve(n int64, m int64, x int64) int64 {
	numOfCols := ((x - 1) / n)
	start := numOfCols + 1
	different := x - numOfCols*n - 1
	return start + m*different
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int64(0)
		m := int64(0)
		x := int64(0)
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &x)
		fmt.Fprintf(out, "%d\n", solve(n, m, x))
		tt--
	}
	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	input := bufio.NewReader(os.Stdin)
	var testCases int
	fmt.Fscan(input, &testCases)

	for testCases > 0 {
		testCases--
		var n ,m, x int64
		fmt.Fscan(input, &n, &m, &x)
		x--
		rows := x % n
		cols := x / n
		fmt.Println(rows * m + 1 + cols)
	}

}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)

	for q := 0; q < t; q += 1 {
		var n, m, x int64
		fmt.Scan(&n, &m, &x)

		if x % n != 0 {
			fmt.Printf("%d\n", x / n + 1 + m * ((x % n) - 1))
		} else {
			fmt.Printf("%d\n", x / n + m * (n - 1))
		}
	}
}

// http://codeforces.com/problemset/problem/1506/A

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var a, b, n, m, x int64
		scanf("%d %d %d\n", &n, &m, &x)

		if x % n == 0 {
			a = n
			b = x / n
		} else {
			a = x % n
			b = (x / n) + 1
		}

		printf("%d\n", 1 + (m*(a-1)) + b-1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int
	var m, n, d int64
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &m, &n, &d)
		col := d/m + 1
		row := d % m
		if row == 0 {
			row = m
			col -= 1
		}
		ans := (row-1)*n + col
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const EnoughSize = 10000

var io *bufio.ReadWriter
var rq chan interface{}

func init() {
	io = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))
	rq = make(chan interface{}, EnoughSize)
}

func rl() string {
	s, _ := io.ReadString('\n')
	return strings.TrimRight(s, "\r\n")
}

func ri() int64 {
	s := rl()
	i, _ := strconv.ParseInt(s, 0, 64)
	return i
}

func ris() []int64 {
	s := rl()
	ns := make([]int64, 0)
	splits := strings.Split(s, " ")
	for _, seg := range splits {
		i, _ := strconv.ParseInt(seg, 0, 64)
		ns = append(ns, i)
	}
	return ns
}

func flush() {
	for {
		r, ok := <-rq
		if !ok {
			break
		}
		fmt.Println(r)
	}
}

func submit(r interface{}) {
	rq <- r
}

func divmod(n, d int64) (q, r int64) {
	q = n / d
	r = n % d
	return
}

func main() {
	T := int(ri())
	for t := 0; t < T; t++ {
		ns := ris()
		p, q, x := ns[0], ns[1], ns[2]
		submit(solve(p, q, x))
	}
	close(rq)
	defer flush()
}

func solve(n, m, x int64) int64 {
	q, r := divmod(x, n)
	var xx, yy int64
	if r == 0 {
		xx = q - 1
		yy = n - 1
	} else {
		xx = q
		yy = r - 1
	}
	return xx + m*yy + 1
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int) int {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {

		var n, m, x int64

		fmt.Fscan(input, &n)
		fmt.Fscan(input, &m)
		fmt.Fscan(input, &x)

		var Row, COL int64
		q := x % n
		if q > 0 {
			Row = int64(q)
			COL = int64(x/n) + 1
		} else {
			Row = n
			COL = int64(x / n)
		}
		var ANSWER int64
		ANSWER = int64(Row-1)*m + COL
		fmt.Println(ANSWER)
		// fmt.Println(Row)
		// fmt.Println(COL)

	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func ICeil(x float64) int64 {
	return int64(math.Ceil(x))
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, x := 0, int64(0), int64(0), int64(0)
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &x)
		r, c := x%n, ICeil(float64(x)/float64(n))
		if r == 0 {
			r = n
		}
		fmt.Fprintln(w, (r-1)*m+c)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader  = bufio.NewReader(os.Stdin)
	t       int
	n, m, x int64
)

func solve(n, m, x int64) int64 {
	column := (x + n - 1) / n
	row := x - (column-1)*n
	return (row-1)*m + column
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m, &x)
		fmt.Println(solve(n, m, x))
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	//"math"
	"os"
)

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, m, x int64
		Fscan(in, &n, &m, &x)

		row, col := (x-1) % n + 1, x / n
		if x % n != 0 {
			col++
		}
		Fprintln(out, (row - 1) * m + col)
	}
}

func main() { run(os.Stdin, os.Stdout) }

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

import "fmt"

func main() {
	var t, x, y, z, q, a, b int64
	fmt.Scan(&t)
	for i := int64(0); i < t; i++ {
		fmt.Scan(&x, &y, &z)
		q = (z % x)
		if q == 0 {
			q = x
		}
		a = (q - 1) * y
		b = (z - q) / x
		fmt.Println(a + b + 1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1506A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1506A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1506A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1506A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1506A) NextInt64() uint64 {
	in.load()
	val, _ := strconv.ParseUint(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1506A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
 Run solve the problem CF1506A
 Date: 16/05/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1506/A
 Problem: CF1506A
**/
func (in *CF1506A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n, m, x := in.NextInt64(), in.NextInt64(), in.NextInt64()
		x--
		a := x / n
		b := x % n
		res := (b * m) + a
		fmt.Println(res+1)
	}
}

func NewCF1506A(r *bufio.Reader) *CF1506A {
	return &CF1506A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1506A(bufio.NewReader(os.Stdin)).Run()
}

// 从给定cell号算出行列坐标即可。

package main

import "fmt"

func main() {
	var t, n, m, x int64
	fmt.Scan(&t)
	for i := int64(0); i < t; i++ {
		fmt.Scan(&n, &m, &x)
		r, c := (x-1)%n, (x-1)/n
		result := r*m + c + 1
		fmt.Println(result)
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var R, C, x int64
		fmt.Fscan(in, &R, &C, &x)
		x--
		c := x/R
		r := x%R
		fmt.Println(r*C+c+1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}

func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}

func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}

func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}

func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt64()
		M := sc.nextInt64()
		x := sc.nextInt64()

		row := (x - 1) % N
		col := (x - 1) / N
		ans := row*M + col + 1
		fmt.Fprintln(wr, ans)
	}

}

package main

import "fmt"
import "math"

func solve(n,m,x int64) int64 {
	var i,j int64
	i = x % n
	if (i == 0) {
		i = n
	}
	j = int64(math.Ceil(float64(x) / float64(n)))
	return (i - 1)*m + j
}

func main() {
	var t int
	var n,m,x int64
	fmt.Scan(&t)
	for i := 0; i < int(t); i++ {
		fmt.Scan(&n,&m,&x)
		fmt.Println(solve(n,m,x))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n, m, x := scanInt64(), scanInt64(), scanInt64()
		r, c := (x-1)%n, (x-1)/n
		fmt.Println(r*m + c + 1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int64
		var m int64
		var x int64

		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &x)

		x--
		c := x / n

		r := x - c*n

		// fmt.Fprintf(out, "%d %d \n", c, r)
		ans := r*m + c
		fmt.Fprintf(out, "%v\n", ans+1)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, m, x int64
		Fscan(in, &n, &m, &x)
		x--
		c, r := x/n, x%n
		Fprintln(out, r*m+c+1)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	i := 0
	fmt.Fscanf(in, "%d\n", &t)
	for {
		i++
		if i > t {
			break
		}
		var n, m, x int64
		fmt.Fscanf(in, "%v%v%v\n", &n, &m, &x)
		hang := (x - 1) / n
		lie := x - hang*n
		hang++
		lie--
		fmt.Fprintf(out, "%v\n", lie*m+hang)
	}
	return
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        var n, m, x int64
        fmt.Fscan(rd, &n, &m, &x)
        x--
        r, c := x % n, x / n
        fmt.Println(r * m + c + 1)
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for test := parseInt(getString(reader)); test > 0; test-- {
		nmx := getIntln(reader)
		n, m, x := nmx[0], nmx[1], nmx[2]
		y := m*(x-1) - ((x-1)/n)*(m*n-1) + 1
		writer.WriteString(fmt.Sprintln(y))
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int64 {
	var res int64
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int64(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int64 {
	b := strings.Split(getString(in), " ")
	res := make([]int64, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import "fmt"

func main() {

    var t int
	fmt.Scanf("%d", &t)
	for t > 0 {
		t--
		var n, m, x int64
		var s string
		fmt.Scanf("%s", &s)
		//fmt.Println(s)
		fmt.Scanf("%d%d%d", &n, &m, &x)
		//fmt.Println(n, m, x)
		x--
		i, j := x % n, x / n
		result := i * m + j
		result++
		fmt.Println(result)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, m, x := getI(), getI(), getI()
	var row int64
	var col int64

	row = x % n
	col = ceil(x, n)

	if row == 0 {
		row = n
	}

	out(row*m - m + col)
}

// http://github.com/KadoBOT (me@ricardoambrogi.com)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!
func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func ceil(n, d int64) int64 {
	return (n + d - 1) / d
}

func nsort(data ...int64) []int64 {
	sort.SliceStable(data, func(i, j int) bool { return data[i] < data[j] })
	return data
}

func nsorti(data ...int64) []int64 {
	idxs := make([]int64, len(data))
	for i := 0; i < len(data); i++ {
		idxs[i] = int64(i)
	}

	sort.SliceStable(idxs, func(i, j int) bool { return data[idxs[i]] < data[idxs[j]] })
	return idxs
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// !------- FORMULAS -------!
func gcd(a, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a, b int64, integers ...int64) int64 {
	result := a * b / gcd(a, b)

	for i := 0; i < len(integers); i++ {
		result = lcm(result, integers[i])
	}

	return result
}

func sieve(n int64) []int64 {
	integers := make([]bool, n+1)
	for i := int64(2); i < n+1; i++ {
		integers[i] = true
	}

	for p := int64(2); p*p <= n; p++ {
		if integers[p] == true {
			for i := p * 2; i <= n; i += p {
				integers[i] = false
			}
		}
	}

	var primes []int64
	for p := int64(2); p <= n; p++ {
		if integers[p] == true {
			primes = append(primes, p)
		}
	}

	return primes
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x,y,z int
		fmt.Scan(&x,&y,&z)
		var a,b,c,d int
		a= x*y
		b= a-z
		c= b%x
		d= b/x
		fmt.Println(a - ((c*y)+(d*1)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	i := 0
	fmt.Fscanf(in, "%d\n", &t)
	for {
		i++
		if i > t {
			break
		}
		var n, m, x int
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &x)
		hang := (x - 1) / n
		lie := x - hang*n
		hang++
		lie--
		fmt.Fprintf(out, "%v\n", lie*m+hang)
	}
	return
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    for t := 0; t < q; t++ {
        var n, m, x int64
        fmt.Fscan(rd, &n, &m, &x)
        x--
        r, c := x % n, x / n
        fmt.Println(r * m + c + 1)
    }
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    for t := 0; t < q; t++ {
        var n, m, x int
        fmt.Fscan(rd, &n, &m, &x)
        x--
        r, c := x % n, x / n
        fmt.Println(r * m + c + 1)
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	for test := parseInt(getString(reader)); test > 0; test-- {
		nmx := getIntln(reader)
		n, m, x := nmx[0], nmx[1], nmx[2]
		var i int
		for i = 0; i < n; i++ {
			if (x-1-i)%n == 0 {
				break
			}
		}
		y := (x + n + (n*m-1)*i - 1) / n
		writer.WriteString(fmt.Sprintln(y))
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x,y,z int
		fmt.Scan(&x,&y,&z)
		if x*y == z {
			fmt.Println(z)
		} else if z%x >=1 {
			fmt.Println((z/x)+1+(y*((z%x)-1)))
		} else {
			fmt.Println((z/x)+(y*(z/x)))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	input := bufio.NewReader(os.Stdin)
	var testCases int
	fmt.Fscan(input, &testCases)

	for testCases > 0 {
		testCases--
		var n ,m, x int
		fmt.Fscan(input, &n, &m, &x)
		x--
		rows := x % n
		cols := x / n
		fmt.Println(rows * m + 1 + cols)
	}

}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)

	for q := 0; q < t; q += 1 {
		var n, m, x int
		fmt.Scan(&n, &m, &x)

		if x % n != 0 {
			fmt.Printf("%d\n", x / n + 1 + m * ((x % n) - 1))
		} else {
			fmt.Printf("%d\n", x / n + m * (n - 1))
		}
	}
}

// http://codeforces.com/problemset/problem/1506/A

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var a, b, n, m, x int
		scanf("%d %d %d\n", &n, &m, &x)

		if x % n == 0 {
			a = n
			b = x / n
		} else {
			a = x % n
			b = (x / n) + 1
		}

		printf("%d\n", 1 + (m*(a-1)) + b-1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, m, n, d int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &m, &n, &d)
		col := d/m + 1
		row := d % m
		if row == 0 {
			row = m
			col -= 1
		}
		ans := (row-1)*n + col
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int) int {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {

		var n, m, x int

		fmt.Fscan(input, &n)
		fmt.Fscan(input, &m)
		fmt.Fscan(input, &x)

		Row := 0
		COL := 0
		q := x % n
		if q > 0 {
			Row = q
			COL = int(x/n) + 1
		} else {
			Row = n
			COL = int(x / n)
		}

		ANSWER := (Row-1)*m + COL
		fmt.Println(ANSWER)
		// fmt.Println(Row)
		// fmt.Println(COL)

	}

}