Boboniu gives you  $$$r$$$ red balls,  $$$g$$$ green balls,  $$$b$$$ blue balls,  $$$w$$$ white balls. He allows you to do the following operation as many times as you want:   Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the balls into a palindrome after several (possibly zero) number of described operations.

The first line contains one integer $$$T$$$ ($$$1\le T\le 100$$$) denoting the number of test cases. For each of the next $$$T$$$ cases, the first line contains four integers $$$r$$$, $$$g$$$, $$$b$$$ and $$$w$$$ ($$$0\le r,g,b,w\le 10^9$$$).

For each test case, print "Yes" if it's possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print "No".

NoteIn the first test case, you're not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.In the second test case, after doing one operation, changing $$$(8,1,9,3)$$$ to $$$(7,0,8,6)$$$, one of those possible palindromes may be "rrrwwwbbbbrbbbbwwwrrr".A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. For example, "rggbwbggr", "b", "gg" are palindromes while "rgbb", "gbbgr" are not. Notice that an empty word, phrase, or sequence is palindrome.

package main

import (
	"bufio"
	"fmt"
	"os"
)
func main() {

	var T int
	fmt.Scan(&T)
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	for z := 0; z < T; z++ {
		r.Scan()
		red := toInt(r.Bytes())
		r.Scan()
		green := toInt(r.Bytes())
		r.Scan()
		blue := toInt(r.Bytes())
		r.Scan()
		white := toInt(r.Bytes())
		evenCount := 0
		oddCount := 0

		if red % 2 == 0 {
			evenCount++
		} else {
			oddCount++
		}

		if green % 2 == 0 {
			evenCount++
		} else {
			oddCount++
		}

		if blue % 2 == 0 {
			evenCount++
		} else {
			oddCount++
		}
		if white%2 == 0 {
			if evenCount == 3  || evenCount == 2 || evenCount == 0 {
				fmt.Println("Yes")
				continue
			}
			// 1
			fmt.Println("No")
		} else {
			if evenCount == 3 || evenCount == 0 {
				fmt.Println("Yes")
				continue
			} else if evenCount == 1 {
				if red != 0 && blue != 0 && green!=0 {
					fmt.Println("Yes")
					continue
				}
			}
			// 2
			fmt.Println("No")
		}

	}

}

func toInt(buf []byte) (n int) {
	if buf[0] == '-' {
		for _, v := range buf[1:] {
			n = n*10 + int(v-'0')
		}
		return -n
	} else {
		for _, v := range buf {
			n = n*10 + int(v-'0')
		}
		return n
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return i
	}

	for t := input(); t > 0; t-- {
		a := make([]uint64, 4)

		for i := range a {
			a[i] = input()
		}

		min := a[0]

		for i := 0; i < 3; i++ {
			if min > a[i] {
				min = a[i]
			}
		}

		var i uint64
		var found bool = false
		for ; i <= min; i = i*i+1 {
			numEven := 0

			for j := 0; j < 4; j++ {
				if a[j]%2 == 0 {
					numEven++
				}
			}

			if numEven >= 3 {
				found = true
			}

			if found {
				break
			}

			for j := 0; j < 3; j++ {
				a[j]--
			}

			a[3] += 3
		}

		if found {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import "fmt"

type Colours struct {
	R, G, B, W int
}

func (c *Colours) countOdd() int {
	return (c.R & 1) + (c.G & 1) + (c.B & 1) + (c.W & 1)
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var c Colours
		fmt.Scanf("%d %d %d %d\n", &c.R, &c.G, &c.B, &c.W)

		// possible to form a palindrome if number of odd colours is <= 1
		// operation: reduce R, G, B by 1, add 1 to W -- flips parity of all
		if c.countOdd() <= 1 || (c.countOdd() >= 3 && c.R > 0 && c.G > 0 && c.B > 0) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var r, g, b, w int
		fmt.Fscan(in, &r)
		fmt.Fscan(in, &g)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &w)

		odds := 0
		whiteOdds := 0

		if r%2 != 0 {
			odds++
		}
		if g%2 != 0 {
			odds++
		}
		if b%2 != 0 {
			odds++
		}
		if w%2 != 0 {
			whiteOdds++
		}

		if (odds + whiteOdds) <= 1 {
			fmt.Println("Yes")
			continue
		}

		if r == 0 || g == 0 || b == 0 {
			fmt.Println("No")
			continue
		}

		if whiteOdds == 1 && odds == 2 {
			fmt.Println("Yes")
			continue
		}

		if odds == 3 {
			fmt.Println("Yes")
			continue
		}

		fmt.Println("No")

	}
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	S := int64(r) + int64(g) + int64(b) + int64(w)

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		// if even == 4 || even == 3 {
		fmt.Println("Yes")
		return
	}

	mini := Min(r, g, b)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		// if even == 4 || even == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

/*********** Output ***********/

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	// S := r + g + b + w

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	// if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
	if even == 4 || even == 3 {
		fmt.Println("Yes")
		return
	}

	mini := Min(r, g, b)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	// if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
	if even == 4 || even == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

/*********** Output ***********/

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return i
	}

	for t := input(); t > 0; t-- {
		a := make([]uint64, 4)

		for i := range a {
			a[i] = input()
		}

		min := a[0]

		for i := 0; i < 3; i++ {
			if min > a[i] {
				min = a[i]
			}
		}

		for i := 0; i < 3; i++ {
			a[i] -= min
		}

		a[3] += 3 * min

		numEven := 0

		for i := 0; i < 4; i++ {
			if a[i]%2 == 0 {
				numEven++
			}
		}

		if numEven >= 3 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var r, g, b, w int
		fmt.Fscan(in, &r)
		fmt.Fscan(in, &g)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &w)

		odds := 0
		whiteOdds := 0

		if r%2 != 0 {
			odds++
		}
		if g%2 != 0 {
			odds++
		}
		if b%2 != 0 {
			odds++
		}
		if w%2 != 0 {
			whiteOdds++
		}

		if (odds + whiteOdds) <= 1 {
			fmt.Println("Yes")
			continue
		}

		if r == 0 || g == 0 || b == 0 {
			fmt.Println("No")
			continue
		}

		if whiteOdds == 1 && odds == 2 {
			fmt.Println("Yes")
			continue
		}

		if whiteOdds == 0 && odds == 3 {
			fmt.Println("Yes")
			continue
		}

		fmt.Println("No")

	}
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	S := r + g + b + w

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
		return
	}

	// mini := Min(tmp...)
	mini := Min(r, g, b)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

/*********** Output ***********/

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	S := r + g + b + w

	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
		return
	}

	mini := Min(tmp...)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if (even == 4 && S%2 == 0) || (even == 3 && S%2 == 1) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

/*********** Output ***********/

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}

/*
URL:
https://codeforces.com/contest/1395/problem/A
*/

package main

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

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

var (
	t int

	r, g, b, w int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		r, g, b, w = ReadInt4()

		solve()
	}
}

func solve() {
	tmp := []int{r, g, b, w}
	even := 0
	for _, a := range tmp {
		if a%2 == 0 {
			even++
		}
	}

	if even == 4 || even == 3 {
		fmt.Println("Yes")
		return
	}

	mini := Min(tmp...)
	if mini == 0 {
		fmt.Println("No")
		return
	}

	tmp2 := []int{r - 1, g - 1, b - 1, w + 3}
	even = 0
	for _, a := range tmp2 {
		if a%2 == 0 {
			even++
		}
	}
	if even == 4 || even == 3 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

/*********** Output ***********/

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}


A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.You have integer n. Find some lucky permutation p of size n.

The first line contains integer n (1 ≤ n ≤ 105) — the required permutation size.

Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) after a space — the required permutation. If there are multiple answers, you can print any of them.

//286A
package main
import "fmt"

func main() {
	var nn, x, y int
	var a[100005]int
	fmt.Scan(&nn)
	x=nn
	if nn==1 {
		fmt.Println("1")
	} else {
		if nn%4==0 || nn%4==1 {
			for i:=1; i<=nn/2; i++ {
				a[i]=i+1
				a[i+1]=x
				a[x-1]=i
				a[x]=x-1
				x=x-2
				i++
			}
			if nn%2==0 {
				for i:=1; i<=nn; i++ {
					fmt.Print(a[i]," ")
				}
			} else {
				y=nn/2+1
				a[y]=y
				for i:=1; i<=nn; i++ {
					fmt.Print(a[i]," ")
				}
			}
		} else {
			fmt.Println("-1")
		}
	}
	fmt.Println()
}

// 286B
package main

import (
	"fmt"
)

func main() {
	var n, i, x, sum int
	fmt.Scan(&n)
	if n%4 == 2 || n%4 == 3 {
		fmt.Print(-1)
		return
	}
	sum = n + 2
	for i = 1; i <= n/2/2; i++ {
		x += 2
		fmt.Printf("%d %d ", x, sum-x)
	}
	if n&1 == 1 {
		fmt.Printf("%d ", n/2+1)
	}
	sum -= 2
	x = n/2 + 1
	for i = 1; i <= n/2/2; i++ {
		x -= 2
		fmt.Printf("%d %d ", x, sum-x)
	}
}

// 286A
package main

import (
	"fmt"
)

func main() {
	var n, i, x, sum int
	fmt.Scan(&n)
	if n%4 == 2 || n%4 == 3 {
		fmt.Print(-1)
		return
	}
	sum = n + 2
	for i = 1; i <= n/2/2; i++ {
		x += 2
		fmt.Printf("%d %d ", x, sum-x)
	}
	if n&1 == 1 {
		fmt.Printf("%d ", n/2+1)
	}
	sum -= 2
	x = n/2 + 1
	for i = 1; i <= n/2/2; i++ {
		x -= 2
		fmt.Printf("%d %d ", x, sum-x)
	}
}


Madoka as a child was an extremely capricious girl, and one of her favorite pranks was drawing on her wall. According to Madoka's memories, the wall was a table of $$$n$$$ rows and $$$m$$$ columns, consisting only of zeroes and ones. The coordinate of the cell in the $$$i$$$-th row and the $$$j$$$-th column ($$$1 \le i \le n$$$, $$$1 \le j \le m$$$) is $$$(i, j)$$$.One day she saw a picture "Mahou Shoujo Madoka Magica" and decided to draw it on her wall. Initially, the Madoka's table is a table of size $$$n \times m$$$ filled with zeroes. Then she applies the following operation any number of times:Madoka selects any rectangular subtable of the table and paints it in a chess coloring (the upper left corner of the subtable always has the color $$$0$$$). Note that some cells may be colored several times. In this case, the final color of the cell is equal to the color obtained during the last repainting.  White color means $$$0$$$, black means $$$1$$$. So, for example, the table in the first picture is painted in a chess coloring, and the others are not. For better understanding of the statement, we recommend you to read the explanation of the first test.Help Madoka and find some sequence of no more than $$$n \cdot m$$$ operations that allows you to obtain the picture she wants, or determine that this is impossible.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 100$$$) — the size of the table. Each of the following $$$n$$$ lines contains a string of length $$$m$$$ consisting only of $$$1$$$ and $$$0$$$ — description of the picture that Madoka wants to obtain.

If it is impossible to obtain the given picture, print $$$-1$$$. Otherwise, print in the first line a single integer $$$q$$$ ($$$0 \leq q \leq n \cdot m$$$) — the number of operations you need to obtain the picture. Note that you do not need to minimize the number of operations. Then for each operation (in the order of execution) print a single line containing four numbers — the coordinates of the upper-left corner and the lower-right corner of the rectangle.

NoteThe description of the first test case is below.  In the third test case, it is impossible to paint the desired picture.In the fourth test case, the initial table is already the desired picture.

package main

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

func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		grids := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &grids[i])
		}
		if grids[0][0] == '1' {
			fmt.Fprintln(out, -1)
			continue
		}
		var ans [][]int
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if grids[i][j] == '1' {
					if i == 0 {
						ans = append(ans, []int{i + 1, j, i + 1, j + 1})
					} else {
						ans = append(ans, []int{i, j + 1, i + 1, j + 1})
					}
				}
			}
		}
		fmt.Fprintln(out, len(ans))
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(out, ans[i][0], ans[i][1], ans[i][2], ans[i][3])
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		A := make([]string, n)
		for i, _ := range A {
			fmt.Scan(&A[i])
		}
		if A[0][0] == '1' {
			fmt.Println(-1)
			continue
		} else {
			fmt.Println(n * m)
		}
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if A[i][j] == '0' {
					fmt.Println(i + 1, j + 1, i + 1, j + 1)
				} else {
					if i == 0 {
						fmt.Println(i + 1, j, i + 1, j + 1)
					} else {
						fmt.Println(i, j + 1, i + 1, j + 1)
					}
				}
			}
		}
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, m int

		Fscan(in, &n, &m)

		a := make([]string, n+1)

		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}

		if a[0][0] == '1' {
			Fprintln(out, "-1")
			continue
		}

		cnt := 0

		ans := make([]string, 0)
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if a[i][j] == '1' {
					cnt++
					if j > 0 {
						ans = append(ans, Sprint(i+1, j, i+1, j+1))
					} else {
						ans = append(ans, Sprint(i, j+1, i+1, j+1))
					}

				}
			}
		}
		Fprintln(out, cnt)
		for _, s := range ans {
			Fprintln(out, s)
		}

	}

}

/*
https://codeforces.com/contest/1647/problem/C

*/

package main

import (
	//"bytes"
	"bufio"
	"fmt"
	//"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		M, _ := strconv.Atoi(line_arr[1])
		arr := make([][]rune, N)
		for i:=0; i<N; i++ {
			arr[i] = make([]rune, M)
			line, _ = reader.ReadString('\n')
			for j:=0; j<M; j++ {
				arr[i][j] = rune(line[j])
			}
		}
		//fmt.Printf("arr: %c\n", arr)
		nsteps, retarr := computeSteps(N, M, arr)
		fmt.Println(nsteps)
		for i:=0; i<nsteps; i++ {
			fmt.Printf("%d %d %d %d\n", retarr[i][0], retarr[i][1], retarr[i][2], retarr[i][3])
		}
	}
}

func computeSteps(n, m int, arr [][]rune) (nsteps int, retarr [][]int) {

	if arr[0][0] == '1' {
		nsteps = -1
		return
	}

	// process rows
	for i:=0; i<n; i++ {
		for j:=m-1; j>0; j-- {
			if arr[i][j] == '1' {
				nsteps++
				rect := []int{i+1, j, i+1, j+1}
				retarr = append(retarr, rect)
			}
		}
	}

	// process onlt the left most column
	for i:=n-1; i>0; i-- {
		if arr[i][0] == '1' {
			nsteps++
			rect := []int{i, 1, i+1, 1}
			retarr = append(retarr, rect)
		}
	}
	return
}

package main

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

func solve(arr [][]int, out io.Writer) {
	n, m := len(arr), len(arr[0])
	ans := make([][]int, 0, n*m+5)
	for i := n - 1; i >= 0; i-- {
		for j := m - 1; j >= 0; j-- {
			if arr[i][j] == 0 {
				continue
			}
			if j == 0 {
				ans = append(ans, []int{i - 1, 0, i, 0})
			} else {
				ans = append(ans, []int{i, j - 1, i, j})
			}
		}
	}
	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprintf(out, "%d %d %d %d\n", v[0]+1, v[1]+1, v[2]+1, v[3]+1)
	}
}
func CF1647C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, m int
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, m)
		}
		for i := 0; i < n; i++ {
			Fscan(in, &s)
			for j := 0; j < m; j++ {
				if s[j] == '1' {
					arr[i][j] = 1
				} else {
					arr[i][j] = 0
				}
			}
		}
		if arr[0][0] == 1 {
			Fprintln(out, -1)
		} else {
			solve(arr, out)
		}
		out.Flush()
	}
}

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

package main

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

var in = bufio.NewReader(os.Stdin)

func read(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans<<3 + ans<<1 + int(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}
func read1(out *int) error {
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
	}
	*out = int(c - '0')
	return err
}

var n, m, T int
var s [105][105]int

type nod struct {
	x1, y1, x2, y2 int
}

func makenod(x1, y1, x2, y2 int) (ret nod) {
	ret.x1 = x1
	ret.y1 = y1
	ret.x2 = x2
	ret.y2 = y2
	return
}
func solve() {
	read(&n)
	read(&m)
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			read1(&s[i][j])
		}
	}
	ve := make([]nod, 0)
	if s[1][1] == 1 {
		fmt.Println("-1")
		return
	}
	for i := 0; i <= n+1; i++ {
		s[i][0] = 0
		s[i][m+1] = 0
	}
	for j := 0; j <= m+1; j++ {
		s[0][j] = 0
		s[n+1][j] = 0
	}
	for i := 1; i <= n; i++ {
		for j := m; j >= 2; j-- {
			if s[i][j] == 1 {
				ve = append(ve, makenod(i, j-1, i, j))
			}
		}
	}
	for i := n; i >= 2; i-- {
		if s[i][1] == 1 {
			ve = append(ve, makenod(i-1, 1, i, 1))
		}
	}
	fmt.Printf("%d\n", len(ve))
	for _, i := range ve {
		fmt.Printf("%d %d %d %d\n", i.x1, i.y1, i.x2, i.y2)
	}
}
func main() {
	read(&T)
	for ; T > 0; T-- {
		solve()
	}
}

package main

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

/*
2
1 1
0
1 1
1
---
0
-1
====

1
2 3
001
010
---
1 2 2 2
1 2 1 3
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	tbl := make([]string, n)

	cnt := 0

	for i := range tbl {
		scanf("%s\n", &tbl[i])

		for _, r := range tbl[i] {
			if r == '1' {
				cnt++
			}
		}
	}

	if tbl[0][0] == '1' {
		fmt.Fprintln(writer, -1)
		return
	}

	fmt.Fprintln(writer, cnt)

	for i := n - 1; i > 0; i-- {
		for j := m - 1; j >= 0; j-- {
			if tbl[i][j] == '1' {
				fmt.Fprintln(writer, i, j+1, i+1, j+1)
			}
		}
	}

	for j := m - 1; j > 0; j-- {
		if tbl[0][j] == '1' {
			fmt.Fprintln(writer, 1, j, 1, j+1)
		}
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	idx := 0
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	// Todo...
	solve = func() {
		var n, m int
		Fscan(in, &n, &m)
		rec := make([][]int, n+2)
		for i := 0; i < n+2; i++ {
			rec[i] = make([]int, m+2)
		}
		for i := 0; i < n+2; i++ {
			for j := 0; j < m+2; j++ {
				rec[i][j] = 1
			}
		}
		var s string
		for i := 1; i <= n; i++ {
			Fscan(in, &s)
			for j := 1; j <= m; j++ {
				if s[j-1] == '1' {
					rec[i][j] = 1
				} else {
					rec[i][j] = 0
				}
			}
		}
		ok := true
		ans := make([][]int, 0)
		for i := 1; i <= n; i++ {
			for j := m; j >= 1; j-- {
				if rec[i][j] == 1 {
					if j-1 >= 1 {
						ans = append(ans, []int{i, j - 1, i, j})
						rec[i][j] = 0
					}
				}
			}
		}
		for j := 1; j <= m; j++ {
			for i := n; i >= 1; i-- {
				if rec[i][j] == 1 {
					if i-1 >= 1 {
						ans = append(ans, []int{i - 1, j, i, j})
						rec[i][j] = 0
					}
				}
			}
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if rec[i][j] == 1 {

					ok = false
				}
			}
		}
		if ok {
			Fprintln(out, len(ans))
			for _, v := range ans {
				Fprintln(out, v[0], " ", v[1], " ", v[2], " ", v[3])
			}
			Fprintln(out)
		} else {
			Fprintln(out, "-1")
		}
	}
	// End...
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		grids := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &grids[i])
		}
		if grids[0][0] == '1' {
			fmt.Fprintln(out, -1)
			continue
		}
		var ans [][]int
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if grids[i][j] == '1' {
					if i == 0 {
						ans = append(ans, []int{i, j - 1, i, j})
					} else {
						ans = append(ans, []int{i - 1, j, i, j})
					}
				}
			}
		}
		fmt.Fprintln(out, len(ans))
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(out, ans[i][0], ans[i][1], ans[i][2], ans[i][3])
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		A := make([]string, n)
		for i, _ := range A {
			fmt.Scan(&A[i])
		}
		if A[0][0] == '1' {
			fmt.Println(-1)
			continue
		} else {
			fmt.Println(n * m)
		}
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if A[i][j] == '0' {
					fmt.Println(i, j, i, j)
				} else {
					if i == 0 {
						fmt.Println(i, j-1, i, j)
					} else {
						fmt.Println(i-1, j, i, j)
					}
				}
			}
		}
	}
}


This is an easy version of the problem. The only difference between an easy and a hard version is the constraints on $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$.You are given $$$4$$$ positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ with $$$a < c$$$ and $$$b < d$$$. Find any pair of numbers $$$x$$$ and $$$y$$$ that satisfies the following conditions: $$$a < x \leq c$$$, $$$b < y \leq d$$$, $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$.Note that required $$$x$$$ and $$$y$$$ may not exist.

The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10$$$), the number of test cases. The descriptions of the test cases follow. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a < c \leq 10^5$$$, $$$1 \leq b < d \leq 10^5$$$).

For each test case print a pair of numbers $$$a < x \leq c$$$ and $$$b < y \leq d$$$ such that $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$. If there are multiple answers, print any of them. If there is no such pair of numbers, then print -1 -1.

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var a, b, c, d int
		fmt.Fscan(r, &a, &b, &c, &d)

		x := -1
		y := -1
		for i := a + 1; i <= c ; i++ {
			num :=  a*b / gcd(a*b, i)
			if num <= d {
				if k := d/num; k * num > b {
					x = i
					y = k * num
					break
				}
			}
		}

		fmt.Fprintln(w, x, y)
	}

}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

func bsearch(n, l, r, v int) int {
	if l == r { return l }
	m := (l + r) >> 1
	if m * n < v { return bsearch(n, m+1, r, v) }
	return bsearch(n, l, m, v)
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var a, b, c, d int
		fmt.Fscan(r, &a, &b, &c, &d)

		x := -1
		y := -1
		for i := a + 1; i <= c ; i++ {
			num :=  a*b / gcd(a*b, i)
			if num <= d {
				k := bsearch(num, 1, d / num, b+1)
				if k * num > b {
					x = i
					y = k * num
					break
				}
			}
		}

		fmt.Fprintln(w, x, y)
	}

}

package main

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

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

func gcd(x, y int) int {
    if y == 0 {
        return x
    }
    return gcd(y, x % y)
}

func solve() {
    var a, b, c, d int
    Fscan(in, &a, &b, &c, &d)

    x, y := -1, -1
    for i := a + 1; i <= c; i++ {
        g := gcd(a * b, i)
        miny := (a * b / g)

        ty := (b / miny + 1) * miny

        if ty <= d {
            x, y = i, ty
            break
        }
    }

    Fprintln(out, x, y)
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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 a, b, c, d int64
		fmt.Fscan(in, &a, &b, &c, &d)

		d1, d2 := -1, -1
		for i := a + 1; i <= c; i++ {
			s := a * b / gcd(i, a*b)
			z := d / s * s
			if z > b && z <= d && (i*z)%(a*b) == 0 {
				d1, d2 = int(i), int(z)
				break
			}
		}

		fmt.Fprintln(out, d1, d2)
	}
}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

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

func bsearch(n, d, l, r, v int) int {
	if l == r { return l }
	m := (l + r + 1) >> 1
	if m * n > v * d { return bsearch(n, d, l, m-1, v) }
	return bsearch(n, d, m, r, v)
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var a, b, c, d int
		fmt.Fscan(r, &a, &b, &c, &d)

		x := -1
		y := -1
		for i := a + 1; i <= c ; i++ {
			// fmt.Fprintln(w, "#################")
			// fmt.Fprintln(w, "## i ", i)
			num :=  a*b / gcd(a*b, i)
			denom := i / gcd(a*b, i)
			k := max(2, denom)
			v := k * num / denom

			// fmt.Fprintln(w, "## num denom k ", num, denom, k)
			if v > b && v <= d {
				// fmt.Fprintln(w, "yo1")
				x = i
				y = v
				break
			} else if v <= b && d*denom/num > k {
				// fmt.Fprintln(w, "yo1")
				k = bsearch(num, denom, k+1, d * denom / num, b+1)
				// fmt.Fprintln(w, "k ", k)
				if (k * num) % denom == 0 {
					x = i
					y = k * num / denom
					break
				}
			}
		}

		fmt.Fprintln(w, x, y)
	}

}

package main

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

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

func gcd(x, y int) int {
    if y == 0 {
        return x
    }
    return gcd(y, x % y)
}

func solve() {
    var a, b, c, d int
    Fscan(in, &a, &b, &c, &d)

    x, y := -1, -1
    for i := a + 1; i <= c; i++ {
        g := gcd(a * b, i)
        miny := (a * b / g) * (i / g)

        ty := (b / miny + 1) * miny

        if ty <= d {
            x, y = i, ty
            break
        }
    }

    Fprintln(out, x, y)
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

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

func gcd(x, y int) int {
    if y == 0 {
        return x
    }
    return gcd(y, x % y)
}

func solve() {
    var a, b, c, d int
    Fscan(in, &a, &b, &c, &d)

    x, y := -1, -1
    for i := a + 1; i <= c; i++ {
        g := gcd(a * b, i)
        miny := a * b * i / g / g

        ty := (b / miny + 1) * miny

        if ty <= d {
            x, y = i, ty
            break
        }
    }

    Fprintln(out, x, y)
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

func primeFactors(n int64) (pfs []int64) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := int64(3); i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

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 a, b, c, d int64
		fmt.Fscan(in, &a, &b, &c, &d)

		if a == 1 || b == 1 {
			fmt.Fprintln(out, c, d)
			continue
		}

		p1 := primeFactors(a)
		p2 := primeFactors(b)
		pp := []int64{}
		for _, v := range p1 {
			for k := range pp {
				if pp[k]*v > c && pp[k]*v > d {
					continue
				}
				pp[k] *= v
			}
			pp = append(pp, v)
		}

		for _, v := range p2 {
			for k := range pp {
				if pp[k]*v > c && pp[k]*v > d {
					continue
				}
				pp[k] *= v
			}
			pp = append(pp, v)
		}
		sort.Slice(pp, func(i, j int) bool {
			return pp[i] < pp[j]
		})

		// fmt.Println(pp)
		x := sort.Search(len(pp), func(i int) bool {
			return pp[i] > a
		})
		if x < len(pp) && pp[x] <= a {
			x++
		}
		y := sort.Search(len(pp), func(i int) bool {
			return pp[i] > b
		})
		if y < len(pp) && pp[y] <= b {
			y++
		}

		d1, d2 := int64(-1), int64(-1)
	Loop:
		for i := x; i < len(pp); i++ {
			if pp[i] > c {
				break
			}
			for j := y; j < len(pp); j++ {
				if pp[j] > d {
					break
				}
				if (pp[i]*pp[j])%(a*b) == 0 {
					d1, d2 = pp[i], pp[j]
					break Loop
				}
			}
		}

		fmt.Fprintln(out, d1, d2)
	}
}


Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the i-th section of this wall. You know that archer who stands at section i can shoot orcs that attack section located at distance not exceeding r, that is all such sections j that |i - j| ≤ r. In particular, r = 0 means that archers are only capable of shooting at orcs who attack section i.Denote as defense level of section i the total number of archers who can shoot at the orcs attacking this section. Reliability of the defense plan is the minimum value of defense level of individual wall section.There is a little time left till the attack so you can't redistribute archers that are already located at the wall. However, there is a reserve of k archers that you can distribute among wall sections in arbitrary way. You would like to achieve maximum possible reliability of the defence plan.

The first line of the input contains three integers n, r and k (1 ≤ n ≤ 500 000, 0 ≤ r ≤ n, 0 ≤ k ≤ 1018) — the number of sections of the wall, the maximum distance to other section archers can still shoot and the number of archers yet to be distributed along the wall. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the current number of archers at each section.

Print one integer — the maximum possible value of defense plan reliability, i.e. the maximum possible value of minimum defense level if we distribute k additional archers optimally.

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"bytes"
)

var k int64
var n, r int
var a []int64
var def []int64

var section []int
var archer []int64

func search(ans int64) bool {
	head, tail := 0, 0
	var sum, total int64

	for i := 0;i < n;i ++ {
		if head != tail && section[head] + r < i {
			sum -= archer[head]
			head ++
		}
		if def[i] + sum < ans {
			section[tail], archer[tail] = i + r, ans - (def[i] + sum)
			total += archer[tail]
			sum += archer[tail]
			if total > k {
				return false
			}
			tail ++
		}
	}
	return true
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d %d %d\n", &n, &r, &k)
	a = make([]int64, n)
	def = make([]int64, n)
	section = make([]int, n)
	archer = make([]int64, n)
	for i := 0;i < n;i ++ {
		if i < n - 1 {
			fmt.Fscanf(reader, "%d ", &a[i])
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i])
		}
	}
	sum := a[0]
	for i, left, right := 0, 0, 0;i < n; {
		if left < i - r {
			sum -= a[left]
			left ++
		} else if right < n - 1 && right < i + r {
			right ++
			sum += a[right]
		} else {
			def[i] = sum
			i ++
		}
	}
	left, right, ans := int64(0), int64(2000000000000000000), int64(0)
	for left <= right {
		mid := (left + right) / 2
		if search(mid) {
			ans = mid
			left = mid + 1
		} else {
			right = mid - 1
		}
	}
	fmt.Printf("%d", ans)
}

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"bytes"
)

var k int64
var n, r int
var a []int64
var def []int64

var section []int
var archer []int64

func search(ans int64) bool {
	head, tail := 0, 0
	var sum, total int64

	for i := 0;i < n;i ++ {
		if head != tail && section[head] + r < i {
			sum -= archer[head]
			head ++
		}
		if def[i] + sum < ans {
			section[tail], archer[tail] = i + r, ans - (def[i] + sum)
			total += archer[tail]
			sum += archer[tail]
			if total > k {
				return false
			}
			tail ++
		}
	}
	return true
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d %d %d\n", &n, &r, &k)
	a = make([]int64, n)
	def = make([]int64, n)
	section = make([]int, n)
	archer = make([]int64, n)
	for i := 0;i < n;i ++ {
		if i < n - 1 {
			fmt.Fscanf(reader, "%d ", &a[i])
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i])
		}
	}
	sum := a[0]
	for i, left, right := 0, 0, 0;i < n; {
		if left < i - r {
			sum -= a[left]
			left ++
		} else if right < n - 1 && right < i + r {
			right ++
			sum += a[right]
		} else {
			def[i] = sum
			i ++
		}
	}
	left, right, ans := int64(0), int64(1000000001000000000), int64(0)
	for left < right {
		mid := (left + right) / 2
		if search(mid) {
			ans = mid
			left = mid + 1
		} else {
			right = mid - 1
		}
	}
	fmt.Printf("%d", ans)
}

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"bytes"
)

var k int64
var n, r int
var a []int64
var def []int64

var section []int
var archer []int64

func search(ans int64) bool {
	head, tail := 0, 0
	var sum, total int64

	for i := 0;i < n;i ++ {
		if head != tail && section[head] + r < i {
			sum -= archer[head]
			head ++
		}
		if def[i] + sum < ans {
			section[tail], archer[tail] = i + r, ans - (def[i] + sum)
			total += archer[tail]
			sum += archer[tail]
			if total > k {
				return false
			}
			tail ++
		}
	}
	return true
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d %d %d\n", &n, &r, &k)
	a = make([]int64, n)
	def = make([]int64, n)
	section = make([]int, n)
	archer = make([]int64, n)
	for i := 0;i < n;i ++ {
		if i < n - 1 {
			fmt.Fscanf(reader, "%d ", &a[i])
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i])
		}
	}
	sum := a[0]
	for i, left, right := 0, 0, 0;i < n; {
		if left < i - r {
			sum -= a[left]
			left ++
		} else if right < n - 1 && right < i + r {
			right ++
			sum += a[right]
		} else {
			def[i] = sum
			i ++
		}
	}
	left, right, ans := int64(0), int64(1000000001000000000), int64(0)
	for left <= right {
		mid := (left + right) / 2
		if search(mid) {
			ans = mid
			left = mid + 1
		} else {
			right = mid - 1
		}
	}
	fmt.Printf("%d", ans)
}


You are given $$$n$$$ distinct points on a plane. The coordinates of the $$$i$$$-th point are $$$(x_i, y_i)$$$.For each point $$$i$$$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $$$n$$$ points. If there are multiple such points — you can choose any of them.The Manhattan distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of points in the set. The next $$$n$$$ lines describe points. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le 2 \cdot 10^5$$$) — coordinates of the $$$i$$$-th point. It is guaranteed that all points in the input are distinct.

Print $$$n$$$ lines. In the $$$i$$$-th line, print the point with integer coordinates that is not among the given $$$n$$$ points and is the nearest (in terms of Manhattan distance) to the $$$i$$$-th point from the input. Output coordinates should be in range $$$[-10^6; 10^6]$$$. It can be shown that any optimal answer meets these constraints. If there are several answers, you can print any of them.

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := make(map[pair]int, n*2)
	for i := 1; i <= n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct { i, j int; pair }
	q := []p2{}
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				ans[i-1] = w
				q = append(q, p2{v.x, v.y, w})
				break
			}
		}
	}
	for _, p := range q {
		delete(s, pair{p.i, p.j})
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.i + d.x, v.j + d.y}
			if i := s[w]; i > 0 {
				delete(s, w)
				ans[i-1] = v.pair
				q = append(q, p2{w.x, w.y, v.pair})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := map[pair]int{}
	for i := 1; i <= n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct { i, j int; pair }
	q := []p2{}
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				ans[i-1] = w
				q = append(q, p2{v.x, v.y, w})
				break
			}
		}
	}
	for _, p := range q {
		delete(s, pair{p.i, p.j})
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.i + d.x, v.j + d.y}
			if i := s[w]; i > 0 {
				delete(s, w)
				ans[i-1] = v.pair
				q = append(q, p2{w.x, w.y, v.pair})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := make(map[pair]int, n)
	for i := 1; i <= n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct { i, j int; pair }
	q := []p2{}
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				ans[i-1] = w
				q = append(q, p2{v.x, v.y, w})
				break
			}
		}
	}
	for _, p := range q {
		delete(s, pair{p.i, p.j})
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.i + d.x, v.j + d.y}
			if i := s[w]; i > 0 {
				delete(s, w)
				ans[i-1] = v.pair
				q = append(q, p2{w.x, w.y, v.pair})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := make(map[pair]int, n)
	for i := 1; i <= n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct { i, j int; pair }
	q := []p2{}
	vis := make(map[pair]bool, n)
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				ans[i-1] = w
				vis[v] = true
				q = append(q, p2{v.x, v.y, w})
				break
			}
		}
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.i + d.x, v.j + d.y}
			if i := s[w]; i > 0 && !vis[w] {
				ans[i-1] = v.pair
				vis[w] = true
				q = append(q, p2{w.x, w.y, v.pair})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := make(map[pair]int, n)
	for i := 1; i <= n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct{ x, y, ox, oy int }
	q := []p2{}
	vis := make(map[pair]bool, n)
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				ans[i-1] = w
				vis[v] = true
				q = append(q, p2{v.x, v.y, w.x, w.y})
				break
			}
		}
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			i := s[w]
			if i > 0 && !vis[w] {
				ans[i-1] = pair{v.ox, v.oy}
				vis[w] = true
				q = append(q, p2{w.x, w.y, v.ox, v.oy})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

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

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

	type pair struct {
		x, y int
	}
	type pair2 struct {
		x, y int
		pair
	}
	var n, x, y int
	fmt.Fscan(r, &n)
	pairList := make(map[pair]int, 0)
	for i := 1; i <= n; i++ {
		fmt.Fscan(r, &x, &y)
		pairList[pair{
			x: x,
			y: y,
		}] = i
	}

	dir := [][]int{{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
	ans := make([]pair, n)
	q := []pair2{}

	for v, i := range pairList {
		for _, d := range dir {
			x, y := v.x+d[0], v.y+d[1]
			p := pair{x: x, y: y}
			if _, ok := pairList[p]; !ok {
				ans[i-1] = p
				q = append(q, pair2{x: v.x, y: v.y, pair: p})
				break
			}
		}
	}
	for _, p := range q {
		delete(pairList, pair{
			x: p.x,
			y: p.y,
		})
	}

	for len(q) > 0 {
		tmp := q
		q = nil
		for _, v := range tmp {
			for _, d := range dir {
				x, y := v.x+d[0], v.y+d[1]
				p := pair{
					x: x,
					y: y,
				}
				if i, ok := pairList[p]; ok {
					delete(pairList, p)
					ans[i-1] = v.pair
					q = append(q, pair2{
						x:    x,
						y:    y,
						pair: v.pair,
					})
				}
			}
		}
	}

	for _, v := range ans {
		fmt.Fprintln(w, v.x, v.y)
	}

}

type uf struct {
	fa, sz  []int
	groups  int
	maxSize int
}

func newUnionFind(n int, a []int) uf {
	fa := make([]int, n)
	sz := make([]int, n)
	for i := range fa {
		fa[i] = i
		sz[i] = a[i]
	}
	return uf{fa, sz, n, 1}
}

func (u uf) find(x int) int {
	if u.fa[x] != x {
		u.fa[x] = u.find(u.fa[x])
	}
	return u.fa[x]
}

func (u *uf) merge(from, to int) (isNewMerge int) {
	x, y := u.find(from), u.find(to)
	if x == y {
		return 0
	}
	u.fa[x] = y
	u.sz[y] += u.sz[x]
	if u.sz[y] > u.maxSize {
		u.maxSize = u.sz[y]
	}
	u.groups--
	return u.sz[y]
}

func (u uf) same(x, y int) bool { return u.find(x) == u.find(y) }
func (u uf) size(x int) int     { return u.sz[u.find(x)] }

func sum(a, b int) int {
	return a + b
}

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

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

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

func gcd(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func maxFloat(a, b float64) float64 {
	if b > a {
		return b
	}
	return a
}

func minFloat(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

package main

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

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

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

	type pair struct {
		x, y int
	}
	type pair2 struct {
		x, y int
		pair
	}
	var n, x, y int
	fmt.Fscan(r, &n)
	pairList := make(map[pair]int, 0)
	for i := 1; i <= n; i++ {
		fmt.Fscan(r, &x, &y)
		pairList[pair{
			x: x,
			y: y,
		}] = i
	}

	dir := [][]int{{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
	ans := make([]pair, n)
	q := []pair2{}

	for v, i := range pairList {
		for _, d := range dir {
			x, y := v.x+d[0], v.y+d[1]
			p := pair{x: x, y: y}
			if _, ok := pairList[p]; !ok {
				ans[i-1] = p
				q = append(q, pair2{x: x, y: y, pair: p})
				break
			}
		}
	}
	for len(q) > 0 {
		tmp := q
		q = nil
		for _, v := range tmp {
			for _, d := range dir {
				x, y := v.x+d[0], v.y+d[1]
				p := pair{
					x: x,
					y: y,
				}
				if i, ok := pairList[p]; ok {
					delete(pairList, p)
					ans[i-1] = v.pair
					q = append(q, pair2{
						x:    x,
						y:    y,
						pair: v.pair,
					})
				}
			}
		}
	}

	for _, v := range ans {
		fmt.Fprintln(w, v.x, v.y)
	}

}

type uf struct {
	fa, sz  []int
	groups  int
	maxSize int
}

func newUnionFind(n int, a []int) uf {
	fa := make([]int, n)
	sz := make([]int, n)
	for i := range fa {
		fa[i] = i
		sz[i] = a[i]
	}
	return uf{fa, sz, n, 1}
}

func (u uf) find(x int) int {
	if u.fa[x] != x {
		u.fa[x] = u.find(u.fa[x])
	}
	return u.fa[x]
}

func (u *uf) merge(from, to int) (isNewMerge int) {
	x, y := u.find(from), u.find(to)
	if x == y {
		return 0
	}
	u.fa[x] = y
	u.sz[y] += u.sz[x]
	if u.sz[y] > u.maxSize {
		u.maxSize = u.sz[y]
	}
	u.groups--
	return u.sz[y]
}

func (u uf) same(x, y int) bool { return u.find(x) == u.find(y) }
func (u uf) size(x int) int     { return u.sz[u.find(x)] }

func sum(a, b int) int {
	return a + b
}

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

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

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

func gcd(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func maxFloat(a, b float64) float64 {
	if b > a {
		return b
	}
	return a
}

func minFloat(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

package main

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

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

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

	type pair struct {
		x, y int
	}
	type pair2 struct {
		x, y int
		pair
	}
	var n, x, y int
	fmt.Fscan(r, &n)
	pairList := make(map[pair]int, 0)
	for i := 1; i <= n; i++ {
		fmt.Fscan(r, &x, &y)
		pairList[pair{
			x: x,
			y: y,
		}] = i
	}

	dir := [][]int{{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
	ans := make([]pair, n)
	q := []pair2{}

	for v, i := range pairList {
		for _, d := range dir {
			x, y := v.x+d[0], v.y+d[1]
			p := pair{x: x, y: y}
			if _, ok := pairList[p]; !ok {
				ans[i-1] = p
				q = append(q, pair2{x: x, y: y, pair: p})
				break
			}
		}
	}
	for _, v := range q {
		delete(pairList, pair{
			x: v.x,
			y: v.y,
		})
	}

	for len(q) > 0 {
		tmp := q
		q = nil
		for _, v := range tmp {
			for _, d := range dir {
				x, y := v.x+d[0], v.y+d[1]
				p := pair{
					x: x,
					y: y,
				}
				if i, ok := pairList[p]; ok {
					delete(pairList, p)
					ans[i-1] = v.pair
					q = append(q, pair2{
						x:    x,
						y:    y,
						pair: v.pair,
					})
				}
			}
		}
	}

	for _, v := range ans {
		fmt.Fprintln(w, v.x, v.y)
	}

}

type uf struct {
	fa, sz  []int
	groups  int
	maxSize int
}

func newUnionFind(n int, a []int) uf {
	fa := make([]int, n)
	sz := make([]int, n)
	for i := range fa {
		fa[i] = i
		sz[i] = a[i]
	}
	return uf{fa, sz, n, 1}
}

func (u uf) find(x int) int {
	if u.fa[x] != x {
		u.fa[x] = u.find(u.fa[x])
	}
	return u.fa[x]
}

func (u *uf) merge(from, to int) (isNewMerge int) {
	x, y := u.find(from), u.find(to)
	if x == y {
		return 0
	}
	u.fa[x] = y
	u.sz[y] += u.sz[x]
	if u.sz[y] > u.maxSize {
		u.maxSize = u.sz[y]
	}
	u.groups--
	return u.sz[y]
}

func (u uf) same(x, y int) bool { return u.find(x) == u.find(y) }
func (u uf) size(x int) int     { return u.sz[u.find(x)] }

func sum(a, b int) int {
	return a + b
}

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

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

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

func gcd(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func maxFloat(a, b float64) float64 {
	if b > a {
		return b
	}
	return a
}

func minFloat(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

package main

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

func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	dx := []int{0, 0, -1, 1}
	dy := []int{-1, 1, 0, 0}

	type pair struct{ x, y int }

	var n int
	Fscan(in, &n)
	a := make([]pair, n)
	st := make(map[pair]int)
	for i := 0; i < n; i++ {
		Fscan(in, &a[i].x, &a[i].y)
		st[a[i]] = 1;
	}

	res := make(map[pair]pair)
	var q []pair
	for _, p := range a {
		x , y := p.x, p.y
		for i := 0; i < 4; i++ {
			nx, ny := x + dx[i], y + dy[i]
			if st[pair{nx, ny}] == 0 {
				res[pair{x, y}] = pair{nx, ny}
				q = append(q, pair{x, y})
				break
			}
		}
	}

	for len(q) != 0 {
		x, y := q[0].x, q[0].y
		q = q[1:]
		for i := 0; i < 4; i++ {
			nx, ny := x + dx[i], y + dy[i]
			if _, err := res[pair{nx, ny}]; st[pair{nx, ny}] == 0 || err {
				continue
			}
			res[pair{nx, ny}] = res[pair{x, y}]
			q = append(q, pair{nx, ny})
		}
	}

	for _, p := range a {
		x, y := p.x, p.y
		it := res[pair{x, y}]
		Fprintln(out, it.x, it.y)
	}
}

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

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := make(map[pair]int, n)
	for i := 1; i <= n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct { i, j int; pair }
	q := []p2{}
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				delete(s, v)
				ans[i-1] = w
				q = append(q, p2{v.x, v.y, w})
				break
			}
		}
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.i + d.x, v.j + d.y}
			if i := s[w]; i > 0 {
				delete(s, w)
				ans[i-1] = v.pair
				q = append(q, p2{w.x, w.y, v.pair})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

// https://space.bilibili.com/206214
func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, x, y int
	Fscan(in, &n)
	s := make(map[pair]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &x, &y)
		s[pair{x, y}] = i
	}

	ans := make([]pair, n)
	type p2 struct { i, j int; pair }
	q := []p2{}
	vis := make(map[pair]bool, n)
	for v, i := range s {
		for _, d := range dir4 {
			w := pair{v.x + d.x, v.y + d.y}
			if s[w] == 0 {
				ans[i] = w
				vis[v] = true
				q = append(q, p2{v.x, v.y, w})
				break
			}
		}
	}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		for _, d := range dir4 {
			w := pair{v.i + d.x, v.j + d.y}
			if i, ok := s[w]; ok && !vis[w] {
				ans[i] = v.pair
				vis[w] = true
				q = append(q, p2{w.x, w.y, v.pair})
			}
		}
	}
	for _, p := range ans {
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

func CF1651D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	dx := []int{-1, 1, 0, 0}
	dy := []int{0, 0, -1, 1}

	type pair struct{ x, y int }

	var n int
	Fscan(in, &n)
	a := make([]pair, n)
	for i := 0; i < n; i++ {
		var x, y int
		Fscan(in, &x, &y)
		a[i] = pair{x, y}
	}

	st := make(map[pair]int)
	res := make(map[pair]pair)
	var q []pair
	for _, p := range a {
		x , y := p.x, p.y
		for i := 0; i < 4; i++ {
			nx, ny := x + dx[i], y + dy[i]
			if st[pair{nx, ny}] == 0 {
				res[pair{x, y}] = pair{nx, ny}
				q = append(q, pair{x, y})
			}
		}
	}

	for len(q) != 0 {
		x, y := q[0].x, q[0].y
		q = q[1:]
		for i := 0; i < 4; i++ {
			nx, ny := x + dx[i], y + dy[i]
			if _, err := res[pair{nx, ny}]; st[pair{nx, ny}] == 0 || !err {
				continue
			}
			res[pair{nx, ny}] = pair{x, y}
			q = append(q, pair{nx, ny})
		}
	}

	for _, p := range a {
		x, y := p.x, p.y
		it := res[pair{x, y}]
		Fprintln(out, it.x, it.y)
	}
}

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


You are given a set $$$S$$$, which contains the first $$$n$$$ positive integers: $$$1, 2, \ldots, n$$$.You can perform the following operation on $$$S$$$ any number of times (possibly zero):   Choose a positive integer $$$k$$$ where $$$1 \le k \le n$$$, such that there exists a multiple of $$$k$$$ in $$$S$$$. Then, delete the smallest multiple of $$$k$$$ from $$$S$$$. This operation requires a cost of $$$k$$$. You are given a set $$$T$$$, which is a subset of $$$S$$$. Find the minimum possible total cost of operations such that $$$S$$$ would be transformed into $$$T$$$. We can show that such a transformation is always possible.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The description of the test cases follows. The first line contains a single positive integer $$$n$$$ ($$$1 \le n \le 10^6$$$). The second line of each test case contains a binary string of length $$$n$$$, describing the set $$$T$$$. The $$$i$$$-th character of the string is '1' if and only if $$$i$$$ is an element of $$$T$$$, and '0' otherwise. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.

For each test case, output one non-negative integer — the minimum possible total cost of operations such that $$$S$$$ would be transformed into $$$T$$$.

NoteIn the first test case, we shall not perform any operations as $$$S$$$ is already equal to $$$T$$$, which is the set $$$\{1, 2, 3, 4, 5, 6\}$$$.In the second test case, initially, $$$S = \{1, 2, 3, 4, 5, 6, 7\}$$$, and $$$T = \{1, 2, 4, 7\}$$$. We shall perform the following operations:   Choose $$$k=3$$$, then delete $$$3$$$ from $$$S$$$.  Choose $$$k=3$$$, then delete $$$6$$$ from $$$S$$$.  Choose $$$k=5$$$, then delete $$$5$$$ from $$$S$$$. The total cost is $$$3+3+5 = 11$$$. It can be shown that this is the smallest cost possible.In the third test case, initially, $$$S = \{1, 2, 3, 4\}$$$ and $$$T = \{\}$$$ (empty set). We shall perform $$$4$$$ operations of $$$k=1$$$ to delete $$$1$$$, $$$2$$$, $$$3$$$, and $$$4$$$.In the fourth test case, initially, $$$S = \{1, 2, 3, 4\}$$$ and $$$T = \{3\}$$$. We shall perform two operations with $$$k=1$$$ to delete $$$1$$$ and $$$2$$$, then perform one operation with $$$k=2$$$ to delete $$$4$$$.

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }

func BAAL() {
	in := os.Stdin
	out := os.Stdout
	iost = NewIost(in, out)
}

func main() {
	BAAL()
	defer func() {
		iost.Writer.Flush()
	}()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		n := iost.GetNextInt()
		s := iost.Text()
		var a []byte
		for i := 0; i < n; i++ {
			a = append(a, s[i])
		}
		o := 0
		for i := 1; i <= n; i++ {
			for j := i; j <= n; j += i {
				k := j - 1
				if a[k] == '1' {
					break
				} else if a[k] == '0' {
					o += i
					a[k] = byte('2')
				}
			}
		}
		iost.Println(o)
	}
}

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 int
		var s string
		fmt.Fscan(in, &n, &s)

		var tot int64
		aa := make([]bool, n+1)
		for i, ch := range s {
			if ch == '1' {
				aa[i+1] = true
			}
		}

		bb := make([]bool, n+1)
		for i, ch := range s {
			if ch == '0' {
				k := i + 1
				for j := 1; k*j <= n; j++ {
					if aa[k*j] {
						break
					}
					if bb[k*j] {
						continue
					}

					bb[k*j] = true
					tot += int64(k)
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		var s []byte
		Fscan(in, &n, &s)
		cost := make([]int, n+1)
		ans := int64(0)
		for i := 1; i <= n; i++ {
			if s[i-1] == '1' {
				continue
			}
			for j := i; j <= n && s[j-1] == '0'; j += i {
				if cost[j] == 0 {
					cost[j] = i
				}
			}
			//if cost[i] == 0 {
			//
			//} else {
			//	//newC := false
			//	for j := i * 2; j <= n && s[j-1] == '0'; j += i {
			//		if cost[j] == 0 {
			//			cost[j] = i
			//			//newC = true
			//		}
			//	}
			//	//if newC {
			//	//	cost[i] = i
			//	//}
			//}
		}
		for _, v := range cost {
			ans += int64(v)
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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


Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki people. The j-th person standing in the queue to the i-th cashier has mi, j items in the basket. Vasya knows that:  the cashier needs 5 seconds to scan one item;  after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.

The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier. The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, ..., mi, ki (1 ≤ mi, j ≤ 100) — the number of products the j-th person in the queue for the i-th cash has.

Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.

NoteIn the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.

package main

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

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

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

	n := nextInt()

	k := make([]int, n)

	for i:=0; i<n; i++ {
		k[i] = nextInt()
	}

	result, totalSecond := math.MaxInt32, 0

	for i:=0; i<n; i++ {
		totalSecond = 15 * k[i]

		for j:=0; j<k[i]; j++ {
			totalSecond += 5 * nextInt()
		}

		if totalSecond < result {
			result = totalSecond
		}
		// fmt.Println(totalSecond, n, k)
	}

	println(result)
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main
import (
	"fmt"
)
func main() {
	var n,t,m int
	min:=10000000
	a:=make([]int,105)
	fmt.Scan(&n)
	for i:=0;i<n;i++ {
		fmt.Scan(&a[i])
	}
	for i:=0;i<n;i++ {
		t=0
		for j:=0;j<a[i];j++ {
			fmt.Scan(&m)
			t+=m
		}
		if t*5+a[i]*15<min {
			min=t*5+a[i]*15
		}
	}
	fmt.Println(min)
}

package main

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

var (
    reader = bufio.NewReader(os.Stdin)
)

func main() {
    var (
        n, k, min int
        cash      [110]int
    )
    fmt.Fscan(reader, &n)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &cash[i])
    }
    min = 1e9 + 1
    for i := 0; i < n; i++ {
        sum := 0
        for j := 0; j < cash[i]; j++ {
            fmt.Fscan(reader, &k)
            sum += k
        }
        sum = sum*5 + cash[i]*15
        if sum < min {
            min = sum
        }
    }
    fmt.Println(min)
}

package main

import "fmt"

func main() {
    var n int
    var m [105]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ { fmt.Scan(&m[i]) }
    ans := 1000000000
    for i := 0; i < n; i++ {
        total := 0
        var a int
        for j := 0; j < m[i]; j++ {
            fmt.Scan(&a)
            total += (a*5)+15
        }
        if ans > total { ans = total }
    }
    fmt.Println(ans)
}

/*********************************************************************************
*     File Name           :     A.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-04-06 16:51]
*     Last Modified       :     [2014-04-06 16:59]
*     Description         :
**********************************************************************************/

package main

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

func main() {
    in.Split(bufio.ScanWords)

    n := in.NextInt()
    k := make([]int, n)
    for i := 0; i < n; i++ {
        k[i] = in.NextInt()
    }
    ans := 0x7fffffff
    for i := 0; i < n; i++ {
        sum := 0
        for j := 0; j < k[i]; j++ {
            sum += in.NextInt()
        }
        if sum*5+k[i]*15 < ans {
            ans = sum*5 + k[i]*15
        }
    }
    fmt.Println(ans)
}

type Scanner struct {
    *bufio.Scanner
}

var in = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

// 408A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, now, d int
    var a [542]int
    res := 10000000
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    for i := 0; i < n; i++ {
        now = 0
        for j := 0; j < a[i]; j++ {
            fmt.Scan(&d)
            now = now + d*5
        }
        now += a[i] * 15
        res = int(math.Min(float64(now), float64(res)))
    }
    fmt.Println(res)
}