Monocarp is playing a computer game. Now he wants to complete the first level of this game.A level is a rectangular grid of $$$2$$$ rows and $$$n$$$ columns. Monocarp controls a character, which starts in cell $$$(1, 1)$$$ — at the intersection of the $$$1$$$-st row and the $$$1$$$-st column.Monocarp's character can move from one cell to another in one step if the cells are adjacent by side and/or corner. Formally, it is possible to move from cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ in one step if $$$|x_1 - x_2| \le 1$$$ and $$$|y_1 - y_2| \le 1$$$. Obviously, it is prohibited to go outside the grid.There are traps in some cells. If Monocarp's character finds himself in such a cell, he dies, and the game ends.To complete a level, Monocarp's character should reach cell $$$(2, n)$$$ — at the intersection of row $$$2$$$ and column $$$n$$$.Help Monocarp determine if it is possible to complete the level.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of columns. The next two lines describe the level. The $$$i$$$-th of these lines describes the $$$i$$$-th line of the level — the line consists of the characters '0' and '1'. The character '0' corresponds to a safe cell, the character '1' corresponds to a trap cell. Additional constraint on the input: cells $$$(1, 1)$$$ and $$$(2, n)$$$ are safe.

For each test case, output YES if it is possible to complete the level, and NO otherwise.

NoteConsider the example from the statement.In the first test case, one of the possible paths is $$$(1, 1) \rightarrow (2, 2) \rightarrow (2, 3)$$$.In the second test case, one of the possible paths is $$$(1, 1) \rightarrow (1, 2) \rightarrow (2, 3) \rightarrow (2, 4)$$$.In the fourth test case, one of the possible paths is $$$(1, 1) \rightarrow (2, 2) \rightarrow (1, 3) \rightarrow (2, 4) \rightarrow (1, 5) \rightarrow (2, 6)$$$.

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		v := make([]byte, n)
		w := make([]byte, n)
		fmt.Scanf("%s\n%s\n", &v, &w)
		chk := true
		for i, c := range v {
			if c == '1' && w[i] == '1' {
				chk = false
				break
			}
		}
		if chk {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n int
		var v, w string
		fmt.Scanf("%d\n%s\n%s\n", &n, &v, &w)
		chk := true
		for i, c := range v {
			if c == '1' && w[i] == '1' {
				chk = false
				break
			}
		}
		if chk {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for w := 0; w < t; w++ {
		var n int
		var s1, s2 string
		fmt.Scanf("%d\n%s\n%s\n", &n, &s1, &s2)
		chk := true
		for i := 0; i < n; i++ {
			if s1[i] == '1' && s2[i] == '1' {
				chk = false
				break
			}
		}
		if chk {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func AtoI(s string) []int {
	o := make([]int, len(s))
	for i := 0; i < len(s); i++ {
		p, _ := strconv.Atoi(string(s[i]))
		o[i] = p
	}
	return o
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, s, bad, o := 0, "", false, [][]int{}
		fmt.Fscan(f, &n)
		for j := 0; j < 2; j++ {
			fmt.Fscan(f, &s)
			o = append(o, AtoI(s))
		}
		for j := 0; j < len(s); j++ {
			bad = bad || (o[0][j] == 1 && o[1][j] == 1)
		}
		if !bad {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	o          [][]int
	vis        [][]bool
	delx, dely = []int{1, 0, 1, -1}, []int{0, 1, 1, 1}
)

func AtoI(s string) []int {
	o := make([]int, len(s))
	for i := 0; i < len(s); i++ {
		p, _ := strconv.Atoi(string(s[i]))
		o[i] = p
	}
	return o
}

func dfs(i, j, n int) bool {
	if vis[i][j] {
		return false
	}
	vis[i][j] = true
	if i == 1 && j == n-1 {
		return true
	}
	for k := 0; k < 4; k++ {
		if 0 <= i+delx[k] && i+delx[k] < 2 && 0 <= j+dely[k] && j+dely[k] < n {
			if o[i+delx[k]][j+dely[k]] == 0 && dfs(i+delx[k], j+dely[k], n) {
				return true
			}
		}
	}
	return false
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, s := 0, ""
		o, vis = [][]int{}, [][]bool{}
		fmt.Fscan(f, &n)
		for j := 0; j < 2; j++ {
			fmt.Fscan(f, &s)
			o = append(o, AtoI(s))
			vis = append(vis, make([]bool, len(s)))
		}
		if dfs(0, 0, n) {
			fmt.Fprintln(w, "YES")

		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func (in *A) run() {

	t := in.nextInt()
	for T := 0; T < t; T++ {
		n := in.nextInt()
		arr := make([][]byte, 2, n)
		for y := 0; y < len(arr); y++ {
			arr[y] = []byte(in.nextString())
		}
		dfs := newDfs(arr, '0')
		possible(dfs, 0, 0)
		if dfs.found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

type Dfs struct {
	dX    []int
	dY    []int
	grid  [][]byte
	find  byte
	found bool
}

func newDfs(grid [][]byte, find byte) *Dfs {
	dX := []int{1, 1, 1, 0, 0, -1, -1, -1}
	dY := []int{1, 0, -1, 1, -1, 1, 0, -1}
	return &Dfs{dX: dX, dY: dY, grid: grid, find: find, found: false}
}

func possible(d *Dfs, x, y int) {
	for i := 0; i < len(d.dX); i++ {
		_y := y + d.dY[i]
		_x := x + d.dX[i]
		if 0 <= _y && _y < len(d.grid) && 0 <= _x && _x < len(d.grid[_y]) && d.grid[_y][_x] == d.find {
			if _y == len(d.grid)-1 && _x == len(d.grid[_y])-1 {
				d.found = true
				return
			}
			d.grid[_y][_x] = '1'
			possible(d, _x, _y)
		}
	}
}

func main() {
	file, err := os.Open("input.txt")
	var F *bufio.Reader
	if err == nil {
		F = bufio.NewReader(file)
		os.Stdin = file
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(file)
	NewA(F).run()
}

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

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

func (in *A) 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 *A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

package main

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

var ok bool

func (in *A) run() {
	X := []int{1, 1, 1, 0, 0, -1, -1, -1}
	Y := []int{1, 0, -1, 1, -1, 1, 0, -1}
	t := in.nextInt()
	for T := 0; T < t; T++ {
		n := in.nextInt()
		arr := make([][]byte, 2, n)
		for y := 0; y < len(arr); y++ {
			arr[y] = []byte(in.nextString())
		}
		ok = false
		possible(X, Y, arr, 0, 0)
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func possible(X, Y []int, arr [][]byte, x, y int) {
	for i := 0; i < len(X); i++ {
		_y := y + Y[i]
		_x := x + X[i]
		if 0 <= _y && _y < len(arr) && 0 <= _x && _x < len(arr[_y]) && arr[_y][_x] == '0' {
			if _y == len(arr)-1 && _x == len(arr[_y])-1 {
				ok = true
				return
			}
			arr[_y][_x] = '1'
			possible(X, Y, arr, _x, _y)
		}
	}
}

func main() {
	file, err := os.Open("input.txt")
	var F *bufio.Reader
	if err == nil {
		F = bufio.NewReader(file)
		os.Stdin = file
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(file)
	NewA(F).run()
}

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

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

func (in *A) 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 *A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

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

type queue struct {
	ary        [10000][2]int
	head, tail int
}

func (q *queue) pop() [2]int {
	a := q.ary[q.head]
	q.head++
	return a
}

func (q *queue) isEmpty() bool {
	return q.head == q.tail
}

func (q *queue) add(a, b int) {
	q.ary[q.tail] = [2]int{a, b}
	q.tail++
}

var x = []int{-1, -1, 0, 1, 1}
var y = []int{0, 1, 1, 1, 0}

func main() {
	defer writer.Flush()

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

	for ; k > 0; k-- {
		scanf("%d\n", &n)

		ary := [2][1000]int{}
		mark := [2][1000]bool{}

		for i := 0; i < n; i++ {
			scanf("%c", &ary[0][i])
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			scanf("%c", &ary[1][i])
		}
		scanf("\n")

		que := queue{}
		que.add(0, 0)
		mark[0][0] = true

		flag := false
		for !que.isEmpty() {
			head := que.pop()
			if head[0] == 1 && head[1] == n-1 {
				printf("YES\n")
				flag = true
				break
			}

			for i := 0; i < 5; i++ {
				newx := head[0] + x[i]
				newy := head[1] + y[i]
				if newx < 0 || newx > 1 || newy < 0 || newy >= n || mark[newx][newy] || ary[newx][newy] == 49 {
					continue
				}
				mark[newx][newy] = true
				que.add(newx, newy)
			}
		}
		if !flag {
			printf("NO\n")
		}

	}
}

package main

import (
  "fmt"
)

func solve() string {
	var n int
	fmt.Scan(&n)
	var A string
	var B string
	fmt.Scan(&A)
	fmt.Scan(&B)
	for i := 1; i < n; i++ {
		//fmt.Println(A[i], B[i])
		if A[i] == '1' && B[i] == '1' {
			return "NO"
		}
	}
	return "YES"
}

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

package main

import "fmt"

var (
	T int
)

func main() {
	_, _ = fmt.Scan(&T)
	for ; T > 0; T-- {
		var (
			n   int
			str [2]string
		)

		_, _ = fmt.Scan(&n, &str[0], &str[1])

		ans := "YES"
		for i := range str[0] {
			if str[0][i] == '1' && str[1][i] == '1' {
				ans = "NO"
			}
		}
		fmt.Println(ans)
	}
}

package main

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

// 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 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		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
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

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)

		S := make([]byte, 0)
		M := make([]byte, 0)

		fmt.Fscan(input, &S, &M)
		jj := 0
		for i := 0; i < n; i++ {
			if string(S[i]) == "1" && string(M[i]) == "1" {
				jj = 1
				break
			}
		}

		if jj == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

package main

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

// 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 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		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
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

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)

		S := make([]byte, 0)
		M := make([]byte, 0)

		fmt.Fscan(input, &S, &M)
		j := 0
		for i := 0; i < n; i++ {
			if string(S[i]) == "1" && string(M[i]) == "1" {
				j = 1
				break
			}
		}

		if j == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

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

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

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		grid := [2][]byte{}
		grid[0] = []byte(_string())
		grid[1] = []byte(_string())
		printf("%s\n", sol(n, grid))
	}
}

func sol(n int, grid [2][]byte) string {
	q := [][2]int{{0, 0}}
	for len(q) > 0 {
		e := q[0]
		q = q[1:]
		if grid[e[0]][e[1]] != '0' {
			continue
		}
		grid[e[0]][e[1]] = 'x'
		for _, delta := range [][2]int{
			{0, 1},
			{1, 0},
			{0, -1},
			{-1, 0},
			{1, 1},
			{-1, -1},
			{1, -1},
			{-1, 1},
		} {
			next := [2]int{
				delta[0] + e[0],
				delta[1] + e[1],
			}
			if next[0] >= 0 && next[0] < len(grid) &&
				next[1] >= 0 && next[1] < len(grid[next[0]]) &&
				grid[next[0]][next[1]] == '0' {
				q = append(q, next)
			}
		}
	}
	// printf("%v\n", string(grid[0]))
	// printf("%v\n", string(grid[1]))
	if grid[1][n-1] == 'x' {
		return "YES"
	}
	return "NO"
}

package main
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 int
		fmt.Fscan(in,&n)
		var row1,row2 string
		fmt.Fscan(in,&row1,&row2)
		for j:=1;j<len(row1);j++{
			if string(row1[j]) == "1" && string(row2[j]) == "1" {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

/*
	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 s1, s2 string
		s1 = readString()
		s2 = readString()
		var arr [][]byte
		arr = append(arr, []byte(s1))
		arr = append(arr, []byte(s2))
		//fmt.Printf("Arr======>%v\n", arr)
		dr := []int{0, -1, -1, -1, 0, 1, 1, 1}
		dc := []int{-1, -1, 0, 1, 1, 1, 0, -1}
		visited := make(map[[2]int]int)
		visited[[2]int{0, 0}] = 1
		if DFS(arr, dr, dc, 0, 0, 1, n-1, visited) {
			writeLine("YES")
		} else {
			writeLine("NO")
		}
	}
}
func DFS(arr [][]byte, dr []int, dc []int, x int, y int, tar_x int, tar_y int, visited map[[2]int]int) bool {
	//fmt.Printf("x====>%v,y====>%v,visited====>%v\n",x,y,visited)
	//fmt.Printf("tar_x===>%v,tar_y====>%v\n",tar_x,tar_y)
	if x == tar_x && y == tar_y {
		return true
	}
	for i := 0; i < len(dr); i++ {
		rr := x + dr[i]
		cc := y + dc[i]
		if rr < 0 || cc < 0 {
			continue
		}
		if rr > tar_x || cc > tar_y {
			continue
		}
		if arr[rr][cc] == '0' {
			r := [2]int{rr, cc}
			//fmt.Printf("r====>%v\n", r)
			if _, found := visited[r]; !found {
				visited[r] = 1
				if DFS(arr, dr, dc, rr, cc, tar_x, tar_y, visited) {
					return true
				}
			} else {
				continue
			}
		}
	}
	return false
}

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

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 (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

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

var (
	n int
)

func solve() {
	scan(&n)
	a := make([]string, 2)
	scan(&a[0], &a[1])
	yes := true
	for i := 0; i < n; i++ {
		if a[0][i] == '1' && a[1][i] == '1' {
			yes = false
		}
	}
	if yes {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

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

package main

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

func solve(r *bufio.Reader) {
	var n int
	var s1, s2 string
	fmt.Fscan(r, &n, &s1, &s2)
	for i := 0; i < n; i++ {
		if s1[i] == '1' && s2[i] == '1' {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

import (
	"container/list"
	"fmt"
	"strconv"
)

type Node struct {
	x int
	y int
}

var neighbors = []Node{
	{0, 1},
	{0, -1},
	{1, 0},
	{-1, 0},
	{1, 1},
	{-1, 1},
	{-1, -1},
	{1, -1},
}

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		graph := make([][]int, 2)
		visited := make([][]bool, 2)

		for i := 0; i < 2; i++ {
			var txt string
			fmt.Scan(&txt)

			graph[i] = make([]int, n)
			visited[i] = make([]bool, n)

			for j, c := range txt {
				v, _ := strconv.Atoi(string(c))
				graph[i][j] = v
				visited[i][j] = false
			}
		}

		// BFS

		if bfs(graph, visited) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

func bfs(graph [][]int, visited [][]bool) bool {
	var q = list.New()

	q.PushBack(Node{0, 0})
	visited[0][0] = true

	for q.Len() > 0 {
		e := q.Front()
		q.Remove(e)
		v := e.Value.(Node)

		for i := 0; i < len(neighbors); i++ {
			x := v.x + neighbors[i].x
			y := v.y + neighbors[i].y

			if isValid(x, y, graph) {
				if x == len(graph[0])-1 && y == 1 {
					return true
				}
				if !visited[y][x] {
					q.PushBack(Node{x, y})
					visited[y][x] = true
				}
			}
		}
	}

	return false
}

func isValid(x, y int, graph [][]int) bool {
	if x < 0 || y < 0 || x >= len(graph[0]) || y >= len(graph) {
		return false
	}
	return graph[y][x] == 0
}

package main

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

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

func (in *CF1598A) 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 *CF1598A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1598A
Date: 16/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1598/A
Problem: CF1598A
**/
func (in *CF1598A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		a := in.NextString()
		b := in.NextString()
		ans := true
		for i := 0; i < n; i++ {
			if a[i] == '1' && b[i] == '1' {
				ans = false
				break
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

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

		var s1, s2 string
		fmt.Fscan(in, &s1, &s2)

		f := true
		for i := range s1 {
			if s1[i] == '1' && s2[i] == '1' {
				f = false
				break
			}
		}

		if !f {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

/*
https://codeforces.com/problemset/problem/1598/A
*/
package main

import (
	"fmt"
	"strconv"
)

var (
	numberOfTests   string
	numberOfColumns string
	inputTests      [][]int8
	validTests      [][]int8
	answerBuffer    []string
)

type divineArray struct {
	size int
	pos1 string
	pos2 string
}

func (arr *divineArray) yieldValidMove() string {
	// returns true if move is valid
	res := "YES"

	for i, _ := range arr.pos1 {
		s := fmt.Sprintf("%c%c", arr.pos1[i], arr.pos2[i])
		// fmt.Println(s)
		if s == "11" {
			res = "NO"
			break
		}
	}
	return res
}

func main() {
	fmt.Scanln(&numberOfTests)
	t, _ := strconv.Atoi(numberOfTests)

	var arrs []divineArray

	// 4
	// 3
	// 000
	// 000
	for ; t > 0; t-- {
		// Get number of valid columns per test
		fmt.Scanln(&numberOfColumns)
		c, _ := strconv.Atoi(numberOfColumns)
		// numberofColumns = strconv.Atoi(numberOfColumns)
		// introduce the 2 following parameters, the actual values of the test
		var v1, v2 string
		fmt.Scanln(&v1)
		fmt.Scanln(&v2)
		if !(len(v1) != c) || !(len(v2) != c) {
			newArr := divineArray{size: c, pos1: v1, pos2: v2}
			arrs = append(arrs, newArr)
		}
	}

	for _, a := range arrs {
		fmt.Println(a.yieldValidMove())
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	n := ReadInt()
	grid := make([]string, 2)
	for i := 0; i < 2; i++ {
		grid[i] = ReadString()
	}

	type State struct{ x, y int }
	q := make([]State, 0)
	dist := make(map[State]int)

	s := State{0, 0}
	dist[s] = 0
	q = append(q, s)

	var dx = []int{1, 0, 0, 1, 1}
	var dy = []int{0, 1, -1, -1, 1}
	for len(q) > 0 {
		cur := q[0]
		q = q[1:]
		for dir := 0; dir < 5; dir++ {
			nx, ny := cur.x+dx[dir], cur.y+dy[dir]
			if 0 <= nx && nx < n && 0 <= ny && ny < 2 && grid[ny][nx] == '0' {
				next := State{nx, ny}
				if _, found := dist[next]; !found {
					dist[next] = dist[cur] + 1
					q = append(q, next)
				}
			}
		}
	}

	if _, found := dist[State{n - 1, 1}]; found {
		println("YES")
	} else {
		println("NO")
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (s []int64) {
	for i := 0; i < n; i++ {
		s = append(s, ReadInt64())
	}
	return
}
func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func prints(s []int)                    { v := fmt.Sprint(s); println(v[1 : len(v)-1]) }

package main

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

var n int

var level []string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		level = make([]string, 2)

		for j := 0; j < 2; j++ {
			fmt.Fscan(r, &level[j])
		}

		ans := solve()
		fmt.Println(ans)
	}
}

func solve() string {
	for i := 1; i < n - 1; i++ {
		if level[0][i] == '1' && level[1][i] == '1' {
			return "NO"
		}
	}

	return "YES"
}

package main

import "fmt"

func main() {
	var k, n int
	var str1, str2 string
	fmt.Scanf("%d\n", &k)
	for i := 0; i < k; i++ {
		fmt.Scanf("%d\n%s\n%s\n", &n, &str1, &str2)
		f := true
		for i, c := range str1 {
			if c == '1' && str2[i] == '1' {
				fmt.Println("NO")
				f = false
				break
			}
		}
		if f {
			fmt.Println("YES")
		}
	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int
	fmt.Fscanf(r, "%d\n", &T)

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

		arr := make([]string, 2)
		fmt.Fscanf(r, "%s\n", &arr[0])
		fmt.Fscanf(r, "%s\n", &arr[1])

		can := make([][]bool, 2)
		can[0] = make([]bool, n)
		can[1] = make([]bool, n)

		can[0][0] = true
		if arr[1][0] == '1' {
			can[1][0] = true
		}

		for i := 1; i < n; i++ {
			for j := 0; j < 2; j++ {
				if arr[j][i] == '0' && (can[0][i-1] || can[1][i-1]) {
					can[j][i] = true
				}
			}
		}

		//	fmt.Println(can)

		if can[1][n-1] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for w := 0; w < t; w++ {
		var n int
		var s1, s2 string
		fmt.Scanf("%d\n%s\n%s\n", &n, &s1, &s2)
		chk := true
		for i := 0; i < n; i++ {
			if s1[i] == '1' && s2[i] == '1' {
				chk = false
				break
			}
		}
		if chk {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

var (
	T int
)

func main() {
	_, _ = fmt.Scan(T)
	for ; T > 0; T-- {
		var (
			n   int
			str [2]string
		)

		_, _ = fmt.Scan(n, str[0], str[1])

		ans := "YES"
		for i := range str[0] {
			if str[0][i] == '1' && str[1][i] == '1' {
				ans = "NO"
			}
		}
		fmt.Println(ans)
	}
}


Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.

The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.

NoteIn the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.Optimal sequence of actions in the second sample case:   In the first day Anastasia collects 8 pebbles of the third type.  In the second day she collects 8 pebbles of the fourth type.  In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.  In the fourth day she collects 7 pebbles of the fifth type.  In the fifth day she collects 1 pebble of the second type.

package main

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

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	p := 0
	for i := 0; i < n; i++ {
		p += w[i] / k
		if w[i]%k != 0 {
			p += 1
		}
	}
	if p%2 == 0 {
		fmt.Println(p / 2)
	} else {
		fmt.Println(p/2 + 1)
	}
}

// Codeforces 58 B training, done
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n int
var k int
var w []int
var minDays int

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	n,k,_,_,_ = readFive()
	w = readLineNumbs(n)
}

func solve() {
	minDays = 0
	for i:=0; i<n; i++ {
		d := w[i]/k
		o := w[i]%k
		minDays += d
		if o>0 {
			minDays += 1
		}
	}
	// fmt.Println(minDays)
	minDays = (minDays+1)/2
}

func printRes() {
	fmt.Println(minDays)
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	w := sc.NextIntArray()
	count := 0
	for i := 0; i < N; i++ {
		count += (w[i] + (K - 1)) / K
	}
	fmt.Println((count + 1) / 2)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integers: the number of the starting vertex, the number of the final vertex and the edge's weight. So, as Vasya was trying to represent characteristics of a recently invented robot in his program, he faced the following problem.Vasya is not a programmer, so he asked his friend Gena, what the convenient way to store n integers is. Gena used to code in language X-- and so he can use only the types that occur in this language. Let's define, what a "type" is in language X--:  First, a type is a string "int".  Second, a type is a string that starts with "pair", then followed by angle brackets listing exactly two comma-separated other types of language X--. This record contains no spaces.  No other strings can be regarded as types. More formally: type := int | pair<type,type>. For example, Gena uses the following type for graph edges: pair<int,pair<int,int>>.Gena was pleased to help Vasya, he dictated to Vasya a type of language X--, that stores n integers. Unfortunately, Gena was in a hurry, so he omitted the punctuation. Now Gena has already left and Vasya can't find the correct punctuation, resulting in a type of language X--, however hard he tries.Help Vasya and add the punctuation marks so as to receive the valid type of language X--. Otherwise say that the task is impossible to perform.

The first line contains a single integer n (1 ≤ n ≤ 105), showing how many numbers the type dictated by Gena contains. The second line contains space-separated words, said by Gena. Each of them is either "pair" or "int" (without the quotes). It is guaranteed that the total number of words does not exceed 105 and that among all the words that Gena said, there are exactly n words "int".

If it is possible to add the punctuation marks so as to get a correct type of language X-- as a result, print a single line that represents the resulting type. Otherwise, print "Error occurred" (without the quotes). Inside the record of a type should not be any extra spaces and other characters.  It is guaranteed that if such type exists, then it is unique. Note that you should print the type dictated by Gena (if such type exists) and not any type that can contain n values.

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Node struct {
  IsLeaf bool
  Children []*Node
}

func parse(tokens []string, pos int) (root *Node, nextPos, leafCount int) {
  if pos == len(tokens) {
    return nil, pos, 0
  }
  if tokens[pos] == "int" {
    return &Node{ true, nil }, pos + 1, 1
  }
  pos += 1
  children := make([]*Node, 2)
  leafCount = 0
  for i := range children {
    child, nextPos, leafPlus := parse(tokens, pos)
    if child == nil {
      return nil, nextPos, -1
    }
    children[i] = child
    pos = nextPos
    leafCount += leafPlus
  }
  return &Node{ false, children }, pos, leafCount
}

func display(tree *Node, writer *bufio.Writer) {
  if tree.IsLeaf {
    writer.WriteString("int")
  } else {
    writer.WriteString("pair<")
    display(tree.Children[0], writer)
    writer.WriteString(",")
    display(tree.Children[1], writer)
    writer.WriteString(">")
  }
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  tokens := []string{}
  for scanner.Scan() {
    tokens = append(tokens, scanner.Text())
  }
  tree, tokenPos, leafCount := parse(tokens, 0)
  if tree == nil || tokenPos != len(tokens) || leafCount != n {
    writer.WriteString("Error occurred\n")
  } else {
    display(tree, writer)
    writer.WriteString("\n")
  }
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	buf = &strings.Builder{}
	s   string
)

type pair struct {
	isInt bool
	a, b  *pair
}

func (p *pair) read() bool {
	if n, _ := Fscan(in, &s); n == 0 {
		return false
	}
	if s[0] == 'i' {
		buf.WriteString("int")
		return true
	}
	buf.WriteString("pair<")
	p.a = &pair{}
	if !p.a.read() {
		return false
	}
	buf.WriteByte(',')
	p.b = &pair{}
	if !p.b.read() {
		return false
	}
	buf.WriteByte('>')
	return true
}

// github.com/EndlessCheng/codeforces-go
func main() {
	const e = "Error occurred"
	var n int
	Fscan(in, &n)
	p := &pair{}
	if !p.read() {
		Print(e)
		return
	}
	if n, _ := Fscan(in, &s); n > 0 {
		Print(e)
		return
	}
	Print(buf.String())
}

package main

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

type pair struct {
	isInt bool
	a, b  *pair
}

func (p *pair) read(in *bufio.Reader) bool {
	var s string
	if _, err := Fscan(in, &s); err != nil {
		return false
	}
	if s == "int" {
		p.isInt = true
		return true
	}
	p.a = &pair{}
	if !p.a.read(in) {
		return false
	}
	p.b = &pair{}
	if !p.b.read(in) {
		return false
	}
	return true
}

func (p *pair) print(out *bufio.Writer) {
	if p.isInt {
		Fprint(out, "int")
		return
	}
	Fprint(out, "pair<")
	p.a.print(out)
	Fprint(out, ",")
	p.b.print(out)
	Fprint(out, ">")
}

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

	var n int
	Fscan(in, &n)
	p := &pair{}
	if !p.read(in) {
		Fprintln(out, "Error occurred")
		return
	}
	var s string
	if _, err := Fscan(in, &s); err == nil {
		Fprintln(out, "Error occurred")
		return
	}
	p.print(out)
}

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

package main

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

type pair struct {
	isInt bool
	a, b  *pair
}

func (p *pair) read(in *bufio.Reader) bool {
	var s string
	if n, _ := Fscan(in, &s); n == 0 {
		return false
	}
	if s[0] == 'i' {
		p.isInt = true
		return true
	}
	p.a = &pair{}
	if !p.a.read(in) {
		return false
	}
	p.b = &pair{}
	if !p.b.read(in) {
		return false
	}
	return true
}

func (p *pair) print(out *bufio.Writer) {
	if p.isInt {
		Fprint(out, "int")
		return
	}
	Fprint(out, "pair<")
	p.a.print(out)
	Fprint(out, ",")
	p.b.print(out)
	Fprint(out, ">")
}

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

	const e = "Error occurred"
	var n int
	Fscan(in, &n)
	p := &pair{}
	if !p.read(in) {
		Fprint(out, e)
		return
	}
	var s string
	if n, _ := Fscan(in, &s); n > 0 {
		Fprint(out, e)
		return
	}
	p.print(out)
}

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

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	buf = &bytes.Buffer{}
	s   string
)

type pair struct {
	isInt bool
	a, b  *pair
}

func (p *pair) read() bool {
	if n, _ := Fscan(in, &s); n == 0 {
		return false
	}
	if s[0] == 'i' {
		buf.WriteString("int")
		return true
	}
	buf.WriteString("pair<")
	p.a = &pair{}
	if !p.a.read() {
		return false
	}
	buf.WriteByte(',')
	p.b = &pair{}
	if !p.b.read() {
		return false
	}
	buf.WriteByte('>')
	return true
}

// github.com/EndlessCheng/codeforces-go
func main() {
	const e = "Error occurred"
	var n int
	Fscan(in, &n)
	p := &pair{}
	if !p.read() {
		Print(e)
		return
	}
	if n, _ := Fscan(in, &s); n > 0 {
		Print(e)
		return
	}
	Print(buf.String())
}

package main

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

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

type pair struct {
	isInt bool
	a, b  *pair
}

func (p *pair) read() bool {
	if n, _ := Fscan(in, &s); n == 0 {
		return false
	}
	if s[0] == 'i' {
		p.isInt = true
		return true
	}
	p.a = &pair{}
	if !p.a.read() {
		return false
	}
	p.b = &pair{}
	if !p.b.read() {
		return false
	}
	return true
}

func (p *pair) print() {
	if p.isInt {
		Fprint(out, "int")
		return
	}
	Fprint(out, "pair<")
	p.a.print()
	Fprint(out, ",")
	p.b.print()
	Fprint(out, ">")
}

// github.com/EndlessCheng/codeforces-go
func main() {
	defer out.Flush()
	const e = "Error occurred"
	var n int
	Fscan(in, &n)
	p := &pair{}
	if !p.read() {
		Fprint(out, e)
		return
	}
	if n, _ := Fscan(in, &s); n > 0 {
		Fprint(out, e)
		return
	}
	p.print()
}

package main

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

type pair struct {
	isInt bool
	a, b  *pair
}

func (p *pair) read(in *bufio.Reader) bool {
	var s string
	if _, err := Fscan(in, &s); err != nil {
		return false
	}
	if s == "int" {
		p.isInt = true
		return true
	}
	p.a = &pair{}
	if !p.a.read(in) {
		return false
	}
	p.b = &pair{}
	if !p.b.read(in) {
		return false
	}
	return true
}

func (p *pair) print(out *bufio.Writer) {
	if p.isInt {
		Fprint(out, "int")
		return
	}
	Fprint(out, "pair<")
	p.a.print(out)
	Fprint(out, ",")
	p.b.print(out)
	Fprint(out, ">")
}

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

	var n int
	Fscan(in, &n)
	p := &pair{}
	if !p.read(in) {
		Fprintln(out, "Error occurred")
		return
	}
	p.print(out)
}

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


Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally?

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student.

Print exactly one integer — the maximum number of students that can get a favorite drink.

NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth).

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var n, k int
	fmt.Fscan(read, &n, &k)
	var a = make([]int, k)
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		a[ai-1]++
	}
	var np int
	var n21 int
	for _, val := range a {
		if val%2 == 0 {
			np = np + val
		} else {
			np = np + val - 1
			n21 = n21 + 1
		}

	}
	if n21%2 == 1 {
		np = np + 1 + n21/2
	} else {
		np = np + n21/2
	}
	fmt.Print(np)
}

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var n, k int
	fmt.Fscan(read, &n, &k)
	var a = make(map[int]int)
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		a[ai]++
	}
	var np int
	var n21 int
	for _, val := range a {
		if val%2 == 0 {
			np = np + val
		} else {
			np = np + val - 1
			n21 = n21 + 1
		}
	}
	if n21%2 == 1 {
		np = np + 1 + n21/2
	} else {
		np = np + n21/2
	}
	fmt.Print(np)
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

func solve() {

	n, _ := readInt(), readInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	sort.Ints(a)

	packs := 0
	remains := n/2 + n%2

	for i := 1; i < n; i++ {
		if a[i] == a[i-1] {
			packs++
			remains--
			i++
		}
	}

	printInt(packs*2 + remains)

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

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

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	var n, k, res int
	// var a, b, c string

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &k)

	m := make(map[int]int)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanln(scr, &a[i])
		m[a[i]]++
	}

	for _, y := range m {
		res += 2 * (y / 2)
	}

	res += int(math.Ceil(float64(n)/float64(2))) - (res / 2)

	fmt.Println(res)

}

package main

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

func main() {
	var n, k, d int
	var drinks [1010]int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &d)
		drinks[d-1] += 1
	}

	sort.Sort(sort.Reverse(sort.IntSlice(drinks[:k])))

	pair, alone := 0, 0
	for i := 0; i < k; i++ {
		pair += (drinks[i] / 2) * 2
		alone += drinks[i] % 2
	}
	fmt.Println(pair + alone/2 + alone%2)
}

package main

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

func main() {
	var n, k, d int
	var drinks [1010]int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &d)
		drinks[d-1] += 1
	}

	sort.Sort(sort.Reverse(sort.IntSlice(drinks[:k])))

	good, bad := 0, 0

	for i := 0; i < k; i++ {
		if drinks[i]%2 == 0 {
			good += drinks[i]
		} else {
			good += drinks[i] - 1
			bad += 1
		}
	}
	ans := good + bad/2
	if bad%2 != 0 {
		ans += 1
	}

	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var (
		stuNum int
		drkNum int
	)
	if _, err := fmt.Scanln(&stuNum, &drkNum); err != nil {

	}

	stuMap := make([]int, drkNum)
	for i := 0; i < stuNum; i += 1 {
		var fav int

		if _, err := fmt.Scanln(&fav); err != nil {
		}
		fav -= 1
		stuMap[fav] += 1
	}

	total := 0
	others := 0
	for i := 0; i < drkNum; i += 1 {
		if stuMap[i] % 2 == 0{
			total += stuMap[i]
		}else {
			total += stuMap[i] - 1
			others += 1
		}
	}
	total += others/2 + others%2
	fmt.Println(total)
}

// Copyright (C) 2017 Kazumasa Kohtaka <kkohtaka@gmail.com> All right reserved
// This file is available under the MIT license.

package main

import "fmt"

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

	var flag bool
	var ans int
	for _, i := range a {
		if i%2 == 0 {
			ans += i
		} else if !flag {
			ans += i
			flag = true
		} else {
			ans += i - 1
			flag = false
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, k := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &k)
	a := make([]int, n)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d\n", &a[i])
		cnt[a[i]]++
	}
	pair := 0
	single := 0
	for _, v := range cnt {
		if v%2 == 0 {
			pair += v
		} else {
			pair += v - 1
			single++
		}
	}
	ans := pair + (single+1)/2
	fmt.Fprintf(out, "%d\n", ans)
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n, k int
var a []int

func main() {
	fmt.Fscan(reader, &n, &k)
	a = make([]int, n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
		m[a[i]]++
	}
	ans := 0
	for i := (n + 1) / 2; i != 0; i-- {
		flag := false
		for k, v := range m {
			if v > 1 {
				m[k] -= 2
				ans += 2
				flag = true
				if m[k] == 0 {
					delete(m, k)
				}
				break
			}
		}
		if !flag {
			ans += Min(i, len(m))
			fmt.Println(ans)
			return
		}
	}
	fmt.Println(ans)
}

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

package main

import "fmt"

func drinkChoosing(sNum int, dNum int, sFav map[int]int) int {
	result := 0
	t := 0
	for _, v := range sFav {
		result += v - v % 2
		t += v % 2
	}
	result += t / 2 + t % 2
	return result
}

func main() {
	var sNum, dNum int

	_, err := fmt.Scanln(&sNum, &dNum)
	if err != nil {
		fmt.Println(err)
	}

	sFav := make(map[int]int)
	for k := 0; k < sNum; k++ {
		a := 0
		_, err := fmt.Scanln(&a)
		if err != nil {
			fmt.Println(err)
		}
		sFav[a] ++
	}
	result := drinkChoosing(sNum, dNum, sFav)
	fmt.Println(result)
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	arr := make([]int, k)
	res := 0
	for i := 0; i < n; i++ {
		var drink int
		fmt.Scan(&drink)
		arr[drink-1]++
	}
	single := 0
	for i := range arr {
		last_bit := arr[i] & 1
		res += arr[i] - last_bit
		single += last_bit
	}
	res += single/2 + (single & 1)
	fmt.Println(res)
}

package main

import (
    "fmt"
)

func main() {
    var n, k int
    fmt.Scan(&n, &k)
    cnt := make([]int, k)
    for i := 0; i < n; i++ {
        var x int
        fmt.Scan(&x)
        cnt[x - 1]++
    }
    c := (n + 1) / 2
    ans := 0
    for i := 0; i < k; i++ {
        x := cnt[i] / 2
        c -= x
        ans += 2 * x
    }
    for i := 0; i < k; i++ {
        if cnt[i] > 0 && c > 0 {
            ans++
            c--
        }
    }
    fmt.Println(ans)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1195/problem/A

package main

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

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func getSets(m map[int]int) (int, int) {
	completeSets := 0
	singleSets := 0
	for _, value := range m {
		completeSets += value / 2
		if value%2 == 1 {
			singleSets += 1
		}
	}
	return completeSets, singleSets
}

func Solve(n int, k int, a []int) int {
	count := make(map[int]int)
	for _, elem := range a {
		count[elem] += 1
	}
	sets := (n + 1) / 2
	completeSets, singleSets := getSets(count)
	students := min(sets, completeSets) * 2
	sets -= min(sets, completeSets)
	return students + min(sets, singleSets)
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, k, a))
}

package main

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

func main() {
	var n, k, res int
	// var a, b, c string

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n, &k)

	m := make(map[int]int)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanln(scr, &a[i])
		m[a[i]]++
	}

	for _, y := range m {
		res += 2 * (y / 2)
	}

	res += int(math.Ceil(float64(n/2))) - (res / 2)

	fmt.Println(res)

}

package main

import (
	"fmt"
	"sort"
)

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

	// for i := 0; i < k; i++ {
	// 	fmt.Printf("%d ", drinks[i])
	// }
	// fmt.Println()

	sort.Sort(sort.Reverse(sort.IntSlice(drinks[:n])))

	// for i := 0; i < k; i++ {
	// 	fmt.Printf("%d ", drinks[i])
	// }
	// fmt.Println()

	var rem_drinks int
	if n%2 == 0 {
		rem_drinks = n / 2
	} else {
		rem_drinks = n/2 + 1
	}

	ans := 0

	for i := 0; i < k && rem_drinks > 0; i++ {
		if drinks[i] <= rem_drinks*2 {
			ans += drinks[i]
			if drinks[i]%2 == 0 {
				rem_drinks = rem_drinks - drinks[i]/2
			} else {
				rem_drinks = rem_drinks - drinks[i]/2 - 1
			}
		} else {
			ans += rem_drinks * 2
			rem_drinks = 0
		}
	}
	fmt.Printf("%d\n", ans)
}

package main

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

func main() {
	var n, k, d int
	var drinks [1010]int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &d)
		drinks[d-1] += 1
	}

	sort.Sort(sort.Reverse(sort.IntSlice(drinks[:k])))

	var rem_drinks int
	if n%2 == 0 {
		rem_drinks = n / 2
	} else {
		rem_drinks = n/2 + 1
	}

	ans := 0

	for i := 0; i < k && rem_drinks > 0; i++ {
		if drinks[i] <= rem_drinks*2 {
			ans += drinks[i]
			if drinks[i]%2 == 0 {
				rem_drinks = rem_drinks - drinks[i]/2
			} else {
				rem_drinks = rem_drinks - drinks[i]/2 - 1
			}
		} else {
			ans += rem_drinks * 2
			rem_drinks = 0
		}
	}
	fmt.Println(ans)
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n, k int
var a []int

func main() {
	fmt.Fscan(reader, &n, &k)
	a = make([]int, n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
		m[a[i]]++
	}
	ans := 0
	n = (n + 1) / 2
	for i := (n + 1) / 2; i != 0; i-- {
		flag := false
		for k, v := range m {
			if v > 1 {
				m[k] -= 2
				ans += 2
				flag = true
				if m[k] == 0 {
					delete(m, k)
				}
			}
		}
		if !flag {
			ans += Min(i, len(m))
			fmt.Println(ans)
			return
		}
	}
	fmt.Println(ans)
}

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


A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).You are given a permutation of $$$1,2,\dots,n$$$, $$$[a_1,a_2,\dots,a_n]$$$. For integers $$$i$$$, $$$j$$$ such that $$$1\le i<j\le n$$$, define $$$\operatorname{mn}(i,j)$$$ as $$$\min\limits_{k=i}^j a_k$$$, and define $$$\operatorname{mx}(i,j)$$$ as $$$\max\limits_{k=i}^j a_k$$$.Let us build an undirected graph of $$$n$$$ vertices, numbered $$$1$$$ to $$$n$$$. For every pair of integers $$$1\le i<j\le n$$$, if $$$\operatorname{mn}(i,j)=a_i$$$ and $$$\operatorname{mx}(i,j)=a_j$$$ both holds, or $$$\operatorname{mn}(i,j)=a_j$$$ and $$$\operatorname{mx}(i,j)=a_i$$$ both holds, add an undirected edge of length $$$1$$$ between vertices $$$i$$$ and $$$j$$$.In this graph, find the length of the shortest path from vertex $$$1$$$ to vertex $$$n$$$. We can prove that $$$1$$$ and $$$n$$$ will always be connected via some path, so a shortest path always exists.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5\cdot 10^4$$$). Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 2.5\cdot 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1\le a_i\le n$$$). It's guaranteed that $$$a$$$ is a permutation of $$$1$$$, $$$2$$$, $$$\dots$$$, $$$n$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.

For each test case, print a single line containing one integer — the length of the shortest path from $$$1$$$ to $$$n$$$.

NoteThe following are illustrations of constructed graphs in example test cases.    the constructed graph in test case 1     the constructed graph in test case 2     the constructed graph in test case 3     the constructed graph in test case 4     the constructed graph in test case 5

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n Int
		Fscan(in, &n)
		a := make([]Int, n+1)
		segTree := newSegTree(n)
		for i := L1; i <= n; i++ {
			Fscan(in, &a[i])
			segTree.Modify(1, i, i, a[i])
		}

		incV := make([]Int, 0, n+1)
		desV := make([]Int, 0, n+1)

		lastG := make([]Int, n+1)
		lastL := make([]Int, n+1)

		for i := L1; i <= n; i++ {

			for len(desV) > 0 && a[i] > a[desV[len(desV)-1]] {
				desV = desV[:len(desV)-1]
			}

			if len(desV) > 0 {
				lastG[i] = desV[len(desV)-1]
			} else {
				lastG[i] = 0
			}

			desV = append(desV, i)

			for len(incV) > 0 && a[i] < a[incV[len(incV)-1]] {
				incV = incV[:len(incV)-1]
			}

			if len(incV) > 0 {
				lastL[i] = incV[len(incV)-1]
			} else {
				lastL[i] = 0
			}

			incV = append(incV, i)

		}

		dis := make([]Int, n+1)
		dis[1] = 0
		for i := Int(2); i <= n; i++ {
			dis[i] = dis[i-1] + 1
			_, minIdx := segTree.Query(1, lastG[i]+1, i)
			if minIdx < i {
				dis[i].MinAs(dis[minIdx] + 1)
			}

			_, maxIdx := segTree.QueryMax(1, lastL[i]+1, i)
			if maxIdx < i {
				dis[i].MinAs(dis[maxIdx] + 1)
			}

		}
		Fprintln(out, dis[n])
	}
}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, maxVal, maxIndex, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		segTree.st[x].maxIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}

	if segTree.st[x<<1].maxVal > segTree.st[x<<1|1].maxVal {
		segTree.st[x].maxVal = segTree.st[x<<1].maxVal
		segTree.st[x].maxIndex = segTree.st[x<<1].maxIndex
	} else {
		segTree.st[x].maxVal = segTree.st[x<<1|1].maxVal
		segTree.st[x].maxIndex = segTree.st[x<<1|1].maxIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	segTree.st[x].maxVal += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateMinRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateMinRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateMinRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateMinRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

func updateMaxRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes < res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) QueryMax(x, l, r Int) (Int, Int) {
	res := Int(math.MinInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateMaxRes(res, resInd, segTree.st[x].maxVal, segTree.st[x].maxIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.QueryMax(x<<1, l, r)
		res, resInd = updateMaxRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.QueryMax(x<<1|1, l, r)
		res, resInd = updateMaxRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscan(reader, &n)
	a := make([]int, n)
	l := make([]int, n)
	r := make([]int, n)
	for k := 0; k < n; k++ {
		fmt.Fscan(reader, &a[k])
		l[k] = k
		r[k] = n - 1 - k
	}

	mn, mx := 0, 0
	for k := 1; k < n; k++ {
		switch {
		case a[k] < a[mn]:
			mn = k
			l[k] = l[mx] + 1
		case a[k] > a[mx]:
			mx = k
			l[k] = l[mn] + 1
		}
	}

	mn, mx = n - 1, n - 1
	for k := n - 2; k >= 0; k-- {
		switch {
		case a[k] < a[mn]:
			mn = k
			r[k] = r[mx] + 1
		case a[k] > a[mx]:
			mx = k
			r[k] = r[mn] + 1
		}
	}

	ans := n - 1;
	for k := 0; k < n; k++ {
		if ans > l[k] + r[k] {
			ans = l[k] + r[k]
		}
	}

	fmt.Fprintln(writer, ans)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n Int
		Fscan(in, &n)
		a := make([]Int, n+1)
		segTree := newSegTree(n)
		for i := L1; i <= n; i++ {
			Fscan(in, &a[i])
			segTree.Modify(1, i, i, a[i])
		}

		incV := make([]Int, 0, n+1)
		desV := make([]Int, 0, n+1)

		lastG := make([]Int, n+1)
		lastL := make([]Int, n+1)

		for i := L1; i <= n; i++ {

			for len(desV) > 0 && a[i] > a[desV[len(desV)-1]] {
				desV = desV[:len(desV)-1]
			}

			if len(desV) > 0 {
				lastG[i] = desV[len(desV)-1]
			} else {
				lastG[i] = 0
			}

			desV = append(desV, i)

			for len(incV) > 0 && a[i] < a[incV[len(incV)-1]] {
				incV = incV[:len(incV)-1]
			}

			if len(incV) > 0 {
				lastL[i] = incV[len(incV)-1]
			} else {
				lastL[i] = 0
			}

			incV = append(incV, i)

		}

		dis := make([]Int, n+1)
		dis[1] = 0
		for i := Int(2); i <= n; i++ {
			dis[i] = dis[i-1] + 1
			_, minIdx := segTree.Query(1, lastG[i]+1, i)
			if minIdx < i {
				dis[i].MinAs(dis[minIdx] + 1)
			}

			_, maxIdx := segTree.QueryMax(1, lastL[i]+1, i)
			if maxIdx < i {
				dis[i].MinAs(dis[maxIdx] + 1)
			}

		}
		Fprintln(out, dis[n])
	}
}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, maxVal, maxIndex, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		segTree.st[x].maxIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}

	if segTree.st[x<<1].maxVal > segTree.st[x<<1|1].maxVal {
		segTree.st[x].maxVal = segTree.st[x<<1].maxVal
		segTree.st[x].maxIndex = segTree.st[x<<1].maxIndex
	} else {
		segTree.st[x].maxVal = segTree.st[x<<1|1].maxVal
		segTree.st[x].maxIndex = segTree.st[x<<1|1].maxIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateMinRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateMinRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateMinRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateMinRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

func updateMaxRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes < res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) QueryMax(x, l, r Int) (Int, Int) {
	res := Int(math.MinInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateMaxRes(res, resInd, segTree.st[x].maxVal, segTree.st[x].maxIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.QueryMax(x<<1, l, r)
		res, resInd = updateMaxRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.QueryMax(x<<1|1, l, r)
		res, resInd = updateMaxRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}