An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?

The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 < a+b+c+d \leq 10^5$$$).

If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spaces — a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.

NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.

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"
	"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"
	"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")
	}
}


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 $$$a_{i,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.

Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 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 \le n,m \le 50$$$) — the height and width of the binary matrix, respectively.

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.

NoteWhite means $$$0$$$, black means $$$1$$$. The binary matrix from the first test caseThe binary matrix from the second test caseThe binary matrix from the third test case

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 (
	"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 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"
)

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() }


After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer xi. Consider binary representation of xi: if the j-th bit of number xi equal to one, then the army of the i-th player has soldiers of the j-th type. Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.

The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.

Print a single integer — the number of Fedor's potential friends.

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 (
	"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 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, 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 (
	"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)
}


Let's consider a k × k square, divided into unit squares. Please note that k ≥ 3 and is odd. We'll paint squares starting from the upper left square in the following order: first we move to the right, then down, then to the left, then up, then to the right again and so on. We finish moving in some direction in one of two cases: either we've reached the square's border or the square following after the next square is already painted. We finish painting at the moment when we cannot move in any direction and paint a square. The figure that consists of the painted squares is a spiral.   The figure shows examples of spirals for k = 3, 5, 7, 9.  You have an n × m table, each of its cells contains a number. Let's consider all possible spirals, formed by the table cells. It means that we consider all spirals of any size that don't go beyond the borders of the table. Let's find the sum of the numbers of the cells that form the spiral. You have to find the maximum of those values among all spirals.

The first line contains two integers n and m (3 ≤ n, m ≤ 500) — the sizes of the table. Each of the next n lines contains m space-separated integers: the j-th number in the i-th line aij ( - 1000 ≤ aij ≤ 1000) is the number recorded in the j-th cell of the i-th row of the table.

Print a single number — the maximum sum of numbers among all spirals.

NoteIn the first sample the spiral with maximum sum will cover all 1's of the table.In the second sample the spiral may cover only six 1's.

package main

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

var a, t, s [501][501]int32

var reader SReader

func main() {
	reader.Init()
	n := reader.ReadInt()
	m := reader.ReadInt()
	for i := int32(1); i <= n; i++ {
		for j := int32(1); j <= m; j++ {
			a[i][j] = reader.ReadInt()
		}
	}

	for i := int32(0); i <= n; i++ {
		t[i][0] = 0
		s[i][0] = 0
	}
	for j := int32(0); j <= m; j++ {
		t[0][j] = 0
		s[0][j] = 0
	}

	for i := int32(1); i <= n; i++ {
		for j := int32(1); j <= m; j++ {
			t[i][j] = t[i][j-1] + a[i][j]
		}
	}
	for i := int32(1); i <= n; i++ {
		for j := int32(1); j <= m; j++ {
			s[i][j] = s[i-1][j] + t[i][j]
		}
	}

	nMaxSum := IntMin
	for i := int32(1); i <= n; i++ {
		for j := int32(1); j <= m; j++ {
			nLastSpiralSum := int32(0)
			for k := int32(3); ; k += 2 {
				r := k / 2
				top := i - r
				left := j - r
				bottom := i + r
				right := j + r
				if top < 1 || left < 1 || bottom > n || right > m {
					break
				}

				nLeftSum := s[bottom][left-1]
				nTopSum := s[top-1][right]
				nLeftTopSum := s[top-1][left-1]
				nTotalSum := s[bottom][right]
				nSquareSum := nTotalSum + nLeftTopSum - nTopSum - nLeftSum
				if k == 3 {
					nSpiralSum := nSquareSum - a[i][j] - a[i][j-1]
					nLastSpiralSum = nSpiralSum
					nMaxSum = Max(nMaxSum, nSpiralSum)
					continue
				}

				nSpecialCell := a[top+1][left]
				nSpiralSum := nSquareSum - nLastSpiralSum - nSpecialCell
				nLastSpiralSum = nSpiralSum
				nMaxSum = Max(nMaxSum, nSpiralSum)
			}
		} // for i
	}

	fmt.Println(nMaxSum)
}

const (
	IntMax = int32(^uint32(0) >> 1)
	IntMin = ^IntMax
)

// reader
type SReader struct {
	file *os.File
	scanner *bufio.Scanner
}

func (this *SReader) Init() {
	this.file = os.Stdin
	this.scanner = bufio.NewScanner(this.file)
	this.scanner.Split(bufio.ScanWords)
}

func (this *SReader) ReadInt() int32 {
	this.scanner.Scan()
	n, err:= strconv.ParseInt(this.scanner.Text(), 10, 0)
	if err != nil {
		panic(err)
	}
	return int32(n)
}

// min/max

func Max(a, b int32) int32 {
	if a > b {
		return a
	} else {
		return b
	}
}