package main

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

func f(in io.Reader, out io.Writer) {
	var n int
	var s string
	Fscan(in, &n, &s)
	prev := 1
	count := 0
	prev_num := 2
	ans := 0

	for _, char := range s {
		tmp, _ := strconv.Atoi(string(char))
		if tmp == prev {
			count++
		} else {
			if prev_num == 2 {
				prev_num = count % 2
				if prev_num == 1 {
					ans++
				}
			} else {
				if prev_num == 1 {
					if count%2 == 0 {
						ans++
					} else {
						prev_num = 0
					}
				} else {
					if count%2 == 1 {
						ans++
						prev_num = 1
					}
				}

			}
			prev = 1 - prev
			count = 1
		}
	}
	Fprintln(out, ans)
}

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	Fscan(in, &t)

	for i := 0; i < t; i++ {
		f(in, out)
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Scan(&s)
		segmentedBuilder := strings.Builder{}
		var start int = 0
		for i, ch := range s {
			if ch != rune(s[start]) {
				length := i - start
				if length%2 == 0 {
					segmentedBuilder.Write([]byte{'e'})
				} else {
					segmentedBuilder.Write([]byte{'o'})
				}
				start = i
			}
		}
		if start < len(s) {
			length := len(s) - start
			if length%2 == 0 {
				segmentedBuilder.Write([]byte{'e'})
			} else {
				segmentedBuilder.Write([]byte{'o'})
			}
			start = i + 1
		}
		segmented := segmentedBuilder.String()
		prev := 'e'
		ans := 0
		for _, ch := range segmented {
			if prev == 'o' && ch == 'e' {
				ch = 'o'
				ans++
			} else if prev == 'o' && ch == 'o' {
				ch = 'e'
				ans++
			}
			prev = ch
		}
		if prev == 'o' {
			ans++
		}
		fmt.Println(ans)
	}
}

package main

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

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

func slove() {
	defer w.Flush()
	var n int
	var s string
	fmt.Fscan(r, &n, &s)
	last := 0
	ans := 0
	for i:=0;i<n;i++ {
		if s[i] != s[last] {
			if (i - last) % 2 == 1 {
				ans++
				last = i + 1
			} else {
				last = i
			}
		}
	}
	fmt.Fprintln(w, ans)
}

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

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		_ = io.ReadInt()
		s := io.ReadString()
		a := make([]int, 1)
		a[0] = 1

		for i := 1; i < len(s); i++ {
			if s[i] == s[i-1] {
				a[len(a)-1]++
			} else {
				a = append(a, 1)
			}
		}

		ans := 0

		for i := 1; i < len(a); i++ {
			if a[i-1]%2 != 0 {
				a[i-1]++
				a[i]--
				ans++
			}
		}

		fmt.Println(ans)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1678B
Date: 9/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1678/B1
Problem: CF1678B
**/
func (in *CF1678B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		arr := make([]int, 0)
		count := 0
		current := str[0]
		for i := 0; i < n; i++ {
			if str[i] == current {
				count++
			} else {
				arr = append(arr, count)
				count = 1
				current = str[i]
			}
		}
		arr = append(arr, count)

		ans := 0
		for i := 0; i < len(arr); i++ {
			if arr[i]%2 != 0 {
				arr[i]++
				ans++
				if i+1 < len(arr) {
					arr[i+1]--
					ans++
				}
			}
		}

		fmt.Println(ans / 2)

	}
}

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

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

package main

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

const MAXN = 2e5

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var ntests int
	fmt.Fscan(in, &ntests)
	for iiter := 0; iiter < ntests; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		sums := make([]int, 0)
		last := '2'
		curr := 0
		var s string
		fmt.Fscan(in, &s)
		for _, el := range s {
			if el == last {
				curr++
			} else {
				last = el
				sums = append(sums, curr)
				curr = 1
			}
		}
		sums = append(sums, curr)
		sums = sums[1:]
		//fmt.Println("_", sums)
		res := 0
		flag := false
		count := 0
		for i := 0; i < len(sums); i++ {
			count++
			if sums[i]%2 == 1 {
				if flag {
					res += count
					flag = false
				} else {
					count = 0
					flag = true
				}
			}
		}
		fmt.Fprintln(out, res)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); S := gs()
		ep := []int{}
		for i:=0;i<N-1;i++ { if S[i] != S[i+1] { ep = append(ep,i) } }; ep = append(ep,N-1)
		larr := []int{}; larr = append(larr,ep[0]+1); for i:=1;i<len(ep);i++ { larr = append(larr,ep[i]-ep[i-1]) }
		odds := []int{}; for i:=0;i<len(larr);i++ { if larr[i] % 2 == 1 { odds = append(odds,i) } }
		ans := 0;  for i:=0;i<len(odds);i+=2 {	ans += odds[i+1]-odds[i] }
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var n int
	var s string
	Fscan(in, &n, &s)

	//Fscanf(in, "%s", &s)

	//Fprintln(out, n, "         ", s)
	var prev uint8 = '2'
	notEqCnt := 0
	segmentCnt := 0

	for i := 0; i < n; i += 2 {
		if s[i] != s[i+1] {
			notEqCnt++
		} else if prev != s[i] {
			prev = s[i]
			segmentCnt++
		}
	}

	//Fprintf(out, "%d %d\n", notEqCnt, segmentCnt)
	Fprintln(out, notEqCnt)

}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	for Fscan(in, &T); T > 0; T-- {
		solve(in, out)
	}
}

package main

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

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

	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		ans := 0
		for i := 0; i < n; i += 2 {
			if s[i] != s[i+1] {
				ans++
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

func main() {
	myio := NewIO(os.Stdin, os.Stdout)
	defer myio.Flush()

	t := myio.ReadInt()
	sol := func() {
		n := myio.ReadInt()
		b := myio.ReadBytes()
		c := 0
		for i := 0; i < n; i += 2 {
			if b[i] != b[i+1] {
				c++
			}
		}
		myio.Println(c)
	}
	for ; t > 0; t-- {
		sol()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"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)
		var s string
		Fscan(in, &s)

		dp := MakeGrid(n+1, 2)

		dp[0][0] = L0
		dp[0][1] = L0
		ans := Int(n)
		for i := 1; i < n; i += 2 {
			dp[i][0] = Int(n)
			dp[i][1] = Int(n)

			to0 := L0
			if s[i-1] == '1' {
				to0++
			}
			if s[i] == '1' {
				to0++
			}

			to1 := L0
			if s[i-1] == '0' {
				to1++
			}
			if s[i] == '0' {
				to1++
			}

			if i > 2 {
				dp[i][0].MinAs(dp[i-2][0]+to0, dp[i-2][1]+to0)
				dp[i][1].MinAs(dp[i-2][1]+to1, dp[i-2][0]+to1)
			} else {
				dp[i][0] = to0
				dp[i][1] = to1
			}

			if i == n-1 {
				ans.MinAs(dp[i][0], dp[i][1])
			}
		}
		Fprintln(out, ans)

	}

}

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
}

package main

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

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

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

		var c0, c1 int
		if s[0] == '0' {
			c0++
		} else {
			c1++
		}

		var tot int
		for i := 1; i < n; i++ {
			if s[i] == '0' {
				if c0 > 0 {
					c0++
				} else if c1%2 == 0 {
					c1 = 0
					c0 = 1
				} else {
					c1++
					tot++
				}
			} else {
				if c1 > 0 {
					c1++
				} else if c0%2 == 0 {
					c0 = 0
					c1 = 1
				} else {
					c0++
					tot++
				}
			}
		}

		fmt.Fprintln(out, tot)
	}
}

package main

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

func f(in io.Reader, out io.Writer){
	var n int
	var s string
	Fscan(in,&n, &s)
	prev := 1
	count := 0
	prev_num := 2
	ans := 0

	for _, char := range s {
		tmp, _ := strconv.Atoi(string(char))
		if tmp == prev {
			count++
		} else {
			if prev_num == 2 {
				prev_num = count % 2
				if prev_num == 1{
					ans++
				}
			} else {
				if prev_num == 1{
					ans++
				}
				if count%2 == 0 {
					continue
				} else {
					prev_num = 1 - prev_num
				}
			}
			prev = 1 - prev
			count = 1
		}
	}
	Fprintln(out, ans)
}

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	Fscan(in, &t)

	for i := 0; i < t; i++ {
		f(in, out)
	}
}

package main

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

func f() int {
	var n int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)
	prev := 1
	count := 0
	prev_num := 2
	ans := 0

	for _, char := range s {
		tmp, _ := strconv.Atoi(string(char))
		if tmp == prev {
			count++
		} else {
			if prev_num == 2 {
				prev_num = count % 2
				if prev_num == 1{
					ans++
				}
			} else {
				if prev_num == 1{
					ans++
				}
				if count%2 == 0 {
					continue
				} else {
					prev_num = 1 - prev_num
				}
			}
			prev = 1 - prev
			count = 1
		}
	}
	return ans
}

func main() {
	var t int
	//in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Scanf("%d", &t)

	for i := 0; i < t; i++ {
		fmt.Fprintln(out,f())
	}
}

package main

import (
	"fmt"
	"strconv"
)

func f() int {
	var n int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)
	prev := 1
	count := 0
	prev_num := 2
	ans := 0

	for _, char := range s {
		tmp, _ := strconv.Atoi(string(char))
		if tmp == prev {
			count++
		} else {
			if prev_num == 2 {
				prev_num = count % 2
				if prev_num == 1{
					ans++
				}
			} else {
				if prev_num == 1{
					ans++
				}
				if count%2 == 0 {
					continue
				} else {
					prev_num = 1 - prev_num
				}
			}
			prev = 1 - prev
			count = 1
		}
	}
	return ans
}

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

	for i := 0; i < t; i++ {
		fmt.Println(f())
	}
}

package main

import (
	"fmt"
	"strconv"
)

func f()int{
		var n int
		var s string
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &s)
		prev := 1
		count := 0
		var l []int

		for _, char := range s{
			tmp, _ := strconv.Atoi(string(char))
			if tmp == prev {
				count++
			}else{
				l = append(l, count)
				prev = 1 - prev
				count = 1
			}
		}
		l = append(l, count)
		prev = -1
		ans := 0
		for _, value := range l{
			if prev == 0{
				if value%2 == 0{
					continue
				}else {
					prev = 1
					ans++
				}
			} else if prev == 1{
				if value%2 == 0{
					ans++
				}else {
					prev = 0
				}
			} else{
				if value%2 == 0{
					prev = 0
				}else {
					prev = 1
					ans++
				}
			}
		}
	return ans
	}

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

	for i := 0; i < t; i++ {
		fmt.Println(f())
	}
}

package main

import (
	"fmt"
	"strconv"
)

func f()int{
		var n int
		var s string
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &s)
		prev := 1
		count := 0
		var l []int

		for _, char := range s{
			tmp, _ := strconv.Atoi(string(char))
			if tmp == prev {
				count++
			}else{
				l = append(l, count)
				prev = 1 - prev
				count = 1
			}
		}
		l = append(l, count)
		prev = -1
		ans := 0
		for _, value := range l{
			if prev == 0{
				if value%2 == 0{
					continue
				}else {
					prev = 1
					ans++
				}
			} else if prev == 1{
				if value%2 == 0{
					ans++
				}else {
					prev = 0
				}
			} else{
				if value%2 == 0{
					prev = 0
				}else {
					prev = 1
					ans++
				}
			}
		}
	return ans
	}

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

	for i := 0; i < t; i++ {
		println(f())
	}
}

package main

import (
	"fmt"
	"strconv"
)

func f(){
		var n int
		var s string
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &s)
		prev := 1
		count := 0
		var l []int

		for _, char := range s{
			tmp, _ := strconv.Atoi(string(char))
			if tmp == prev {
				count++
			}else{
				l = append(l, count)
				prev = 1 - prev
				count = 1
			}
		}
		l = append(l, count)
		prev = -1
		ans := 0
		for _, value := range l{
			if prev == 0{
				if value%2 == 0{
					continue
				}else {
					prev = 1
					ans++
				}
			} else if prev == 1{
				if value%2 == 0{
					ans++
				}else {
					prev = 0
				}
			} else{
				if value%2 == 0{
					prev = 0
				}else {
					prev = 1
					ans++
				}
			}
		}
		fmt.Println(ans)
	}

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

	for i := 0; i < t; i++ {
		f()
	}
}

package main

import (
	"fmt"
	"strconv"
)

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

	for i := 0; i < t; i++ {
		var n int
		var s string
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &s)
		prev := 1
		count := 0
		var l []int

		for _, char := range s{
			tmp, _ := strconv.Atoi(string(char))
			if tmp == prev {
				count++
			}else{
				l = append(l, count)
				prev = 1 - prev
				count = 1
			}
		}
		l = append(l, count)
		prev = -1
		ans := 0
		for _, value := range l{
			if prev == 0{
				if value%2 == 0{
					continue
				}else {
					prev = 1
					ans++
				}
			} else if prev == 1{
				if value%2 == 0{
					ans++
				}else {
					prev = 0
				}
			} else{
				if value%2 == 0{
					prev = 0
				}else {
					prev = 1
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"strconv"
)

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

	for i := 0; i < t; i++ {
		var n int
		var s string
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &s)
		prev := 1
		count := 0
		var l []int

		for _, char := range s{
			tmp, _ := strconv.Atoi(string(char))
			if tmp == prev {
				count++
			}else{
				l = append(l, count)
				prev = 1 - prev
				count = 1
			}
		}
		l = append(l, count)
		//fmt.Println(l)
		prev = -1
		ans := 0
		for _, value := range l{
			if prev == 0{
				if value%2 == 0{
					continue
				}else {
					prev = 1
					ans++
				}
			} else if prev == 1{
				if value%2 == 0{
					ans++
				}else {
					prev = 0
				}
			} else{
				if value%2 == 0{
					prev = 0
				}else {
					prev = 1
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Scan(&s)
		segmentedBuilder := strings.Builder{}
		var start int = 0
		for i, ch := range s {
			if ch != rune(s[start]) {
				length := i - start
				if length%2 == 0 {
					segmentedBuilder.Write([]byte{'e'})
				} else {
					segmentedBuilder.Write([]byte{'o'})
				}
				start = i
			}
		}
		if start < len(s) {
			length := len(s) - start
			if length%2 == 0 {
				segmentedBuilder.Write([]byte{'e'})
			} else {
				segmentedBuilder.Write([]byte{'o'})
			}
			start = i + 1
		}
		segmented := segmentedBuilder.String()
		prev := 'e'
		ans := 0
		for _, ch := range segmented {
			if prev == 'o' && ch == 'e' {
				ch = 'o'
				ans++
			} else if prev == 'o' && ch == 'o' {
				ch = 'e'
				ans++
			}
			prev = ch
		}
		if prev == 'o' {
			ans++
		}
		fmt.Println(s, ":", segmented, ":", ans)
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		_ = io.ReadInt()
		s := io.ReadString()
		a := make([]int, 1)
		a[0] = 1

		for i := 1; i < len(s); i++ {
			if s[i] == s[i-1] {
				a[len(a)-1]++
			} else {
				a = append(a, 1)
			}
		}

		ans := 0

		for len(a) > 1 {
			a1 := a[len(a)-2]
			a2 := a[len(a)-1]
			if a1%2 == 0 && a2%2 == 0 {
				a = a[:len(a)-1]
				a[len(a)-1] = a1 + a2
				continue
			}

			if a1%2 == 1 && a2%2 == 1 {
				a = a[:len(a)-1]
				a[len(a)-1] = a1 - 1
				ans++
				continue
			}

			ans += min(a1, a2)

			if min(a1, a2) == a2 {
				a = a[:len(a)-1]
				a[len(a)-1] = a1 + a2
				continue
			} else {
				a = a[:len(a)-2]
				a[len(a)-1] += a1 + a2
			}
		}

		fmt.Println(ans)
	}
}


package main

import (
	"fmt"
)

var (
	n, m   int
	input  []string
	result int = 0
)

func in() {
	fmt.Scanf("%d %d\n", &n, &m)
	input = make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scanln(&input[i])
	}
}

func out() {
	fmt.Println(result)
}

func run() {
	var table [][]int
	table = make([][]int, n-1)
	for i := 0; i < n-1; i++ {
		table[i] = make([]int, m)
		for j, _ := range input[i] {
			table[i][j] = int(input[i][j]) - int(input[i+1][j])
		}
	}

	for !isGood(table) {
		for i := 0; i < n-1; i++ {
			for j := 0; j < m; j++ {
				if table[i][j] < 0 {
					break
				} else if table[i][j] > 0 {
					result++
					for k := 0; k < n-1; k++ {
						table[k][j] = 0
					}
				}
			}
		}
	}
}

func isGood(table [][]int) bool {
	for i := 0; i < n-1; i++ {
		for j := 0; j < m; j++ {
			if table[i][j] == 0 {
				continue
			} else if table[i][j] > 0 {
				return false
			} else { // table[i][j] < 0
				break
			}
		}
	}
	return true
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	t := make([][]rune, n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		t[i] = []rune(s)
	}
	removed := make([]bool, m)
	for j := 0; j < m; j++ {
		for i := 1; i < n; i++ {
			if removed[j] {
				break
			}
			for k := 0; k <= j; k++ {
				if removed[k] {
					continue
				}
				if t[i-1][k] < t[i][k] {
					break
				}
				if k == j && t[i-1][k] > t[i][k] {
					removed[j] = true
				}
			}
		}
	}
	z := 0
	for i := 0; i < m; i++ {
		if removed[i] {
			z++
		}
	}
	fmt.Println(z)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/496/C

package main

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

func Solve(n, m int, words []string) int {
	pairs := make([]bool, n-1)
	ans := 0
	for i := 0; i < m; i++ {
		remove := 0
		for j := 0; j < n-1; j++ {
			if words[j][i] > words[j+1][i] && !pairs[j] {
				remove = 1
			}
		}
		ans += remove
		if remove == 0 {
			for j := 0; j < n-1; j++ {
				if words[j][i] < words[j+1][i] {
					pairs[j] = true
				}
			}
		}
	}
	return ans
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, m, words))
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	count := 0
	s := make([]string, n)

	for i := 0; i < n; i++ {
		s[i] = next()
	}
	// println(s)
	for i := 0; i < n - 1; i++ {
		if s[i] > s[i+1] {
			count++
			for j := 0; j < m; j++ {
				if s[i][j] > s[i+1][j] {
					for k := 0; k < n; k++ {
						s[k] = s[k][:j] + s[k][j+1:]
					}

					m--
					break
				}
				// println("ij:", i, j, s[i], s[j], okRow[j], count)
			}

			i = -1
		}

	}
	// println(okRow)
	println(count)
}

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var n, m, res int
	fmt.Scan(&n, &m)
	table := make([][]byte, n)

	for i := 0; i < n; i++ {
		var row string
		fmt.Scan(&row)
		table[i] = []byte(row)
	}

	if n == 1 {
		fmt.Println(0)
		return
	}

	lcp := make([]int, n-1)

	for j := 0; j < len(table[0]); {
		illegal := false

		for i := 0; i < n-1; i++ {
			if lcp[i] < j {
				continue
			}

			if table[i][j] == table[i+1][j] {
				lcp[i]++
			} else if table[i][j] > table[i+1][j] {
				illegal = true
				break
			}
		}

		if !illegal {
			j++
		} else {
			res++

			for i := 0; i < n-1; i++ {
				if lcp[i] > j {
					lcp[i]--
				}
			}

			for i, l := 0, len(table[0]); i < n; i++ {
				if j < l-1 {
					table[i] = append(table[i][:j], table[i][j+1:]...)
				} else {
					table[i] = table[i][:j]
				}
			}
		}
	}

	fmt.Println(res)
}

package main

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

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

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

	n, m := nextInt(), nextInt()
	count := 0

	s := make([]string, n)

	for i := 0; i < n; i++ {
		s[i] = next()
	}
	// println(s)
	for i := 0; i < n - 1; i++ {
		for j := 0; j < m; j++ {
			if s[i][j] < s[i+1][j] {
				break
			} else if s[i][j] > s[i+1][j] {
				// println(i, j, s)
				removeCol(s, j)
				m--
				j--
				count++
			}
		}
	}

	if len(s) > 0 {
		for i := 0; i < len(s) - 1; i++ {
			if s[i][0] == s[i+1][0] {
				continue
			} else if s[i][0] > s[i+1][0] {
				count++
				break
			}
		}
	}

	println(count)
}

func removeCol(s []string, index int) {
	for i := 0; i < len(s); i++ {
		s[i] = s[i][:index] + s[i][index+1:]
	}
}

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

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

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	count := 0
	s := make([]string, n)
	delCol := make([]bool, m)

	for i := 0; i < n; i++ {
		s[i] = next()
	}
	// println(s)
	for i := 0; i < n - 1; i++ {
		for j := 0; j < m; j++ {
			if delCol[j] {
				continue
			}

			if s[i][j] < s[i+1][j] {
				break
			} else if s[i][j] > s[i+1][j] {
				// println(i, s[i], s[i+1], j)
				delCol[j] = true
				i = 0
				count++
			}
		}
	}
	// println(delCol)
	println(count)
}

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

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

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

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

package main

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

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

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

	n, m := nextInt(), nextInt()
	count := 0
	s := make([]string, n)
	okRow := make([]bool, n)

	for i := 0; i < n; i++ {
		s[i] = next()
	}
	// println(s)
	for i := 0; i < m; i++ {
		indexOkRows := make([]int, 0)
		isDelCol := false
		for j := 0; j < n - 1; j++ {
			// println("ij:", i, j, s[i], s[j], okRow[j], count)
			if s[j][i] == s[j+1][i] {
				continue
			}

			if okRow[j] {
				break
			}

			if s[j][i] > s[j+1][i] {
				count++
				isDelCol = true
				break
			} else {
				indexOkRows = append(indexOkRows, j)
			}
		}

		if !isDelCol {
			for _, v := range indexOkRows {
				okRow[v] = okRow[v] || true
			}
		}
	}
	// println(okRow)
	println(count)
}

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var n, m, res int
	fmt.Scan(&n, &m)
	table := make([][]byte, n)

	for i := 0; i < n; i++ {
		var row string
		fmt.Scan(&row)
		table[i] = []byte(row)
	}

	if n == 1 {
		fmt.Println(0)
		return
	}

	lcp := make([]int, n-1)

	for j := 0; j < len(table[0]); {
		illegal := false

		for i := 0; i < n-1; i++ {
			if lcp[i] < j {
				continue
			}

			if table[i][j] == table[i+1][j] {
				lcp[i]++
			} else if table[i][j] > table[i+1][j] {
				illegal = true
				break
			}
		}

		if !illegal {
			j++
		} else {
			res++

			for i, l := 0, len(table[0]); i < n; i++ {
				if j < l-1 {
					table[i] = append(table[i][:j], table[i][j+1:]...)
				} else {
					table[i] = table[i][:j]
				}
			}
		}
	}

	fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var table [110][110]int
	for i := 1; i <= n; i++ {
		var s string
		fmt.Scan(&s)
		for j, r := range s {
			table[j+1][i] = int(r - '0')
		}
	}
	var z, prevCol int
	for i := 1; i <= m; i++ {
		px := -1
		j := 1
		for ; j <= n; j++ {
			if px == table[prevCol][j] {
				if table[i][j-1] > table[i][j] {
					z++
					break
				}
			} else {
				px = table[prevCol][j]
			}
		}
		if j > n {
			prevCol = i
		}
	}
	fmt.Println(z)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var table [110][110]int
	for i := 1; i <= n; i++ {
		var s string
		fmt.Scan(&s)
		for j, r := range s {
			table[j+1][i] = int(r - '0')
		}
	}
	var z, prevCol int
	for i := 1; i <= m; i++ {
		px := table[prevCol][1]
		j := 1
		for j <= n {
			if px == table[prevCol][j] {
				if table[i][j-1] > table[i][j] {
					z++
					break
				}
				j++
			} else {
				px = table[prevCol][j]
				j++
			}
		}
		if j > n {
			prevCol = i
		}
	}
	fmt.Println(z)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var table [110][110]rune
	for i := 1; i <= n; i++ {
		var s string
		fmt.Scan(&s)
		for j, r := range s {
			table[j+1][i] = r
		}
	}
	var z, prevCol int
	var fixed, tmpFixed [110]bool
	fixed[1] = true
	for i := 1; i <= m; i++ {
		j := 1
		px := table[prevCol][1]
		for ; j <= n; j++ {
			if fixed[j] {
				px = table[prevCol][j]
				continue
			}
			if px == table[prevCol][j] {
				if table[i][j-1] > table[i][j] {
					z++
					break
				}
				if table[i][j-1] < table[i][j] {
					tmpFixed[j] = true
				}
			} else {
				px = table[prevCol][j]
			}
		}
		if j > n {
			prevCol = i
			for k := 0; k < n; k++ {
				if tmpFixed[k] {
					fixed[k] = true
				}
			}
		}
	}
	fmt.Println(z)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var table [110][110]rune
	for i := 1; i <= n; i++ {
		var s string
		fmt.Scan(&s)
		for j, r := range s {
			table[j+1][i] = r
		}
	}
	var z, prevCol int
	var fixed, tmpFixed [110]bool
	fixed[1] = true
	for i := 1; i <= m; i++ {
		j := 1
		var px rune
		for ; j <= n; j++ {
			if fixed[j] {
				px = table[prevCol][j]
				continue
			}
			if px == table[prevCol][j] {
				if table[i][j-1] > table[i][j] {
					z++
					break
				}
				if table[i][j-1] < table[i][j] {
					tmpFixed[j] = true
				}
			} else {
				px = table[prevCol][j]
			}
		}
		if j > n {
			prevCol = i
			for k := 1; k <= n; k++ {
				if tmpFixed[k] {
					fixed[k] = true
				}
			}
		}
	}
	fmt.Println(z)
}


package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		var m int64
		fmt.Fscan(in, &n, &m)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		sort.Slice(nums, func(i, j int) bool {
			return nums[i] < nums[j]
		})
		used := 1 + nums[n-1]
		for i := n - 2; i >= 0; i-- {
			if i == 0 {
				used += nums[n-1] + 1
			} else {
				used += nums[i] + 1
			}
		}
		if used <= m {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

//4444444444
//4444444444
//4444444444
//4444444444
//4444444444

package main

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

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

	var limit int64
	Fscan(reader, &limit)

	for limit != 0 {
		var people, chair int64

		Fscan(reader, &people, &chair)

		store := make([]int64, people)

		nofchair := chair-people

		for i := range store {
			Fscan(reader, &store[i])
		}

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

		left, right := store[0], store[0]
		nofchair -= left+right
		for i := int64(1); i < people; i++ {
			if i == people-1 {
				break
			}
			if i % 2 == 0 {
				if left >= store[i] {
					left = store[i]
					nofchair -= left
				}
			} else {
				if right >= store[i] {
					right = store[i]
					nofchair -= right
				}
			}
		}

		if nofchair >= 0 {
			Fprintln(writer, "YES")
		} else {
			Fprintln(writer, "NO")
		}

		limit--
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i := 0;i < t;i++ {
		var n int
		var m int
		fmt.Fscan(in, &n, &m)
		want := make([]int64,n)
		for j := 0;j < n;j++ {
			fmt.Fscan(in, &want[j])
		}
		sort.Slice(want, func(i, j int) bool {
			return want[i] < want[j]
		})
		k := int64(0)
		for j := 1;j < n;j++ {
			if want[j-1] < want[j] {
				k += want[j]+1
			}else {
				k += want[j-1]+1
			}

		}
		if k + want[n-1] <= int64(m)-1 {
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

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

		row := []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			row = append(row, x)
		}
		sort.Ints(row)

		u := int64(1 + 2*row[n-1])
		for i := n - 2; i >= 0; i-- {
			v := row[i]
			u += int64(1 + v)
		}
		u -= int64(row[0])

		if u > m {
			Fprintln(out, "NO")

		} else {
			Fprintln(out, "YES")
		}
	}
}

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(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, m int
		Fscan(in, &n, &m)

		a := make([]int, n)
		sum := L0
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		sort.Ints(a)

		sum += int64(a[n-1]<<1) + 1
		for i := n - 2; i > 0; i-- {
			sum += 1 + int64(a[i])
		}
		sum += 1

		if sum <= int64(m) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

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

package main

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

/*
2
3 5
1 1 2
2 5
1 1
---
NO
YES
=======
5
3 8
1 2 3
3 8
1 1 1
3 8
1 1 2
3 8
1 2 2
3 9
1 2 2
---
NO
YES
YES
NO
YES
=======
2
4 13
1 2 2 3
4 14
1 2 2 3
*/

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

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	reqSpace := 2 + 2*int64(a[0])

	for i := 1; i < n-1; i++ {
		reqSpace += 1 + int64(a[i])
	}

	if int64(m) >= reqSpace {
		fmt.Fprintln(writer, "YES")
	} else {
		fmt.Fprintln(writer, "NO")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

	for ftr := 2; ftr <= sqrtA; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > sqrtA {
		factors = append(factors, num)
	}

	return factors
}

package main

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

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

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

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

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

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

		var pos int64
		for i := 1; i < n; i++ {
			pos += max(arr[i-1], arr[i]) + 1
		}

		if pos+arr[n-1] <= int64(m)-1 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i := 0;i < t;i++ {
		var n int
		var m int
		fmt.Fscan(in, &n, &m)
		want := make([]int64,n)
		for j := 0;j < n;j++ {
			fmt.Fscan(in, &want[j])
		}
		if n > m {
			fmt.Println("NO")
			continue
		}
		k := int64(0)
		for j := 0;j < n-1;j++ {
			if want[j] < want[j+1] {
				k += want[j+1]+1
			}else {
				k += want[j]+1
			}

		}
		if k + want[n-1] >= int64(m) || k >= int64(m)-want[0] {
			fmt.Println("NO")
		}else {
			fmt.Println("YES")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i := 0;i < t;i++ {
		var n int
		var m int
		fmt.Fscan(in, &n, &m)
		want := make([]int,n)
		for j := 0;j < n;j++ {
			fmt.Fscan(in, &want[j])
		}
		if n > m {
			fmt.Println("NO")
			continue
		}
		k := 0
		for j := 0;j < n-1;j++ {
			if want[j] < want[j+1] {
				k += want[j+1]+1
			}else {
				k += want[j]+1
			}
			if k >= m-want[0] {
				break
			}
		}
		if k + want[n-1] >= m || k >= m-want[0]{
			fmt.Println("NO")
		}else {
			fmt.Println("YES")
		}
	}
}

package main

import "fmt"

func main() {
	t,n,m := 0,0,0
	fmt.Scan(&t)
	for i := 0;i < t;i++ {
		fmt.Scan(&n,&m)
		want := make([]int,n)
		for j := 0;j < n;j++ {
			fmt.Scan(&want[j])
		}
		if n > m {
			println("NO")
			continue
		}
		k := 0
		for j := 0;j < n-1;j++ {
			if want[j] < want[j+1] {
				k += want[j+1]+1
			}else {
				k += want[j]+1
			}
			if k >= m-want[0] {
				break
			}
		}
		if k + want[n-1] >= m || k >= m-want[0]{
			println("NO")
		}else {
			println("YES")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		sort.Ints(nums)
		used := 1 + nums[n-1]
		for i := n - 2; i >= 0; i-- {
			if i == 0 {
				used += nums[n-1] + 1
			} else {
				used += nums[i] + 1
			}
		}
		if used <= m {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

//4444444444
//4444444444
//4444444444
//4444444444
//4444444444

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		sort.Ints(nums)
		used := 1 + nums[n-1]*2
		for i := n - 2; i >= 0; i-- {
			if i == 0 {
				used++
			} else {
				used += nums[i] + 1
			}
		}
		if used <= m {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

//4444444444
//4444444444
//4444444444
//4444444444
//4444444444

package main

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

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

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

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

		row := []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			row = append(row, x)
		}
		sort.Ints(row)

		u := 1 + 2*row[n-1]
		for i := n - 2; i >= 0; i-- {
			v := row[i]
			u += 1 + v
		}
		u -= row[0]

		if u > m {
			Fprintln(out, "NO")

		} else {
			Fprintln(out, "YES")
		}
	}
}


package main

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

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

// source: _
func solve() {
	n, arr := _readArr()

	a := make([]int, 0, len(arr))
	a = append(a, arr[0])
	for i := 1; i < n; i++ {
		if arr[i] != arr[i-1] {
			a = append(a, arr[i])
		}
	}

	cnt := 0
	na := len(a)
	if na == 1 {
		_print("YES")
		return
	}

	if a[1] > a[0] {
		cnt++
	}
	if a[na-1] < a[na-2] {
		cnt++
	}
	for i := 1; i < na-1; i++ {
		if a[i] < a[i-1] && a[i] < a[i+1] {
			cnt++
		}
	}

	if cnt == 1 {
		_print("YES")
	} else {
		_print("NO")
	}

}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1760D
Date: 11/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1760/D
Problem: CF1760D
**/
func (in *CF1760D) Run() {
	for t := in.NextInt(); t > 0; t-- {
		nL := in.NextInt()
		arr := make([]int, 0)
		last := -1

		for i := 0; i < nL; i++ {
			val := in.NextInt()
			if last != val {
				arr = append(arr, val)
			}
			last = val
		}
		n := len(arr)

		valley := 0
		for i := 0; i < n; i++ {
			if i == 0 && i+1 < n {
				if arr[i+1] > arr[i] {
					valley++
				}
			} else if i == n-1 && i-1 >= 0 {
				if arr[i-1] > arr[i] {
					valley++
				}
			} else {
				if i-1 >= 0 && i < n && arr[i-1] > arr[i] && arr[i+1] > arr[i] {
					valley++
				}
			}
		}

		//	fmt.Println("Valley ", valley)
		if valley == 1 || len(arr) == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

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

		a := make([]int, n + 2)
		a[0] = 1e9 + 7
		a[n+1] = 1e9 + 7
		for i := 1; i <= n; i++ {
			fmt.Fscan(r, &a[i])
		}

		res := "YES"
		cnt := 0

		var on bool
		for i := 1; i <= n && cnt < 2; i++ {
			if a[i] < a[i-1] && a[i] < a[i+1] {
				// fmt.Fprintln(w, "%%%% 1 i", i)
				cnt++
			}
			if a[i] > a[i-1] {
				on = false
				// fmt.Fprintln(w, "%%%% 1 on i", on, i)
			} else if a[i] < a[i-1] {
				on = true
				// fmt.Fprintln(w, "%%%% 2 on i", on, i)
			} else if a[i] < a[i+1] && on {
				// fmt.Fprintln(w, "%%%% 2 i", i)
				cnt++
			}
		}

		// fmt.Fprintln(w, "%%% cnt", cnt)
		if cnt != 1 {
			res = "NO"
		}

		fmt.Fprintln(w, res)

	}

}

package main

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

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		s := 0
		for j := 0; j < n; j++ {
			l, r := j-1, j+1
			for l >= 0 && a[l] == a[j] {
				l--
			}
			for r < n && a[j] == a[r] {
				r++
			}
			if l == -1 && r < n && a[j] < a[r] {
				s++
			} else if r == n && l >= 0 && a[j] < a[l] {
				s++
			} else if l >= 0 && r < n && a[j] < a[l] && a[j] < a[r] {
				s++
			}
			if r == n {
				break
			}
			j = r - 1
		}
		if s <= 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	usedDesc := false
	for i := 1; i < n; i++ {
		if arr[i-1] < arr[i] {
			if !usedDesc {
				usedDesc = true
				continue
			}
		}
		if arr[i-1] > arr[i] {
			if usedDesc {
				fmt.Fprintln(out, "NO")
				return
			}
		}
	}
	fmt.Fprintln(out, "YES")
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"index/suffixarray"
	"log"
	"math"
	"net"
	"os"
	"path"
	"sort"
	"strconv"
	"strings"
	"time"
)

// For Codeforces
func main() {
	io := newStdIO()
	defer io.Flush()
	for T := io.ScanUInt16(); T > 0; T-- {
		solve(&io)
	}
}
func solve(io *IO) {
	n := io.ScanInt32()
	s := make([]int32, n)
	for i := int32(0); i < n; i++ {
		s[i] = io.ScanInt32()
	}

	s = append(s, s[n-1]+1)
	s = append([]int32{s[0] + 1}, s...)
	c := 0
	l := 1
	r := 1
	for {
		for r+1 < len(s) && s[r] == s[r+1] {
			r++
		}
		if s[r] < s[r+1] {
			if c == 1 {
				c++
				goto fin
			} else {
				c++
			}

			for r+1 < len(s) && s[r] <= s[r+1] {
				r++
			}
			l = r
		} else {

			l = r + 1
			r = l
		}
		if r+1 == len(s) {
			break
		}
	}
fin:
	if c == 1 {
		io.PrintLn("YES")
		return
	}
	io.PrintLn("NO")
}
func MaxN(n []int32) int32 {
	m := n[0]
	for i := 1; i < len(n); i++ {
		m = Max(m, n[i])
	}
	return m
}

// #region INTERFACES

// From https://pkg.go.dev/golang.org/x/exp/constraints
type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}
type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
type Integer interface {
	Signed | Unsigned
}
type Float interface {
	~float32 | ~float64
}
type Complex interface {
	~complex64 | ~complex128
}
type Ordered interface {
	Integer | Float | ~string
}

type Prioritizable[T any] interface {
	PriorTo(x T) bool // If you take this as a relation: if (a,b) in R => (b,a) not in R
}

// #endregion
// #region TYPES WITH METHODS
// #region SingleLinkedList
type singleLinkedListNode[T comparable] struct {
	Value T
	Next  *singleLinkedListNode[T]
}

type SingleLinkedList[T comparable, IndexType Unsigned] struct {
	first  *singleLinkedListNode[T]
	last   *singleLinkedListNode[T]
	length IndexType
}

func NewSingleLinkedList[T comparable, IndexType Unsigned]() *SingleLinkedList[T, IndexType] {
	return &SingleLinkedList[T, IndexType]{
		first:  nil,
		last:   nil,
		length: 0,
	}
}
func (l *SingleLinkedList[T, I]) Len() I { return l.length }

// length > 0
func (l *SingleLinkedList[T, I]) First() T { return l.first.Value }

// length > 0
func (l *SingleLinkedList[T, I]) Last() T { return l.last.Value }

func (l *SingleLinkedList[T, I]) InsertFirst(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.first = &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) InsertLast(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.last.Next = &singleLinkedListNode[T]{
			Value: value,
			Next:  nil,
		}
		l.last = l.last.Next
	}
	l.length++
}

// index <= length
func (l *SingleLinkedList[T, I]) InsertAt(index I, value T) {
	if index == 0 {
		l.InsertFirst(value)
		return
	}
	if index == l.length {
		l.InsertLast(value)
		return
	}

	n := l.first
	for index > 1 {
		n = n.Next
		index--
	}
	n.Next = &singleLinkedListNode[T]{
		Value: value,
		Next:  n.Next,
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) Contains(value T) bool {
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		if tmp.Value == value {
			return true
		}
		tmp = tmp.Next
	}
	return false
}
func (l *SingleLinkedList[T, I]) Clear() {
	l.first = nil
	l.last = nil
	l.length = 0
}

// index < length
func (l *SingleLinkedList[T, I]) GetElementAt(index I) T {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	return n.Value
}

// index < length
func (l *SingleLinkedList[T, I]) SetElementAt(index I, value T) {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	n.Value = value
}

func (l *SingleLinkedList[T, I]) RemoveFirst() T {
	tmp := l.first
	l.first = l.first.Next
	l.length--
	if l.length == 0 {
		l.last = nil
	}
	return tmp.Value
}
func (l *SingleLinkedList[T, I]) RemoveLast() (value T) {
	value = l.last.Value
	if l.length == 1 {
		l.first = nil
		l.last = nil
		l.length = 0
		return
	}

	tmp := l.first
	for i := I(2); i < l.length; i++ {
		tmp = tmp.Next
	}
	l.last = tmp
	return
}

func (l *SingleLinkedList[T, I]) RemoveAt(index I) T {
	if index == 0 {
		return l.RemoveFirst()
	}
	if index == l.length-1 {
		return l.RemoveLast()
	}

	tmp := l.first
	for i := I(1); i < index; i++ {
		tmp = tmp.Next
	}
	res := tmp.Next.Value
	tmp.Next = tmp.Next.Next
	return res
}

func (l *SingleLinkedList[T, I]) ToSlice() (res []T) {
	res = make([]T, 0, l.length)
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		res = append(res, tmp.Value)
		tmp = tmp.Next
	}
	return
}
func (it *SingleLinkedList[T, I]) String() string {
	return "Qua:: " + fmt.Sprint(it.ToSlice())
}

// #endregion
// #region Queue

type Queue[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewQueue[T comparable, I Unsigned]() *Queue[T, I] {
	return &Queue[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (q *Queue[T, I]) Len() I          { return q.l.length }
func (q *Queue[T, I]) Enqueue(value T) { q.l.InsertLast(value) }
func (q *Queue[T, I]) Dequeue(T) T     { return q.l.RemoveFirst() }
func (q *Queue[T, I]) Preview() T      { return q.l.First() }
func (q *Queue[T, I]) String() string  { return q.l.String() }

// #endregion
// #region Stack

type Stack[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewStack[T comparable, I Unsigned]() *Stack[T, I] {
	return &Stack[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (s *Stack[T, I]) Len() I         { return s.l.length }
func (s *Stack[T, I]) Push(value T)   { s.l.InsertFirst(value) }
func (s *Stack[T, I]) Pop(T) T        { return s.l.RemoveFirst() }
func (s *Stack[T, I]) Preview() T     { return s.l.First() }
func (s *Stack[T, I]) String() string { return s.l.String() }

// #endregion
// #region Heap
type BinaryHeap[T Prioritizable[T], I Signed] struct {
	s []T
}

func NewBinaryHeap[T Prioritizable[T], I Signed](s []T) (h *BinaryHeap[T, I]) {
	h = &BinaryHeap[T, I]{
		s: s,
	}

	for i := (h.Len() - 2) / 2; i >= 0; i-- {
		h.heapifyDown(i)
	}
	return
}
func (h *BinaryHeap[T, I]) Len() I {
	return I(len(h.s))
}
func (h *BinaryHeap[T, I]) Push(value T) {
	h.s = append(h.s, value)
	h.heapifyUp(h.Len() - 1)
}
func (h *BinaryHeap[T, I]) Pop() (res T) {
	res = h.s[0]
	h.s[0] = h.s[h.Len()-1]
	h.s = h.s[:h.Len()-1]
	h.heapifyDown(0)
	return
}

func (h *BinaryHeap[T, I]) heapifyDown(index I) bool {
	origin := index
	for {
		j := index*2 + 2
		if j < h.Len() {
			if h.s[j-1].PriorTo(h.s[j]) {
				j--
			}
		} else {
			if j <= h.Len() && !h.s[j].PriorTo(h.s[index]) {
				h.s[j], h.s[index] = h.s[index], h.s[j]
			}
			break
		}
		if h.s[j].PriorTo(h.s[index]) {
			h.s[j], h.s[index] = h.s[index], h.s[j]
			index = j
		} else {
			break
		}
	}
	return origin != index
}
func (h *BinaryHeap[T, I]) heapifyUp(index I) {
	for {
		parent := (index - 1) / 2
		if parent == index || h.s[parent].PriorTo(h.s[index]) {
			break
		}
		h.s[index], h.s[parent] = h.s[parent], h.s[index]
		index = parent
	}
}

// #endregion

// #endregion

// #region FUNCTIONS
func Max[T Ordered](a, b T) T {
	if a >= b {
		return a
	}
	return b
}
func Min[T Ordered](a, b T) T {
	if a <= b {
		return a
	}
	return b
}
func Abs[T Integer | Float](a T) T {
	if a < 0 {
		return -a
	}
	return a
}
func Swap[T any](a, b *T) {
	*a, *b = *b, *a
}

// At least one != 0
func GCD[T Unsigned](a, b T) T {
	if b < a {
		Swap(&a, &b)
	}
	for {
		if a == 0 {
			return b
		}
		r := (b % a)
		b = a
		a = r
	}
}

// At least one != 0
func LCM[T Unsigned](a, b T) T {
	return (a * b) / GCD(a, b)
}

func First[T any](a T, _ any) T { return a }

// #endregion

// #region IO STUFF
type IO struct {
	r *bufio.Reader
	w *bufio.Writer
}

func newStdIO() IO {
	return IO{
		r: bufio.NewReader(os.Stdin),
		w: bufio.NewWriter(os.Stdout),
	}
}

// Is assumed that input.txt file exists
func newFileIO() IO {
	return IO{
		r: bufio.NewReader(First(os.Open("input.txt"))),
		w: bufio.NewWriter(First(os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm))),
	}
}

func (io *IO) ScanInt8() (x int8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt16() (x int16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt32() (x int32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt64() (x int64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanUInt8() (x uint8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt16() (x uint16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt32() (x uint32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt64() (x uint64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanFloat32() (x float32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanFloat64() (x float64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanString() (x string) { fmt.Fscan(io.r, &x); return }

func (io *IO) Print(x ...any)   { fmt.Fprint(io.w, x...) }
func (io *IO) PrintLn(x ...any) { fmt.Fprintln(io.w, x...) }

func (io *IO) Flush() { io.w.Flush() }

// #endregion

// #region KEEP IMPORTS
func D() {
	_ = bufio.Reader{}
	_ = bytes.Buffer{}
	_ = suffixarray.Index{}
	_ = log.Default()
	_ = math.Abs(0)
	_ = net.Dialer{}
	_ = path.ErrBadPattern
	_ = sort.Float64sAreSorted(nil)
	_ = strconv.ErrRange
	_ = strings.Builder{}
	_ = time.ANSIC
	_ = newStdIO()
	_ = newFileIO()
}

// #endregion

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		right := make([]bool, n)
		left := make([]bool, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &nums[j])
		}
		left[0] = true
		for j := 1; j < n; j++ {
			if nums[j] < nums[j-1] {
				left[j] = true
			}
		}
		right[n-1] = true
		for j := n - 2; j >= 0; j-- {
			if nums[j] < nums[j+1] {
				right[j] = true
			}
		}
		ans := 0
		l := 0
		for r := 0; r < n && l < n; r++ {
			for r < n && nums[r] == nums[l] {
				r++
			}
			r--
			if left[l] && right[r] {
				ans++
			}
			l = r + 1
		}
		// 输出res
		if ans == 1 {
			fmt.Fprint(out, "YES\n")
		} else {
			fmt.Fprint(out, "NO\n")
		}

	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	a := readArrayInt(reader)

	var l, r, cnt int
	for i := 0; i < n; i++ {
		if i == 0 || a[i] < a[i-1] {
			l = i
		}
		if i == n-1 || a[i] < a[i+1] {
			r = i
			if l >= 0 && l <= r {
				cnt++
				l = -1
			}
		}
	}
	if cnt == 1 {
		fmt.Fprintln(writer, "YES")
	} else {
		fmt.Fprintln(writer, "NO")
	}
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		n := nextInt()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = nextInt()
		}
		ans := 0
		for i := 0; i < n; i++ {
			j := i
			for j < n && a[j] == a[i] {
				j++
			}
			j = max(i, j-1)
			if (i == 0 || a[i-1] > a[i]) && (j == n-1 || a[j] < a[j+1]) {
				//fmt.Printf("%d %d\n", i, j)
				ans++
			}
			i = j
		}
		if ans == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

package main

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

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

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		for len(a) > 1 && a[0] >= a[1] {
			a = a[1:]
		}
		for len(a) > 1 && a[0] <= a[1] {
			a = a[1:]
		}
		if len(a) < 2 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

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

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

}

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1760D
Date: 11/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1760/D
Problem: CF1760D
**/
func (in *CF1760D) Run() {
	for t := in.NextInt(); t > 0; t-- {
		nL := in.NextInt()
		arr := make([]int, 0)
		last := -1

		for i := 0; i < nL; i++ {
			val := in.NextInt()
			if last != val {
				arr = append(arr, val)
			}
			last = val
		}
		n := len(arr)

		valley := 0
		for i := 0; i < n; i++ {
			if i == 0 && i+1 < n {
				if arr[i+1] > arr[i] {
					valley++
				}
			} else if i == n-1 && i-1 >= 0 {
				if arr[i-1] > arr[i] {
					valley++
				}
			} else {
				if i-1 >= 0 && i < n && arr[i-1] > arr[i] && arr[i+1] > arr[i] {
					valley++
				}
			}
		}

		//	fmt.Println("Valley ", valley)
		if valley == 1 || nL == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1760D
Date: 11/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1760/D
Problem: CF1760D
**/
func (in *CF1760D) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, 0)
		last := -1

		for i := 0; i < n; i++ {
			val := in.NextInt()
			if last != val {
				arr = append(arr, val)
			}
			last = val
		}
		n = len(arr)
		valley := 0
		for i := 2; i < n; i++ {
			if arr[i-2] > arr[i-1] && arr[i-1] < arr[i] {
				//fmt.Println("a")
				valley++
			}
		}

		equals := 0
		for equals < n {
			if arr[equals] == arr[0] {
				equals++
			} else {
				equals--
				break
			}
		}

		if equals < n-1 {
			if arr[equals] < arr[equals+1] {
				//fmt.Println("b", equals, arr[equals], arr[equals+1])
				valley++
			}
		}

		if equals != n {
			equals = n - 1
			for equals > 0 {
				if arr[equals] == arr[n-1] {
					equals--
				} else {
					equals++
					break
				}
			}

			if equals > 0 {
				if arr[equals-1] > arr[equals] {
					//fmt.Println("c", equals, arr[equals], arr[equals-1])
					valley++
				}
			}

		} else {
			valley++
		}
		//	fmt.Println("Valley ", valley)
		if valley == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

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

		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}

		res := "YES"
		if n > 1 {
			cnt := 0
			if a[0] < a[1] {
				// fmt.Fprintln(w, "%%%% 1 i", 0)
				cnt++
			}
			if a[n-2] > a[n-1] {
				// fmt.Fprintln(w, "%%%% 2 i", n-1)
				cnt++
			}

			on := true
			for i := 1; i < n-1 && cnt < 2; i++ {
				if a[i] < a[i-1] && a[i] < a[i+1] {
					// fmt.Fprintln(w, "%%%% 3 i", i)
					cnt++
				}
				if a[i] > a[i-1] {
					on = false
					// fmt.Fprintln(w, "%%%% 1 on i", on, i)
				} else if a[i] < a[i-1] {
					on = true
					// fmt.Fprintln(w, "%%%% 2 on i", on, i)
				} else if a[i] < a[i+1] && on {
					// fmt.Fprintln(w, "%%%% 4 i", i)
					cnt++
				}
			}

			// fmt.Fprintln(w, "%%% cnt", cnt)
			if cnt != 1 {
				res = "NO"
			}
		}

		fmt.Fprintln(w, res)

	}

}

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

		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}

		res := "YES"
		if n > 2 {
			cnt := 0
			if a[0] < a[1] {
				// fmt.Fprintln(w, "%%%% 1 i", 0)
				cnt++
			}
			if a[n-2] > a[n-1] {
				// fmt.Fprintln(w, "%%%% 2 i", n-1)
				cnt++
			}

			on := true
			for i := 1; i < n-1 && cnt < 2; i++ {
				if a[i] < a[i-1] && a[i] < a[i+1] {
					// fmt.Fprintln(w, "%%%% 3 i", i)
					cnt++
				}
				if a[i] > a[i-1] {
					on = false
					// fmt.Fprintln(w, "%%%% 1 on i", on, i)
				} else if a[i] < a[i-1] {
					on = true
					// fmt.Fprintln(w, "%%%% 2 on i", on, i)
				} else if a[i] < a[i+1] && on {
					// fmt.Fprintln(w, "%%%% 4 i", i)
					cnt++
				}
			}

			// fmt.Fprintln(w, "%%% cnt", cnt)
			if cnt != 1 {
				res = "NO"
			}
		}

		fmt.Fprintln(w, res)

	}

}


package main

import (
	"fmt"
)

// 1200
// 30.05.2020
// https://codeforces.com/problemset/problem/1104/B

func main() {
	var b []byte
	fmt.Scanln(&b)

	var cnt int
	stack := make([]byte, 50000)
	for _, a := range b {
		if len(stack) > 0 && stack[len(stack)-1] == a {
			stack = stack[:len(stack)-1]
			cnt++
		} else {
			stack = append(stack, a)
		}
	}
	if cnt%2 == 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	s := ""
	fmt.Fscanf(in, "%s\n", &s)
	ans := 0
	st := make([]byte, 0)
	for i := 0; i < len(s); i++ {
		if len(st) > 0 && st[len(st)-1] == s[i] {
			st = st[:len(st)-1]
			ans++
		} else {
			st = append(st, s[i])
		}
	}
	if ans%2 == 0 {
		fmt.Fprintf(out, "No\n")
	} else {
		fmt.Fprintf(out, "Yes\n")
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"

func min(a,b int)int {
    var res int
    if a<b {
        res=a
    } else {
        res=b;
    }
    return res;
}

func solve(){
    var s string
    var n,i,flag,top int
    flag=0
    var st [100010] int
    top=0
    s=readString()
    n=len(s)
    for i=0;i<n;i++{
        if top==0{
            st[top]=(int)(s[i]-'a')
            top=top+1
        }else if st[top-1]!=(int)(s[i]-'a') {
            st[top]=(int)(s[i]-'a')
            top=top+1
        }else{
            top=top-1
            flag=flag^1
        }
    }
    if flag==0{
        fmt.Println("No")
    }else{
        fmt.Println("Yes")
    }

}

var scanner *bufio.Scanner

func main() {
    scanner = bufio.NewScanner(os.Stdin)
    const MaxTokenLength = 1024 * 1024
    scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
    scanner.Split(bufio.ScanWords)
    solve()
}
func readString() string {
    scanner.Scan()
    return scanner.Text()
}

func readInt() int {
    val, _ := strconv.Atoi(readString())
    return val
}

func readInt64() int64 {
    v, _ := strconv.ParseInt(readString(), 10, 64)
    return v
}

package main

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

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

	str := make([]byte,100100)
	fmt.Fscanf(buf, "%s\n", &str)
	slen := len(string(str))
	sk := make([]byte,slen+10)
	front := 0

	for i:= 0;i < slen;i++{
		if front > 0&&str[i] == sk[front-1]{
			front--
		}else{
			sk[front] = str[i]
			front++
		}
	}
	//fmt.Printf("%d %d\n",slen,front)
	if ((slen-front)/2)%2 == 0{
		fmt.Printf("No\n")
	}else{
		fmt.Printf("Yes\n")
	}
}

package main

import "fmt"

func main() {

	var s string
	fmt.Scanf("%s", &s)

	id := 0
	m := make([]int32, 100010)
	winner := 0

	for i := 0; i < len(s); i++ {
		if id == 0 {
			m[id] = int32(s[i])
			id++
		} else {
			if int32(s[i]) == m[id-1] {
				winner = (winner + 1) % 2
				id--
			} else {
				m[id] = int32(s[i])
				id++
			}

		}
	}

	if winner == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func explore() {
	n := 6
	ks := []int{3}

	queue := []int{0}
	total := 1 << n
	seen := make([]bool, total)
	seen[0] = true
	for len(queue) > 0 {
		m := queue[0]
		queue = queue[1:]
		for _, k := range ks {
			k1 := (1<<k - 1)
			for i := 0; i+k <= n; i++ {
				mm := m ^ (k1 << i)
				if !seen[mm] {
					seen[mm] = true
					queue = append(queue, mm)
				}
			}
		}
	}
	cnt := 0
	for i := 0; i < total; i++ {
		if seen[i] {
			cnt++
			parity := 0
			for j := 0; j < n; j++ {
				if (i>>j)&1 == 1 {
					parity ^= (1 << (j % ks[0]))
				}
			}
			printf("%0"+strconv.Itoa(n)+"b %0"+strconv.Itoa(ks[0])+"b\n", i, parity)
		}
	}
	printf("found %d out of %d: %f\n", cnt, total, float64(cnt)/float64(total))
}

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

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

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

const TAM = int(1e6 + 10)

var a [TAM]int
var n, x int

func solve() int64 {
	var ans int64 = 0
	for i := 0; i < x; i++ {
		flag := 0
		var minAbs int = abs(a[i])
		for j := i; j < n; j += x {
			if abs(a[j]) < minAbs {
				minAbs = abs(a[j])
			}
			if a[j] < 0 {
				flag ^= 1
			}
		}
		if flag == 1 {
			ans += int64(minAbs)
		}
	}
	return ans
}

func solveCase() int64 {
	var m int
	var ans int64 = 0
	var sum int64 = 0
	scan(&n, &m)
	for i := 0; i < n; i++ {
		scan(&a[i])
		sum += int64(abs(a[i]))
	}
	x = 0
	var y int
	for i := 0; i < m; i++ {
		scan(&y)
		x = gcd(x, y)
	}
	ans = solve()
	for i := 0; i < x; i++ {
		a[i] = -a[i]
	}
	return sum - 2*min(ans, solve())
}

func main() {
	defer flush()
	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		printf("%d\n", solveCase())
	}
}

/**
If only 1 in B: Reaches anything. 1
If only 2 in B: Reaches even number of 1s. 1/2
...
If only x in B: Reaches any combination of bits in the prefix of size n-x+1.
								But the last x-1 are fixed. So it reaches 1/2^(x-1)

----

Given 0 <= i < x. Consider the answer for a[i], a[i+x], a[i+2x], ....
Applying flips on a[i, ..., i+x-1] and on a[i+1, ..., i+x] only flips
	a[i] and a[i+x], keeping everything else equal.
This shows the problem is reduced to the problem of B={2}.

This reaches 1/2^x. In order to account for all 1/2^(x-1). We must solve the
problem twice, with the initial array a and after flipping a[0, ..., x-1].

----

Theory: In the general case we can assume x=GCD(B).

This is true, because if B={a,b}. We have that a*x+b*y = gcd(a,b) = d, and
since a,b <= n/2, we should be able to build a sequence of flips to flip gcd(a,b)
consecutive elements. This is true because we can reorder a*x+b*y=d into something
like:
a - b + a - b + a + a - b + a - b = gcd(a,b)
In such a way that any prefix of the left hand side is always in [0, n].

Then by induction we can generalize.
*/

package main

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

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

	solve := func(Case int) {
		var n, m, g int
		Fscan(in, &n, &m)
		tot := int64(0)

		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			tot += int64(abs(a[i]))
		}

		Fscan(in, &g)
		for i := 1; i < m; i++ {
			var v int
			Fscan(in, &v)
			g = gcd(g, v)
		}
		if g == 1 {
			Fprintln(out, tot)
			return
		}

		d := make([]int, n+5)
		flip := 0
		for i := range a {
			flip ^= d[i]
			if flip > 0 {
				a[i] = -a[i]
			}
			if i+g <= n && a[i] < 0 {
				flip ^= 1 // flip [i,i+g)
				d[i+g] ^= 1
				a[i] = -a[i]
			}
		}

		//Println(a)

		gs := make([]int, g)
		for _i := range gs {
			gs[_i] = 2e9
		}
		mi := make([]int, g)
		for _i := range mi {
			mi[_i] = 2e9
		}

		for i := len(a) - 1; i >= 0; i-- {
			v := a[i]
			j := i % g
			if gs[j] == 2e9 {
				gs[j] = v
			}
			mi[j] = min(mi[j], abs(v))
		}

		var s1, s2 int64
		for i, v := range gs {
			if v < 0 {
				s1 += int64(mi[i])
			} else {
				s2 += int64(mi[i])
			}
		}

		min2 := min64(s1,s2)

		Fprintln(out, tot-min2*2)
	}

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

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

}

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

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

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

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

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