You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0). It is guaranteed that p / q is an irreducible fraction. Hacks. For hacks, an additional constraint of t ≤ 5 must be met.

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

NoteIn the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	for _, b := range in.Bytes() {
		res = res*10 + int64(b-'0')
	}
	return res
}

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

	for t := readInt(); t > 0; t-- {
		x := readInt()
		y := readInt()
		p := readInt()
		q := readInt()
		if p == 0 && x > 0 || p == q && x != y {
			fmt.Fprintln(out, -1)
			continue
		}
		fmt.Fprintln(out, -y+q*int64(sort.Search(1e9, func(kk int) bool {
			k := int64(kk)
			if k*q < y {
				return false
			}
			ma := k*q - y + x
			return x <= k*p && k*p <= ma
		})))
	}
}

package main

import (
	"fmt"
)

func check(x, y, p, q, total int64) bool{
	pp := total / q * p
	return x <= pp && total - y >= pp - x
}

func main ()  {
	var x, y, p, q int64
	var t int
	fmt.Scan(&t)
	for idx := 0; idx < t; idx++{
		var ans int64 = -1
		fmt.Scan(&x, &y, &p, &q)
		if x * q == y * p {
			fmt.Println(0)
			continue
		}
		var l , r int64
		l = 0
		r = 4223372036854775800
		for ; ; {
			if l == r{
				break;
			}
			tmp := (l + r ) / 2
			mid := tmp - tmp % q
			//fmt.Println(l, r, mid, tmp)
			if mid < l{
				l = tmp + 1
				continue
			}
			if check(x, y, p, q, mid){
				ans = mid
				r = mid - 1
			}else{
				l = mid + 1
			}
		}
		if ans >= 0{
			fmt.Println(ans - y)
		}else {
			fmt.Println(-1)
		}
	}
}

package main

import "fmt"

var t int
var x, y, p, q int64
var ansa, ansb, ansc int64

func main() {
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&x)
		fmt.Scan(&y)
		fmt.Scan(&p)
		fmt.Scan(&q)
		y -= x
		q -= p
		if p == 0 {
			if x != 0 {
				goto fail
			} else {
				goto success
			}
		}
		if q == 0 {
			if y != 0 {
				goto fail
			} else {
				goto success
			}
		}

		ansa = x / p
		if x%p != 0 {
			ansa++
		}
		ansb = y / q
		if y%q != 0 {
			ansb++
		}

		if ansa > ansb {
			ansc = ansa
		} else {
			ansc = ansb
		}

		fmt.Println(ansc*p - x + ansc*q - y)
		continue
	fail:
		fmt.Println("-1")
		continue
	success:
		fmt.Println("0")
		continue
	}
}

package main

import (
	"fmt"
)

func check(x, y, p, q, total int64) bool{
	pp := total / q * p
	return x <= pp && total - y >= pp - x
}

func main ()  {
	var x, y, p, q int64
	var t int
	fmt.Scan(&t)
	for idx := 0; idx < t; idx++{
		var ans int64 = -1
		fmt.Scan(&x, &y, &p, &q)
		if x * q == y * p {
			fmt.Println(0)
			continue
		}
		var l , r int64
		l = 0;
		r = 10000000000000000
		for ; ; {
			if l == r{
				break;
			}
			tmp := (l + r ) / 2
			mid := tmp - tmp % q
			//fmt.Println(l, r, mid, tmp)
			if mid < l{
				l = tmp + 1
				continue
			}
			if check(x, y, p, q, mid){
				ans = mid
				r = mid - 1
			}else{
				l = mid + 1
			}
		}
		if ans >= 0{
			fmt.Println(ans - y)
		}else {
			fmt.Println(-1)
		}
	}
}


You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are $$$n$$$ bosses in this tower, numbered from $$$1$$$ to $$$n$$$. The type of the $$$i$$$-th boss is $$$a_i$$$. If the $$$i$$$-th boss is easy then its type is $$$a_i = 0$$$, otherwise this boss is hard and its type is $$$a_i = 1$$$.During one session, either you or your friend can kill one or two bosses (neither you nor your friend can skip the session, so the minimum number of bosses killed during one session is at least one). After your friend session, your session begins, then again your friend session begins, your session begins, and so on. The first session is your friend's session.Your friend needs to get good because he can't actually kill hard bosses. To kill them, he uses skip points. One skip point can be used to kill one hard boss.Your task is to find the minimum number of skip points your friend needs to use so you and your friend kill all $$$n$$$ bosses in the given order.For example: suppose $$$n = 8$$$, $$$a = [1, 0, 1, 1, 0, 1, 1, 1]$$$. Then the best course of action is the following:  your friend kills two first bosses, using one skip point for the first boss;  you kill the third and the fourth bosses;  your friend kills the fifth boss;  you kill the sixth and the seventh bosses;  your friend kills the last boss, using one skip point, so the tower is completed using two skip points. You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of bosses. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the type of the $$$i$$$-th boss. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer: the minimum number of skip points your friend needs to use so you and your friend kill all $$$n$$$ bosses in the given order.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func Sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	// x, y, k := nextLong()-1, nextLong(), nextLong()
	// printf("%d\n", k+((y+1)*k+x-2)/x)
	n := nextInt()
	arr := make([]int, n+1)
	for i := 0; i < n; i++ {
		arr[i] = nextInt()
	}

	dp := [2][]int{make([]int, n+2), make([]int, n+2)}
	for i := n - 1; i >= 0; i-- {
		dp[0][i] = Min(dp[1][i+1]+arr[i], dp[1][i+2]+arr[i]+arr[i+1])
		dp[1][i] = Min(dp[0][i+1], dp[0][i+2])
	}
	printf("%d\n", dp[0][0])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "foreign"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// 	printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func solve(n int, A []int) int {
	if n == 1 {
		return A[0]
	}
	// dp[i][0] = min(dp[i-1][1] + x, dp[i-2][1] + x + y)
	// dp[i][1] = dp[i-1][0]

	dp := make([][]int, 3)
	for i := 0; i < 3; i++ {
		dp[i] = make([]int, 2)
		for j := 0; j < 2; j++ {
			dp[i][j] = n
		}
	}

	dp[0][0] = A[0]
	dp[1][0] = A[0] + A[1]
	dp[1][1] = A[0]
	//dp[1][0] = A[0] + A[1]
	for i := 2; i < n; i++ {
		dp[idx(i)][1] = min(dp[idx(i-1)][0], dp[idx(i-2)][0])
		dp[idx(i)][0] = min(dp[idx(i-1)][1]+A[i], dp[idx(i-2)][1]+A[i-1]+A[i])
	}

	return min(dp[idx(n-1)][0], dp[idx(n-1)][1])
}

func idx(i int) int {
	i = i % 3
	i = (i + 3) % 3
	return i
}

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func solve(arr []int) int {
	ans := arr[0]

	for i := 1; i < len(arr); i++ {
		if arr[i] == 0 {
			continue
		}

		j := i
		for j < len(arr) && arr[j] == 1 {
			j++
		}

		ans += (j - i) / 3
		i = j - 1
	}

	return ans
}

func main() {
	defer writer.Flush()

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

	for t > 0 {
		scanf("%d\n", &n)
		arr = make([]int, n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		scanf("\n")
		ans := solve(arr)
		printf("%d\n", ans)
		t--
	}
}

/*
URL:
https://codeforces.com/contest/1418/problem/C
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

func solve() {
	// j: 自分 or フレンド, k: 回数
	dp := [][2][2]int{}
	for i := 0; i <= n; i++ {
		row := [2][2]int{}
		dp = append(dp, row)
	}

	for i := 0; i <= n; i++ {
		for j := 0; j < 2; j++ {
			for k := 0; k < 2; k++ {
				dp[i][j][k] = INF_B30
			}
		}
	}

	dp[0][0][0] = 0
	for i := 0; i < n; i++ {
		if A[i] == 0 {
			// フレンド
			ChMin(&dp[i+1][0][1], dp[i][0][0])
			ChMin(&dp[i+1][1][0], dp[i][0][0])
			ChMin(&dp[i+1][1][0], dp[i][0][1])

			// 自分
			ChMin(&dp[i+1][1][1], dp[i][1][0])
			ChMin(&dp[i+1][0][0], dp[i][1][0])
			ChMin(&dp[i+1][0][0], dp[i][1][1])
		} else {
			// フレンド
			ChMin(&dp[i+1][0][1], dp[i][0][0]+1)
			ChMin(&dp[i+1][1][0], dp[i][0][0]+1)
			ChMin(&dp[i+1][1][0], dp[i][0][1]+1)

			// 自分
			ChMin(&dp[i+1][1][1], dp[i][1][0])
			ChMin(&dp[i+1][0][0], dp[i][1][0])
			ChMin(&dp[i+1][0][0], dp[i][1][1])
		}
	}

	ans := INF_B30
	for j := 0; j < 2; j++ {
		for k := 0; k < 2; k++ {
			ChMin(&ans, dp[n][j][k])
		}
	}
	fmt.Println(ans)
}

// func solve() {
// 	dp := [][]int{}
// 	for i := 0; i <= n; i++ {
// 		row := make([]int, 2)
// 		dp = append(dp, row)
// 	}

// 	for i := 0; i <= n; i++ {
// 		for j := 0; j < 2; j++ {
// 			dp[i][j] = INF_B30
// 		}
// 	}

// 	dp[0][0] = 0
// 	for i := 0; i < n; i++ {
// 		if A[i] == 0 {
// 			ChMin(&dp[i+1][1], dp[i][0])
// 		} else {

// 		}
// 	}
// }

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
)

// modi can calculate a right residual whether value is positive or negative.
func modi(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

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

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

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

var (
	// reads returns a WORD string.
	reads  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()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

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

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

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

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(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"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		h := make([]bool, n)
		for i := range h {
			Fscan(in, &h[i])
		}
		dp := make([][2][2]int, n)
		for i := range dp {
			dp[i] = [2][2]int{{-1, -1}, {-1, -1}}
		}
		var f func(p, who, c int) int
		f = func(p, who, c int) (res int) {
			if p == n {
				return
			}
			dv := &dp[p][who][c]
			if *dv != -1 {
				return *dv
			}
			defer func() { *dv = res }()
			res = f(p+1, who^1, 0)
			if c == 0 {
				res = min(res, f(p+1, who, 1))
			}
			if who == 0 && h[p] {
				res++
			}
			return
		}
		Fprintln(out, f(0, 0, 0))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		hard := make([]bool, n)
		for i := range hard {
			Fscan(in, &hard[i])
		}
		dp := make([][2][2]int, n)
		for i := range dp {
			dp[i] = [2][2]int{{-1, -1}, {-1, -1}}
		}
		var f func(p, who, killed int) int
		f = func(p, who, killed int) (res int) {
			if p == n {
				return
			}
			dv := &dp[p][who][killed]
			if *dv != -1 {
				return *dv
			}
			defer func() {
				if hard[p] && who == 0 {
					res++
				}
				*dv = res
			}()
			if killed == 0 {
				return min(f(p+1, who, 1), f(p+1, who^1, 0))
			} else {
				return f(p+1, who^1, 0)
			}
		}
		Fprintln(out, f(0, 0, 0))
	}
}

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

package main

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

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
defer w.Flush()

var q int
scan(&q)
for ; q > 0; q-- {
	var n int
	scan(&n)
	var a = make([]int, n)
	var ans = 0
	for i:=0; i< n; i++ {
		scan(&a[i])
	}
	var turn = true
	for i:= 0; i < n; {
		if turn {
			if a[i] == 1 {
				ans++
			}
			i++
			if i < n && a[i] == 0 {
				if i+1 < n && a[i+1] == 1 {
					i++;
				}
			}
		}else{
			i++
				if i<n && a[i] == 1 {
					i++;
				}else if i+1 < n && a[i+1] == 0 {
					i++;
				}
			}
			turn = !turn
		}
		print(ans, "\n")
	}
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func Mins(x *int, y int) {
	if y < *x {
		*x = y
	}
}
func solveCase() {
	n := rw.NextInt()
	a := rw.NextInts(n)
	dp := make([]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = 1e9
	}
	dp[0] = 0
	for i := 0; i <= n; i++ {
		if i+1 <= n {
			Mins(&dp[i+1], dp[i]+a[i])
		}
		if i+2 <= n {
			Mins(&dp[i+2], dp[i]+a[i])
		}
		if i+3 <= n {
			Mins(&dp[i+3], dp[i]+a[i])
		}
		if i+4 <= n {
			Mins(&dp[i+4], dp[i]+a[i]+a[i+1])
		}
	}
	rw.Println(dp[n])
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

import "fmt"

func solve(arr []int) int {
	ans := arr[0]

	for i := 1; i < len(arr); i++ {
		if arr[i] == 0 {
			continue
		}

		j := i
		for j < len(arr) && arr[j] == 1 {
			j++
		}

		ans += (j - i) / 3
		i = j - 1
	}

	return ans
}

func main() {
	var t int
	var n int
	var arr []int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		fmt.Scanf("%d\n", &n)
		arr = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &arr[i])
		}
		// fmt.Scanf("\n")
		ans := solve(arr)
		fmt.Println(ans)
		t--
	}
}

package main

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

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
defer w.Flush()

var q int
scan(&q)
for ; q > 0; q-- {
	var n int
	scan(&n)
	var a = make([]int, n)
	var ans = 0
	for i:=0; i< n; i++ {
		scan(&a[i])
	}
	var turn = true
	for i:= 0; i < n; {
		if turn {
			if a[i] == 1 {
				ans++
			}
			i++
			if i < n && a[i] == 0 {
				i++
			}
		}else{
			i++
				if i<n && a[i] == 1 {
					i++;
				}else if i+1 < n && a[i+1] == 0 {
					i++;
				}
			}
			turn = !turn
		}
		print(ans, "\n")
	}
}


There is a chessboard of size $$$n$$$ by $$$n$$$. The square in the $$$i$$$-th row from top and $$$j$$$-th column from the left is labelled $$$(i,j)$$$.Currently, Gregor has some pawns in the $$$n$$$-th row. There are also enemy pawns in the $$$1$$$-st row. On one turn, Gregor moves one of his pawns. A pawn can move one square up (from $$$(i,j)$$$ to $$$(i-1,j)$$$) if there is no pawn in the destination square. Additionally, a pawn can move one square diagonally up (from $$$(i,j)$$$ to either $$$(i-1,j-1)$$$ or $$$(i-1,j+1)$$$) if and only if there is an enemy pawn in that square. The enemy pawn is also removed.Gregor wants to know what is the maximum number of his pawns that can reach row $$$1$$$?Note that only Gregor takes turns in this game, and the enemy pawns never move. Also, when Gregor's pawn reaches row $$$1$$$, it is stuck and cannot make any further moves.

The first line of the input contains one integer $$$t$$$ ($$$1\le t\le 2\cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$2\le n\le 2\cdot{10}^{5}$$$) — the size of the chessboard. The second line consists of a string of binary digits of length $$$n$$$, where a $$$1$$$ in the $$$i$$$-th position corresponds to an enemy pawn in the $$$i$$$-th cell from the left, and $$$0$$$ corresponds to an empty cell. The third line consists of a string of binary digits of length $$$n$$$, where a $$$1$$$ in the $$$i$$$-th position corresponds to a Gregor's pawn in the $$$i$$$-th cell from the left, and $$$0$$$ corresponds to an empty cell. It is guaranteed that the sum of $$$n$$$ across all test cases is less than $$$2\cdot{10}^{5}$$$.

For each test case, print one integer: the maximum number of Gregor's pawns which can reach the $$$1$$$-st row.

NoteIn the first example, Gregor can simply advance all $$$3$$$ of his pawns forward. Thus, the answer is $$$3$$$.In the second example, Gregor can guarantee that all $$$4$$$ of his pawns reach the enemy row, by following the colored paths as demonstrated in the diagram below. Remember, only Gregor takes turns in this "game"!  In the third example, Gregor's only pawn is stuck behind the enemy pawn, and cannot reach the end.In the fourth example, Gregor has no pawns, so the answer is clearly $$$0$$$.

package main

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

func main() {
	var (
		test int
		n    int
	)
	inp := bufio.NewScanner(os.Stdin)
	inp.Buffer(make([]byte, 1000000), 1000000)

	inp.Scan()
	fmt.Sscanf(inp.Text(), "%d", &test)
	for tt := 0; tt < test; tt++ {
		inp.Scan()
		fmt.Sscanf(inp.Text(), "%d", &n)
		inp.Scan()
		s := inp.Bytes()
		inp.Scan()
		t := inp.Bytes()
		var mark = make([]bool, n)
		var ans int
		for i := 0; i < n; i++ {
			if t[i] == '1' {
				if i > 0 && s[i-1] == '1' && !mark[i-1] {
					ans++
				} else if s[i] == '0' && !mark[i] {
					mark[i] = true
					ans++
				} else if i+1 < n && s[i+1] == '1' && !mark[i+1] {
					mark[i+1] = true
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)
func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read,&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Fscan(read,&n)
	var s1, s2 string
	fmt.Fscan(read,&s1)
	fmt.Fscan(read,&s2)
	//var a, b = make([]byte, n)
	a := []byte(s1)
	b := []byte(s2)
	var count int = 0
	for i := 0; i < n; i++ {
		if b[i] == '1' {
			if i > 0 && a[i-1] == '1' {
				count++
			} else if a[i] == '0' {
				count++
				a[i] = '2'
			} else if i < n-1 && a[i+1] == '1' {
				count++
				a[i+1] = '2'
			}
		}
	}
	fmt.Fprintln(write,count)
}

package main

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

func main() {
	t := 0
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 1000000), 1000000)
	s.Scan()
	fmt.Sscanf(s.Text(), "%d", &t)

	for k := 0; k < t; k++ {
		var n int
		s.Scan()
		fmt.Sscanf(s.Text(), "%d", &n)
		s.Scan()
		a := s.Bytes()
		s.Scan()
		b := s.Bytes()

		res := 0
		for i := 0; i < n; i++ {
			if b[i] == '1' {
				if i > 0 && a[i-1] == '1' {
					res++
				} else if a[i] == '0' {
					a[i] = '2'
					res++
				} else if i < n-1 && a[i+1] == '1' {
					a[i+1] = '2'
					res++
				}
			}
		}
		fmt.Println(res)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var top,bottom string
		fmt.Fscan(in,&top,&bottom)
		row2:= strings.Split(top,"")
		row1:= strings.Split(bottom,"")
		counter:=0
		for k:=0;k<n;k++{ //empties
			if string(row1[k]) == "1" && string(row2[k]) == "0"{
				counter++
				row1[k],row2[k] = ".","1."
			}
		}
		for k:=0;k<n;k++{ // diagonals
			if k == 0 {
				if string(row1[k]) == "1" && string(row2[k+1]) == "1"{
					counter++
					row1[k],row2[k+1] = ".","1."
				}
				continue
			}
			if k == n-1 {
				if string(row1[k]) == "1" && string(row2[k-1]) == "1"{
					counter++
					row1[k],row2[k-1] = ".","1."
				}
				continue
			}
			if string(row1[k]) == "1" && string(row2[k-1]) == "1" {
				counter++
				row1[k],row2[k-1] = ".","1."
				continue
			} else if string(row1[k]) == "1" && string(row2[k+1]) == "1" {
				counter++
				row1[k],row2[k+1] = ".","1."
				continue
			}
		}
		fmt.Fprintln(out,counter)
	}
}

/*
	A template for Go on codeforces.com
	Author: Yakov, frvr.ru
*/

package main

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

func main() {
	// START WRITING YOUR SOLUTION HERE:
	// writeLine(typeOf(readInt()))
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		var arr []string
		arr = append(arr, readLine())
		arr = append(arr, readLine())
		//fmt.Printf("arr====>%v,n=====>%v\n", arr, n)
		cnt := 0
		map1 := make(map[int]int)
		for i := 0; i < n; i++ {
			if arr[1][i] == '1' {
				val := DFS(i, arr[0], map1)
				//fmt.Printf("val ====>%v\n", val)
				if val != 0 {
					if _, found := map1[val-1]; !found {
						map1[val-1]++
						cnt += 1
					}
				}
			}
		}
		//fmt.Printf("map1===>%v\n", map1)
		fmt.Printf("%v\n", cnt)
	}
}
func DFS(i int, s string, map1 map[int]int) int {
	//fmt.Printf("i====>%v, s====>%v, map1====>%v\n",i,s,map1)
	if s[i] == '0' {
		return i + 1
	}
	if i-1 >= 0 && s[i-1] == '1' {
		if _, found := map1[i-1]; !found {
			return i
		}
	}
	if i+1 < len(s) && s[i+1] == '1' {
		if _, found := map1[i+1]; !found {
			return i + 2
		}
	}
	return 0
}

/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

/* ~~~~~~~~~~ */

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

/* ~~~~~~~~~~ */

// Too much overhead with universal method using interface{}, wait for the generics,
// but for now — just don't look at the redundancy of the code after that commentary :)

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}
func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}
func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}
func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}
func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}
func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}
func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

/* ~~~~~~~~~~ */

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLine(arg ...interface{})             { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, a, b, tot := []int{}, "", "", 0
		fmt.Fscan(f, &a, &b)
		for j := 0; j < n; j++ {
			if string(a[j]) == "1" {
				o = append(o, 1)
			} else {
				o = append(o, 0)
			}
		}
		for j := 0; j < n; j++ {
			p, _ := strconv.Atoi(string(b[j]))
			if j == 0 {
				if o[j] == 0 && p == 1 {
					o[j] = 2
				} else if o[j+1] == 1 && p == 1 {
					o[j+1] = 2
				}
			} else if j == n-1 {
				if o[j-1] == 1 && p == 1 {
					o[j-1] = 2
				} else if o[j] == 0 && p == 1 {
					o[j] = 2
				}
			} else {
				if o[j-1] == 1 && p == 1 {
					o[j-1] = 2
				} else if o[j] == 0 && p == 1 {
					o[j] = 2
				} else if o[j+1] == 1 && p == 1 {
					o[j+1] = 2
				}
			}
		}
		for j := 0; j < n; j++ {
			if o[j] == 2 {
				tot++
			}
		}
		fmt.Fprintln(w, tot)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1549B
Date: 24/01/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1549/B
Problem: CF1549B
**/
func (in *CF1549B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		strx := in.NextString()
		str2 := in.NextString()
		marcados := make([]int , n)
		for i:=0;i<n;i++ {
			if strx[i] == '1' {
				marcados[i] = 1
			}
		}
		ans := 0
		for i := 0; i < n; i++ {
			if str2[i] == '1' {
				if marcados[i] == 0 {
					ans++
					marcados[i] = 2
				} else {
					if i > 0  && marcados[i-1] == 1 {
						ans++
						marcados[i-1] = 2
					} else {
						if i+1 < n && marcados[i+1] == 1 {
							ans++
							marcados[i+1] = 2
						}
					}
				}
			}
		}
		fmt.Println(ans)
	}
}

func change(str string, pos int, char string) string {
	if pos == 0 {
		return char + str[1:]
	}
	if pos == len(str)-1 {
		return str[0:pos]+ char
	}
	return str[0:pos] + char + str[pos+1:]
}

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

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

package main

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

var (
	in *bufio.Scanner = bufio.NewScanner(os.Stdin)
	out *bufio.Writer = bufio.NewWriter(os.Stdout)

	n int
	s [2][]string
	res int
)

func main() {
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	var t int = 1
	t = getInts()[0]
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {
	res = 0
}

func input() {
	n = getInts()[0]
	s[0] = strings.Split(getStrings()[0], "")
	s[1] = strings.Split(getStrings()[0], "")
}

func count() {
	for i := 0; i < n; i++ {
		if s[1][i] == "1" {
			if i > 0 && s[0][i-1] == "1" {
				res++
			} else if s[0][i] == "0" {
				res++
			} else if i < (n - 1) && s[0][i+1] == "1" {
				s[0][i+1] = "2"
				res++
			}
		}
	}
}

func output() {
	out.WriteString(fmt.Sprintf("%d\n", res))
}

func test() {

}

func getFloats() []float64 {
	in.Scan()
	str := strings.Split(in.Text(), " ")
	var res []float64 = make([]float64, len(str))
	for i := 0; i < len(str); i++ {
		res[i], _ = strconv.ParseFloat(str[i], 64)
	}
	return res
}

func getInt64s() []int64 {
	in.Scan()
	str := strings.Split(in.Text(), " ")
	var res []int64 = make([]int64, len(str))
	for i := 0; i < len(str); i++ {
		res[i], _ = strconv.ParseInt(str[i], 10, 64)
	}
	return res
}

func getInts() []int {
	in.Scan()
	str := strings.Split(in.Text(), " ")
	var res []int = make([]int, len(str))
	for i := 0; i < len(str); i++ {
		res[i], _ = strconv.Atoi(str[i])
	}
	return res
}

func getStrings() []string {
	in.Scan()
	return strings.Split(in.Text(), " ")
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] > n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] <= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] > n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] <= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"no", "yes", "NO", "YES"}
	var ind = 0
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

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

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

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

func main() {
	defer out.Flush()

	var (
		n, t int
		str  [2]string
	)
	fmt.Fscanf(in, "%d", &t)
	for t > 0 {
		t--

		fmt.Fscan(in, &n)
		s := make([][]int, 2)
		for i := 0; i < 2; i++ {
			s[i] = make([]int, n)
			fmt.Fscan(in, &str[i])
			for j := 0; j < n; j++ {
				s[i][j] = int(str[i][j] - '0')
			}
		}
		ans := 0
		for i := 0; i < n; i++ {
			if s[1][i] == 0 {
				continue
			}
			if s[0][i] == 0 {
				ans++
				continue
			}
			if i-1 >= 0 && s[0][i-1] == 1 {
				ans++
				s[0][i-1] = 2
				continue

			}
			if i+1 < n && s[0][i+1] == 1 {
				ans++
				s[0][i+1] = 2

			}
		}
		printf("%d\n", ans)

	}

}

package main

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

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 n, res int
		var up, down []byte

		fmt.Fscan(r, &n, &up, &down)

		for i := range up {
			if down[i] == '1' && up[i] == '0' {
				res++
				down[i] = '0'
			}
		}

		for i := range up {
			if down[i] == '1' {
				if i > 0 && up[i-1] == '1' {
					res++
				} else if i < n-1 && up[i+1] == '1' {
					res++
					up[i+1] = '0'
				}
			}
		}

		fmt.Fprintln(w, res)
	}

}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
	e, a   string
)

func solve(n int, e, a string) int {
	r := 0
	captured := make([]bool, n)
	for i := range e {
		if a[i] == '1' {
			if i-1 >= 0 && e[i-1] == '1' && !captured[i-1] {
				captured[i-1] = true
				r++
			} else if e[i] == '0' {
				r++
			} else if i < n-1 && e[i+1] == '1' && !captured[i+1] {
				captured[i+1] = true
				r++
			}
		}
	}
	return r
}

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

package main

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

var iost *Iost

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

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	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 isLocal() bool                               { return os.Getenv("I") == "IronMan" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			n := iost.GetNextInt()
			epawn := iost.Text()
			pawn := iost.Text()
			used := make([]int, n+2)
			ret := 0
			for i := 0; i < n; i++ {
				if pawn[i] == '1' {
					if i-1 >= 0 && used[i-1] == 0 && epawn[i-1] == '1' {
						ret += 1
						used[i-1] = 1
					} else if used[i] == 0 && epawn[i] == '0' {
						ret += 1
						used[i] = 1
					} else if i+1 < n && epawn[i+1] == '1' {
						ret += 1
						used[i+1] = 1
					}
				}
			}
			iost.Println(ret)
		}()
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

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

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

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

var t int

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

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

		var n int
		fmt.Fscan(input, &n)

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		STRINGSEC := make([]byte, 0)
		fmt.Fscan(input, &STRINGSEC)

		var ans int
		ARR := make([]int, 0)
		BRR := make([]int, 0)

		ARR = append(ARR, -1)
		BRR = append(BRR, -1)

		for i := 0; i < n; i++ {
			if string(STRING[i]) == "0" {
				ARR = append(ARR, 0)
			}

			if string(STRING[i]) == "1" {
				ARR = append(ARR, 1)
			}

			if string(STRINGSEC[i]) == "0" {
				BRR = append(BRR, 0)
			}

			if string(STRINGSEC[i]) == "1" {
				BRR = append(BRR, 1)
			}

		}
		ARR = append(ARR, -1)
		BRR = append(BRR, -1)

		for i := 1; i <= n; i++ {
			if BRR[i] == 1 {
				if ARR[i] == 0 {
					ans++
				} else {
					if ARR[i-1] == 1 {
						ans++
						ARR[i-1] = 0
					} else {
						if ARR[i+1] == 1 {
							ans++
							ARR[i+1] = 0
						}
					}
				}

			}
		}
		fmt.Println(ans)

	}

}

package main

import "fmt"

func main() {
	var (
		test int
		n    int
		top  string
		bot  string
	)
	fmt.Scanln(&test)
	for tt := 0; tt < test; tt++ {
		fmt.Scanln(&n)
		fmt.Scanln(&top)
		fmt.Scanln(&bot)
		s := []byte(top)
		t := []byte(bot)
		var mark = make([]bool, n)
		var ans int
		for i := 0; i < n; i++ {
			if t[i] == '1' {
				if i > 0 && s[i-1] == '1' {
					ans++
				} else if s[i] == '0' && !mark[i] {
					mark[i] = true
					ans++
				} else if i+1 < n && s[i+1] == '1' && !mark[i+1] {
					mark[i+1] = true
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func main() {
	var (
		test int
		n    int
		top  string
		bot  string
	)
	fmt.Scanln(&test)
	for tt := 0; tt < test; tt++ {
		fmt.Scanln(&n)
		fmt.Scanln(&top)
		fmt.Scanln(&bot)
		s := []byte(top)
		t := []byte(bot)
		var mark = make([]bool, n)
		var ans int
		for i := 0; i < n; i++ {
			if t[i] == '1' {
				if i > 0 && s[i-1] == '1' {
					ans++
				} else if s[i] == '0' && !mark[i] {
					mark[i] = true
					ans++
				} else if i+1 < n && s[i+1] == '1' && !mark[i] {
					mark[i+1] = true
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Scan(&n)
	var s1, s2 string
	fmt.Scan(&s1, &s2)
	//var a, b = make([]byte, n)
	a := []byte(s1)
	b := []byte(s2)
	var count int = 0
	for i := 0; i < n; i++ {
		if b[i] == '1' {
			if i > 0 && a[i-1] == '1' {
				count++
			} else if a[i] == '0' {
				count++
				a[i] = '2'
			} else if i < n-1 && a[i+1] == '1' {
				count++
				a[i] = '2'
			}
		}
	}
	fmt.Println(count)
}

package main

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

func main() {
	t := 0
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	fmt.Sscanf(s.Text(), "%d", &t)

	for i := 0; i < t; i++ {
		var a, b []byte
		var n int
		s.Scan()
		fmt.Sscanf(s.Text(), "%d", &n)
		s.Scan()
		a = s.Bytes()
		s.Scan()
		b = s.Bytes()

		res := 0
		for i := 0; i < n; i++ {
			if b[i] == '1' {
				if i > 0 && a[i-1] == '1' {
					res++
				} else if a[i] == '0' {
					a[i] = '2'
					res++
				} else if i < n-1 && a[i+1] == '1' {
					a[i+1] = '2'
					res++
				}
			}
		}
		fmt.Printf("%d\n", res)
	}
}

/*
	A template for Go on codeforces.com
	Author: Yakov, frvr.ru
*/

package main

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

func main() {
	// START WRITING YOUR SOLUTION HERE:
	// writeLine(typeOf(readInt()))
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		var arr []string
		arr = append(arr, readLine())
		arr = append(arr, readLine())
		//fmt.Printf("arr====>%v,n=====>%v\n", arr, n)
		cnt := 0
		for i := 0; i < n; i++ {
			if arr[1][i] == '1' {
				cnt += DFS(i, arr[0])
			}
		}
		fmt.Printf("%v\n", cnt)
	}
}
func DFS(i int, s string) int {
	if s[i] == '0' {
		return 1
	}
	if (i-1 >= 0 && s[i-1] == '1') || (i+1 < len(s) && s[i+1] == '1') {
		return 1
	}
	return 0
}

/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

/* ~~~~~~~~~~ */

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

/* ~~~~~~~~~~ */

// Too much overhead with universal method using interface{}, wait for the generics,
// but for now — just don't look at the redundancy of the code after that commentary :)

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}
func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}
func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}
func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}
func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}
func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}
func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

/* ~~~~~~~~~~ */

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLine(arg ...interface{})             { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

package main

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

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

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

func main() {
	defer out.Flush()

	var (
		n, t int
		str  [2]string
	)
	fmt.Fscanf(in, "%d", &t)
	for t > 0 {
		t--

		fmt.Fscan(in, &n)
		s := make([][]int, 2)
		for i := 0; i < 2; i++ {
			s[i] = make([]int, n)
			fmt.Fscan(in, &str[i])
			for j := 0; j < n; j++ {
				s[i][j] = int(str[i][j] - '0')
			}
		}
		ans := 0
		for i := 0; i < n; i++ {
			if s[1][i] == 0 {
				continue
			}
			if s[0][i] == 0 {
				ans++
				continue
			}
			if i+1 < n && s[0][i+1] == 1 {
				ans++
				s[0][i+1] = 0
			}
		}
		printf("%d\n", ans)

	}

}


A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.The fare is constructed in the following manner. There are three types of tickets:   a ticket for one trip costs 20 byteland rubles,  a ticket for 90 minutes costs 50 byteland rubles,  a ticket for one day (1440 minutes) costs 120 byteland rubles. Note that a ticket for x minutes activated at time t can be used for trips started in time range from t to t + x - 1, inclusive. Assume that all trips take exactly one minute.To simplify the choice for the passenger, the system automatically chooses the optimal tickets. After each trip starts, the system analyses all the previous trips and the current trip and chooses a set of tickets for these trips with a minimum total cost. Let the minimum total cost of tickets to cover all trips from the first to the current is a, and the total sum charged before is b. Then the system charges the passenger the sum a - b.You have to write a program that, for given trips made by a passenger, calculates the sum the passenger is charged after each trip.

The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger. Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1 ≤ i < n.

Output n integers. For each trip, print the sum the passenger is charged after it.

NoteIn the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had already paid 40 rubles, so it is necessary to charge 10 rubles only.

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	t, ans := make([]int64, n+1), make([]int64, n+1)
	for i := 0; i < n; i++ {
		I(&t[i], "\n")
	}
	for i := 0; i < n; i++ {
		ans[i+1] = ans[i] + 20
		q := sort.Search(n, func(ii int) bool { return t[i]-89 <= t[ii] })
		var o int64
		if q != n {
			o = int64(50) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		q = sort.Search(n, func(ii int) bool { return t[i]-1439 <= t[ii] })
		if q != n {
			o = int64(120) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		O(ans[i+1]-ans[i], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	t, ans := make([]int64, n+1), make([]int64, n+1)
	for i := 0; i < n; i++ {
		I(&t[i], "\n")
	}
	for i := 0; i < n; i++ {
		ans[i+1] = ans[i] + 20
		q := sort.Search(n, func(ii int) bool { return t[i]-90 < t[ii] })
		var o int64
		if q != n {
			o = int64(50) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		q = sort.Search(n, func(ii int) bool { return t[i]-1440 < t[ii] })
		if q != n {
			o = int64(120) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		O(ans[i+1]-ans[i], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	t, ans := make([]int64, n+1), make([]int64, n+1)
	for i := 0; i < n; i++ {
		I(&t[i], "\n")
		ans[i+1] = ans[i] + 20
		q := sort.Search(n, func(ii int) bool { return t[i]-90 < t[ii] })
		var o int64
		if q != n {
			o = int64(50) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		q = sort.Search(n, func(ii int) bool { return t[i]-1440 < t[ii] })
		if q != n {
			o = int64(120) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		O(ans[i+1]-ans[i], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	t, ans := make([]int64, n+1), make([]int64, n+1)
	for i := 0; i < n; i++ {
		I(&t[i], "\n")
		ans[i+1] = ans[i] + 20
		q := sort.Search(n, func(ii int) bool { return t[i]-89 <= t[ii] })
		var o int64
		if q != n {
			o = int64(50) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		q = sort.Search(n, func(ii int) bool { return t[i]-1439 <= t[ii] })
		if q != n {
			o = int64(120) + ans[q]
			if ans[i+1] > o {
				ans[i+1] = o
			}
		}
		O(ans[i+1]-ans[i], "\n")
	}
}


Given two integers $$$n$$$ and $$$x$$$, construct an array that satisfies the following conditions:   for any element $$$a_i$$$ in the array, $$$1 \le a_i<2^n$$$;  there is no non-empty subsegment with bitwise XOR equal to $$$0$$$ or $$$x$$$,  its length $$$l$$$ should be maximized. A sequence $$$b$$$ is a subsegment of a sequence $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The only line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 18$$$, $$$1 \le x<2^{18}$$$).

The first line should contain the length of the array $$$l$$$. If $$$l$$$ is positive, the second line should contain $$$l$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\dots$$$, $$$a_l$$$ ($$$1 \le a_i < 2^n$$$) — the elements of the array $$$a$$$. If there are multiple solutions, print any of them.

NoteIn the first example, the bitwise XOR of the subsegments are $$$\{6,7,4,1,2,3\}$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1174D(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, x int
	Fscan(in, &n, &x)
	if m := 1 << n; x < m {
		m >>= 1
		Fprintln(out, m-1)
		mask := x&-x - 1
		for i := 1; i < m; i++ {
			v := i & -i
			Fprint(out, v&^mask<<1|v&mask, " ")
		}
	} else {
		Fprintln(out, m-1)
		for i := 1; i < m; i++ {
			Fprint(out, i&-i, " ")
		}
	}
}
func main() { CF1174D(os.Stdin, os.Stdout) }


Phoenix has collected $$$n$$$ pieces of gold, and he wants to weigh them together so he can feel rich. The $$$i$$$-th piece of gold has weight $$$w_i$$$. All weights are distinct. He will put his $$$n$$$ pieces of gold on a weight scale, one piece at a time. The scale has an unusual defect: if the total weight on it is exactly $$$x$$$, it will explode. Can he put all $$$n$$$ gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order. Formally, rearrange the array $$$w$$$ so that for each $$$i$$$ $$$(1 \le i \le n)$$$, $$$\sum\limits_{j = 1}^{i}w_j \ne x$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 100$$$; $$$1 \le x \le 10^4$$$) — the number of gold pieces that Phoenix has and the weight to avoid, respectively.  The second line of each test case contains $$$n$$$ space-separated integers $$$(1 \le w_i \le 100)$$$ — the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.

For each test case, if Phoenix cannot place all $$$n$$$ pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array $$$w$$$. If there are multiple solutions, print any.

NoteIn the first test case, Phoenix puts the gold piece with weight $$$3$$$ on the scale first, then the piece with weight $$$2$$$, and finally the piece with weight $$$1$$$. The total weight on the scale is $$$3$$$, then $$$5$$$, then $$$6$$$. The scale does not explode because the total weight on the scale is never $$$2$$$.In the second test case, the total weight on the scale is $$$8$$$, $$$9$$$, $$$11$$$, $$$14$$$, then $$$18$$$. It is never $$$3$$$.In the third test case, Phoenix must put the gold piece with weight $$$5$$$ on the scale, and the scale will always explode.

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, x, d int
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			for j := 0; j < n; j++ {
				if x == arr[j] {
					arr[j], arr[j+1] = arr[j+1], arr[j]
				}
				fmt.Printf("%d ", arr[j])
				x -= arr[j]
			}
			fmt.Println("")
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,w,summer int
		fmt.Fscan(in,&n,&w)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			summer+=list[j]
		}
		if summer == w {
			fmt.Fprintln(out,"NO")
			continue
		}
		var sum int
		for j:=0;j<n;j++{
			if list[j]+sum == w {
				if j == n-1 {
					list[j],list[j-1] = list[j-1],list[j]
				} else {
					list[j],list[j+1] = list[j+1],list[j]
				}
				break
			}
			sum+=list[j]
		}
		fmt.Fprintln(out,"YES")
		for j:=0;j<n;j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func printArr(w []int) string {
	x := ""
	for _, v := range w {
		x += fmt.Sprintf("%d ", v)
	}
	return x
}

func solve(n, x int, w []int) string {
	sum := 0
	for _, v := range w {
		sum += v
	}
	if sum == x {
		return "NO"
	}
	sort.Ints(w)
	sum = 0
	for i := range w {
		sum += w[i]
		if sum == x {
			w[i], w[n-1] = w[n-1], w[i]
			break
		}
	}
	return "YES\n" + printArr(w)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &x)
		w := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &w[i])
		}
		fmt.Println(solve(n, x, w))
	}
}

package main

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)

	for kk := 0; kk < nt; kk++ {
		var n, x int
		fmt.Fscanf(reader, "%d%d\n", &n, &x)

		var a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")

		var sum = 0

		for i := 0; i < n; i++ {
			sum += a[i]
			if sum == x && i < n - 1 {
				a[i], a[i + 1] = a[i + 1], a[i]
			}
		}

		if sum != x {
			fmt.Fprintf(writer, "YES\n")
			for _, record := range a {
				fmt.Fprintf(writer, "%d ", record)
			}
			fmt.Fprintf(writer, "\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

const maxN = 1023

func swap(x, y *int) {
  *x, *y = *y, *x
}

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, x int
    fmt.Fscan(in, &n, &x)
    var w[maxN] int
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &w[i]);
    }
    //sort.Ints(w[:n])
    var sm int
    sm = 0
    for i := 0; i < n; i++ {
      sm += w[i]
      if sm == x && i < n - 1 {
        sm += w[i+1] - w[i]
        swap(&w[i], &w[i+1])
      }
    }
    if sm == x {
      fmt.Fprint(out, "NO\n")
    }else {
      fmt.Fprint(out, "YES\n")
      for i := 0; i < n; i++ {
        fmt.Fprint(out, w[i], " ")
      }
      fmt.Fprint(out, "\n")
    }
  }
}

package main

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

const maxN = 1023

func swap(x, y *int) {
  *x, *y = *y, *x
}

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, x int
    fmt.Fscan(in, &n, &x)
    var w[maxN] int
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &w[i]);
    }
    sort.Ints(w[:n])
    var sm int
    sm = 0
    for i := 0; i < n; i++ {
      sm += w[i]
      if sm == x && i < n - 1 {
        sm += w[i+1] - w[i]
        swap(&w[i], &w[i+1])
      }
    }
    if sm == x {
      fmt.Fprint(out, "NO\n")
    }else {
      fmt.Fprint(out, "YES\n")
      for i := 0; i < n; i++ {
        fmt.Fprint(out, w[i], " ")
      }
      fmt.Fprint(out, "\n")
    }
  }
}

package main

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

func main_gr_14_A() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n, x int
		Fscan(in, &n, &x)
		arr := make([]int, n)
		var total int
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
			total += arr[i]
		}
		if total == x {
			Fprintln(out, "NO")
			return
		}
		Fprintln(out, "YES")
		total = 0
		sort.Ints(arr)
		for i := 0; i < n; i++ {
			total += arr[i]
			if total == x {
				Fprint(out, arr[i+1], " ", arr[i], " ")
				i++
			} else {
				Fprint(out, arr[i], " ")
			}
		}
		Fprintln(out)
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_A()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, x := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &x)
		o, sum, s := make([]int, n), 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
			sum += o[j]
		}
		if sum == x {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
			for j := 0; j < n-1; j++ {
				if s+o[j] == x {
					o[j], o[j+1] = o[j+1], o[j]
				}
				s += o[j]
			}
			for j := 0; j < n; j++ {
				fmt.Fprint(w, o[j], " ")
			}
			fmt.Fprintln(w, "")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

		nums := make([]int, n)
		sum, pos := 0, -1
		for i := range nums {
			Fscan(in, &nums[i])
			sum += nums[i]
			if sum == x {
				pos = i
			}
		}
		if pos == n - 1 {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		if pos != -1 {
			nums[pos], nums[pos+1] = nums[pos+1], nums[pos]
		}
		for _, val := range nums {
			Fprint(out, val, " ")
		}
		Fprintln(out)
	}
}

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

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

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

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

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func sum(a []int) int {
    res := 0
    for _, v := range a {
        res += v
    }
    return res
}
func main() {
    q := 0
    fmt.Fscan(rd, &q);
    for t := 0; t < q; t++ {
        n, x := 0, 0
        fmt.Fscan(rd, &n, &x)
        w := make([]int, n)
        for i := range w {
            fmt.Fscan(rd, &w[i])
        }
        if sum(w) == x {
            fmt.Println("NO")
        } else {
            fmt.Println("YES")
            for i := range w {
                if w[i] == x {
                    w[i], w[i + 1] = w[i + 1], w[i]
                }
                fmt.Print(w[i], " ")
                x -= w[i]
            }
            fmt.Println()
        }
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N, X, w int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		Fscan(in, &X)
		ns := make([]int, N)
		tot := 0
		for n := 0; n < N; n++ {
			Fscan(in, &w)
			tot += w
			ns[n] = w
		}
		if tot < X {
			Fprintln(out, "YES")
			for i := 0; i < N; i++ {
				Fprint(out, ns[i], " ")
			}
			Fprintln(out)
			continue
		} else if tot == X {
			Fprintln(out, "NO")
			continue
		}

		sort.Slice(ns, func(i, j int) bool {
			return ns[i] > ns[j]
		})

		s := 0
		eqIdx := -1
		idx := 0
		for idx < N {
			s += ns[idx]
			if s == X {
				eqIdx = idx
				break
			}
			idx++
		}

		Fprintln(out, "YES")
		if eqIdx == -1 {
			for i := 0; i < N; i++ {
				Fprint(out, ns[i], " ")
			}
			Fprintln(out)
		} else {
			idx = 0
			for idx < N {
				if idx == eqIdx {
					Fprint(out, ns[idx+1], " ", ns[idx], " ")
					idx += 2
					continue
				}
				Fprint(out, ns[idx], " ")
				idx++
			}
			Fprintln(out)
		}
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n, x int
		_, _ = fmt.Fscan(in, &n, &x)

		w := make([]int, n)
		var sum int

		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &w[i])
			sum += w[i]
		}

		if sum == x {
			fmt.Println("NO")
			continue
		}

		sort.Ints(w)

		count := 0
		for i := 0; i < n; i++ {
			count += w[i]

			if count == x {
				w[i], w[i+1] = w[i+1], w[i]
				break
			}
		}

		fmt.Println("YES")
		for _, val := range w {
			fmt.Printf("%d ", val)
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, x, d int
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] >= x && arr[j+1] != x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
					break

				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				fmt.Printf("%d ", arr[j])
			}
			fmt.Println("")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, x, d int
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] == x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				fmt.Printf("%d ", arr[j])
			}
			fmt.Println("")
		}
	}
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, x, d int
		var arr []int
		var sums []int
		_, _ = fmt.Fscan(in, &n, &x)
		for j := 0; j < n; j++ {
			_, _ = fmt.Fscan(in, &d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] == x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				fmt.Printf("%d ", arr[j])
			}
			fmt.Println()
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, x, d int
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] == x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				fmt.Printf("%d ", arr[j])
			}
			fmt.Println()
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var n, x, d int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] == x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				fmt.Print(arr[j])
				fmt.Print(" ")
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var n, x, d int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] == x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				if j == len(arr)-1 {
					fmt.Println(arr[j])

				} else {
					fmt.Print(arr[j])
					fmt.Print(" ")
				}
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var n, x, d int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		var arr []int
		var sums []int
		fmt.Scan(&n)
		fmt.Scan(&x)
		for j := 0; j < n; j++ {
			fmt.Scan(&d)
			arr = append(arr, d)
			if j == 0 {
				sums = append(sums, d)
			} else {
				sums = append(sums, sums[j-1]+d)
			}

		}
		if sums[len(sums)-1] == x {
			fmt.Println("NO")
		} else {
			for j := 0; j < len(arr)-1; j++ {
				if sums[j] == x {
					arr[0], arr[j+1] = arr[j+1], arr[0]
				}

			}
			fmt.Println("YES")
			for j := 0; j < len(arr); j++ {
				if j == len(arr)-1 {
					fmt.Println(arr[j])

				} else {
					fmt.Print(arr[j])
					fmt.Print(" ")
				}
			}
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,w int
		fmt.Fscan(in,&n,&w)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		var sum int
		for j:=0;j<n;j++{
			if sum+list[j] == w {
				sum=0
				goto out
			}
			sum+= list[j]
		}
		fmt.Fprintln(out,"YES")
		for j:=0;j<n;j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out)
		continue

		out:
		for j:=n-1;j>=0;j--{
			if list[j]+sum == w {
				fmt.Fprintln(out,"NO")
				goto out2
			}
			sum+=list[j]
		}
		fmt.Fprintln(out,"YES")
		for j:=n-1;j>=0;j--{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out)
		out2:
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,w int
		fmt.Fscan(in,&n,&w)
		list:= make([]int,n)
		var test bool
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			if list[j] != w {
				test=true
			}
		}
		if test == false {
			fmt.Fprintln(out,"NO")
			continue
		}
		for j:=1;j<n;j++{
			if list[j] > list[j-1] {
				list[j-1],list[j] = list[j],list[j-1]
				j-=2
				if j < 0 {
					j=0
				}
			}
		}
		fmt.Fprintln(out,"YES")
		var sum int
		for j:=0;j<n;j++{
			if sum+list[j] == w {
				fmt.Fprintf(out,"%v ",list[n-1])
				sum+=list[n-1]
				n--
			}
			fmt.Fprintf(out,"%v ",list[j])
			sum+= list[j]
		}
		fmt.Fprintln(out)
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,w int
		fmt.Fscan(in,&n,&w)
		list:= make([]int,n)
		var test bool
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			if list[j] != w {
				test=true
			}
		}
		if test == false {
			fmt.Fprintln(out,"NO")
			continue
		}
		fmt.Fprintln(out,"YES")
		if list[0] == w {
			for j:=1;j<n;j++{
				fmt.Fprintf(out,"%v ",list[j])
			}
			fmt.Fprintf(out,"%v",list[0])
		} else {
			for j:=0;j<n;j++{
				fmt.Fprintf(out,"%v ",list[j])
			}
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func printArr(w []int) string {
	x := ""
	for _, v := range w {
		x += fmt.Sprintf("%d ", v)
	}
	return x
}

func solve(n, x int, w []int) string {
	sum := 0
	for _, v := range w {
		sum += v
	}
	if sum == x {
		return "NO"
	}
	sum = 0
	for i := range w {
		sum += w[i]
		if sum == x {
			w[i], w[n-1] = w[n-1], w[i]
			break
		}
	}
	return "YES\n" + printArr(w)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &x)
		w := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &w[i])
		}
		fmt.Println(solve(n, x, w))
	}
}

package main

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)

	for kk := 0; kk < nt; kk++ {
		var n, x int
		fmt.Fscanf(reader, "%d%d\n", &n, &x)

		var a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}

		var sum = 0

		for i := 0; i < n; i++ {
			sum += a[i]
			if sum == x && i < n - 1 {
				a[i], a[i + 1] = a[i + 1], a[i]
			}
		}

		if sum != x {
			fmt.Fprintf(writer, "YES\n")
			for _, record := range a {
				fmt.Fprintf(writer, "%d ", record)
			}
			fmt.Fprintf(writer, "\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}


Zart PMP is qualified for ICPC World Finals in Harbin, China. After team excursion to Sun Island Park for snow sculpture art exposition, PMP should get back to buses before they leave. But the park is really big and he does not know how to find them.The park has n intersections numbered 1 through n. There are m bidirectional roads that connect some pairs of these intersections. At k intersections, ICPC volunteers are helping the teams and showing them the way to their destinations. Locations of volunteers are fixed and distinct.When PMP asks a volunteer the way to bus station, he/she can tell him the whole path. But the park is fully covered with ice and snow and everywhere looks almost the same. So PMP can only memorize at most q intersections after each question (excluding the intersection they are currently standing). He always tells volunteers about his weak memory and if there is no direct path of length (in number of roads) at most q that leads to bus station, the volunteer will guide PMP to another volunteer (who is at most q intersections away, of course). ICPC volunteers know the area very well and always tell PMP the best way. So if there exists a way to bus stations, PMP will definitely find it.PMP's initial location is intersection s and the buses are at intersection t. There will always be a volunteer at intersection s. Your job is to find out the minimum q which guarantees that PMP can find the buses.

The first line contains three space-separated integers n, m, k (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105, 1 ≤ k ≤ n) — the number of intersections, roads and volunteers, respectively. Next line contains k distinct space-separated integers between 1 and n inclusive — the numbers of cities where volunteers are located. Next m lines describe the roads. The i-th of these lines contains two space-separated integers ui, vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — two intersections that i-th road connects. There will be at most one road between any two intersections. Last line of input contains two space-separated integers s, t (1 ≤ s, t ≤ n, s ≠ t) — the initial location of PMP and the location of the buses. It might not always be possible to reach t from s. It is guaranteed that there is always a volunteer at intersection s.

Print on the only line the answer to the problem — the minimum value of q which guarantees that PMP can find the buses. If PMP cannot reach the buses at all, output -1 instead.

NoteThe first sample is illustrated below. Blue intersections are where volunteers are located. If PMP goes in the path of dashed line, it can reach the buses with q = 3:  In the second sample, PMP uses intersection 6 as an intermediate intersection, thus the answer is 3.

package main

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

type edge struct {
	id, to int
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<16)
	var n, m, k int
	fmt.Fscan(in, &n, &m, &k)

	volunteers := make([]int, k)
	for i := range volunteers {
		fmt.Fscan(in, &volunteers[i])
	}

	edges := make([][]edge, n+1)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscan(in, &u, &v)
		edges[u] = append(edges[u], edge{i, v})
		edges[v] = append(edges[v], edge{i, u})
	}

	var s, t int
	fmt.Fscan(in, &s, &t)
	if s == t {
		fmt.Println(0)
		return
	}

	ans := sort.Search(n, func(q int) bool {
		source := make([]int, n+1)
		dist := make([]int, n+1)
		newEdges := make([][]int, n+1)
		queue := append(volunteers, t)
		for _, v := range queue {
			source[v] = v
		}
		for len(queue) > 0 {
			v := queue[0]
			queue = queue[1:]
			for _, e := range edges[v] {
				if source[e.to] == 0 {
					source[e.to] = source[v]
					dist[e.to] = dist[v]+1
					queue = append(queue, e.to)
					continue
				}
				if source[e.to] != source[v] && dist[v] + dist[e.to] < q {
					newEdges[source[v]] = append(newEdges[source[v]], source[e.to])
				}
			}
		}

		visited := make([]bool, n+1)
		var dfs func(v int) bool
		dfs = func(v int) bool {
			if v == t {
				return true
			}
			visited[v] = true
			for _, u := range newEdges[v] {
				if visited[u] {
					continue
				}
				if dfs(u) {
					return true
				}
			}
			return false
		}
		return dfs(s)
	})
	if ans == n {
		ans = -1
	}
	fmt.Println(ans)
}

package main

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

type edge struct {
	id, to int
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<16)
	var n, m, k int
	fmt.Fscan(in, &n, &m, &k)

	volunteers := make([]int, k)
	for i := range volunteers {
		fmt.Fscan(in, &volunteers[i])
	}

	edges := make([][]edge, n+1)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscan(in, &u, &v)
		edges[u] = append(edges[u], edge{i, v})
		edges[v] = append(edges[v], edge{i, u})
	}

	var s, t int
	fmt.Fscan(in, &s, &t)
	if s == t {
		fmt.Println(0)
		return
	}

	ans := sort.Search(n, func(q int) bool {
		source := make([]int, n+1)
		dist := make([]int, n+1)
		newEdges := make([][]int, n+1)
		queue := volunteers
		for _, v := range queue {
			source[v] = v
		}
		for len(queue) > 0 {
			v := queue[0]
			queue = queue[1:]
			for _, e := range edges[v] {
				if source[e.to] == 0 {
					source[e.to] = source[v]
					dist[e.to] = dist[v] + 1
					queue = append(queue, e.to)
					continue
				}
				if source[e.to] != source[v] && dist[v]+dist[e.to] < q {
					newEdges[source[v]] = append(newEdges[source[v]], source[e.to])
				}
			}
		}

		visited := make([]bool, n+1)
		var dfs func(v int) bool
		dfs = func(v int) bool {
			if v == t {
				return true
			}
			visited[v] = true
			for _, u := range newEdges[v] {
				if visited[u] {
					continue
				}
				if dfs(u) {
					return true
				}
			}
			return false
		}
		return dfs(s)
	})
	if ans == n {
		ans = -1
	}
	fmt.Println(ans)
}