Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index.There are $$$n$$$ cities and $$$n−1$$$ undirected roads connecting pairs of cities. Citizens of any city can reach any other city traveling by these roads. Cities are numbered from $$$1$$$ to $$$n$$$ and the city $$$1$$$ is a capital. In other words, the country has a tree structure.There are $$$m$$$ citizens living in the country. A $$$p_i$$$ people live in the $$$i$$$-th city but all of them are working in the capital. At evening all citizens return to their home cities using the shortest paths. Every person has its own mood: somebody leaves his workplace in good mood but somebody are already in bad mood. Moreover any person can ruin his mood on the way to the hometown. If person is in bad mood he won't improve it.Happiness detectors are installed in each city to monitor the happiness of each person who visits the city. The detector in the $$$i$$$-th city calculates a happiness index $$$h_i$$$ as the number of people in good mood minus the number of people in bad mood. Let's say for the simplicity that mood of a person doesn't change inside the city.Happiness detector is still in development, so there is a probability of a mistake in judging a person's happiness. One late evening, when all citizens successfully returned home, the government asked uncle Bogdan (the best programmer of the country) to check the correctness of the collected happiness indexes.Uncle Bogdan successfully solved the problem. Can you do the same?More formally, You need to check: "Is it possible that, after all people return home, for each city $$$i$$$ the happiness index will be equal exactly to $$$h_i$$$".

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5$$$; $$$0 \le m \le 10^9$$$) — the number of cities and citizens. The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \ldots, p_{n}$$$ ($$$0 \le p_i \le m$$$; $$$p_1 + p_2 + \ldots + p_{n} = m$$$), where $$$p_i$$$ is the number of people living in the $$$i$$$-th city. The third line contains $$$n$$$ integers $$$h_1, h_2, \ldots, h_{n}$$$ ($$$-10^9 \le h_i \le 10^9$$$), where $$$h_i$$$ is the calculated happiness index of the $$$i$$$-th city. Next $$$n − 1$$$ lines contain description of the roads, one per line. Each line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$; $$$x_i \neq y_i$$$), where $$$x_i$$$ and $$$y_i$$$ are cities connected by the $$$i$$$-th road. It's guaranteed that the sum of $$$n$$$ from all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print YES, if the collected data is correct, or NO — otherwise. You can print characters in YES or NO in any case.

NoteLet's look at the first test case of the first sample:   At first, all citizens are in the capital. Let's describe one of possible scenarios:   a person from city $$$1$$$: he lives in the capital and is in good mood;  a person from city $$$4$$$: he visited cities $$$1$$$ and $$$4$$$, his mood was ruined between cities $$$1$$$ and $$$4$$$;  a person from city $$$3$$$: he visited cities $$$1$$$ and $$$3$$$ in good mood;  a person from city $$$6$$$: he visited cities $$$1$$$, $$$3$$$ and $$$6$$$, his mood was ruined between cities $$$1$$$ and $$$3$$$;  In total,   $$$h_1 = 4 - 0 = 4$$$,  $$$h_2 = 0$$$,  $$$h_3 = 1 - 1 = 0$$$,  $$$h_4 = 0 - 1 = -1$$$,  $$$h_5 = 0$$$,  $$$h_6 = 0 - 1 = -1$$$,  $$$h_7 = 0$$$. The second case of the first test:   All people have already started in bad mood in the capital — this is the only possible scenario.The first case of the second test:   The second case of the second test:   It can be proven that there is no way to achieve given happiness indexes in both cases of the second test.

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,m int
		Fscan(in, &n,&m)
		p,h:=make([]int,n+1),make([]int,n+1)
		for i:=1;i<=n;i++{
			Fscan(in,&p[i])
		}
		h[0]=2*m
		for i:=1;i<=n;i++{
			Fscan(in,&h[i])
		}
		e:=make([][]int,n+1)
		for i:=0;i<n-1;i++{
			var u,v int
			Fscan(in,&u,&v)
			e[u]=append(e[u],v)
			e[v]=append(e[v],u)
		}

		fl:=true
		var dfs func(int,int) (int,int)
		dfs=func(u,par int) (int,int) {
			gg,nn:=0,p[u]
			for _,v := range(e[u]){
				if v==par{
					continue
				}
				aa,bb:=dfs(v,u)
				gg+=aa
				nn+=bb
			}
			if (nn+h[u])%2!=0{
				fl=false
			}
			// Fprintln(out,nn,gg,h[u])
			if h[u]>nn || h[u]<2*gg-nn{
				fl=false
			}

			return (h[u]+nn)/2,nn
		}
		dfs(1,0)
		// Fprintln(out,m,aa,bb)
		if fl{
			Fprintln(out,"YES")
		} else {
			Fprintln(out,"NO")
		}
	}
}

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

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int
var tree [N][]int
var ans bool
var scanner *bufio.Scanner

func solve() {
	ans = true

	n := readInt()
	m := readInt()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = readInt()
		good[i] = 0
		tot[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = readInt()
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		x := readInt()
		y := readInt()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := readInt()

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

func readInt() int {
	if !scanner.Scan() {
		die(io.ErrUnexpectedEOF)
	}

	i, err := atoi(scanner.Bytes())
	if err != nil {
		die(err)
	}
	return i
}

func atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}
func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int
var tree [N][]int
var ans bool
var scanner *bufio.Scanner

func solve() {
	ans = true

	n := fs()
	m := fs()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = fs()
		good[i] = 0
		tot[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = fs()
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		x := fs()
		y := fs()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}
	defer f.Close()

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := fs()

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

func fs() int {
	if !scanner.Scan() {
		os.Exit(1)
	}
	i, _ := strconv.Atoi(scanner.Text())
	return i
}

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int
var tree [N][]int
var ans bool

func solve(in *bufio.Reader) {
	var n, m int
	ans = true

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &p[i])
		good[i] = 0
		tot[i] = 0
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &hap[i])
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}

	in := bufio.NewReader(os.Stdin)

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

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

package main

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

const N = 1e5 + 100

var p, hap, tot, good []int
var tree [][]int
var ans bool

func init() {
	p = make([]int, N)
	hap = make([]int, N)
	tot = make([]int, N)
	good = make([]int, N)
	tree = make([][]int, N)
}

func solve(in *bufio.Reader) {
	var n, m int
	ans = true

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &p[i])
		good[i] = 0
		tot[i] = 0
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &hap[i])
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}

	in := bufio.NewReader(os.Stdin)

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

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

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int
var tree [N][]int
var ans bool
var scanner *bufio.Scanner

func solve() {
	ans = true

	n := readInt()
	m := readInt()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = readInt()
		good[i] = 0
		tot[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = readInt()
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		x := readInt()
		y := readInt()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := readInt()

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

func readInt() int {
	if !scanner.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		die(err)
	}
	return i

}
func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n, _ := io.nextInt(), io.nextInt()
		x, h := io.nextInts(n), io.nextInts(n)
		g := make([][]int, n+1)
		for i := 0; i < n-1; i++ {
			u, v := io.nextInt(), io.nextInt()
			g[u] = append(g[u], v)
			g[v] = append(g[v], u)
		}

		ok := true
		var dfs func(u, p int) int
		dfs = func(u, p int) int {
			hh, xx := h[u-1], x[u-1]
			xsum, hsum := xx, 0
			for _, v := range g[u] {
				if v != p {
					xsum += dfs(v, u)
					hsum += h[v-1]
				}
			}
			if hh > xsum || hh < hsum-xx || hh&1 != xsum&1 {
				ok = false
			}
			return xsum
		}
		dfs(1, 1)

		if ok {
			io.println("YES")
		} else {
			io.println("NO")
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

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

package main

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

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

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

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

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

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

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

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

var (
	t int

	n, m int
	P, H []int
	G    [][]int
)

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n, m = ReadInt2()
		P = ReadIntSlice(n)
		H = ReadIntSlice(n)
		G = make([][]int, n)
		for i := 0; i < n-1; i++ {
			s, t := ReadInt2()
			s--
			t--

			G[s] = append(G[s], t)
			G[t] = append(G[t], s)
		}

		solve()
	}
}

func solve() {
	_, _, ok := dfs(0, -1)
	if ok {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
	// PrintfDebug("\n")
}

// 正, 負, isOK
func dfs(cid, pid int) (int, int, bool) {
	tp, tn := 0, 0

	for _, nid := range G[cid] {
		if nid == pid {
			continue
		}

		pos, neg, ok := dfs(nid, cid)
		if !ok {
			return 0, 0, false
		}

		tp += pos
		tn += neg
	}

	// 考えられる幸福度を計算する
	target := H[cid] - tp
	free := P[cid] + tn
	total := P[cid] + tn + tp
	if -free <= target && target <= free && AbsInt(target)%2 == AbsInt(free)%2 {
		// 最大はfree, tmpは新たに生じるpositive
		newPosi := (free + target) / 2
		// newNega := free - newPosi
		ppp := tp + newPosi
		nnn := total - ppp

		// PrintfDebug("cid: %d, posi: %d, nega: %d\n", cid, ppp, nnn)
		// return tp + newPosi, tn + newNega, true
		return ppp, nnn, true
	} else {
		return 0, 0, false
	}
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

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

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int

var ans bool

func solve() {
	ans = true
	n := fs()
	m := fs()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = fs()
		good[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = fs()
	}
	tree := make([][]int, n)

	for i := 0; i < n-1; i++ {
		x := fs() - 1
		y := fs() - 1
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1, tree)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int, tree [][]int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id, tree)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	maxV = len(bytes) - 1

	t := fs()

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

var bytes []byte
var l, maxV int

func fs() int {
	b := bytes[l]

	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > maxV {
			return result
		}
		b = bytes[l]
	}
	return result
}

package main

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

const N = 1e5 + 100

var p, hap, tot, good []int
var tree [][]int
var ans bool

func init() {
	p = make([]int, N)
	hap = make([]int, N)
	tot = make([]int, N)
	good = make([]int, N)
	tree = make([][]int, N)
}

func solve() {
	var n, m int
	ans = true
	n = fs()
	m = fs()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = fs()
		good[i] = 0
		tot[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = fs()
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		var x, y int
		x = fs()
		y = fs()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}
func main() {

	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	maxV = len(bytes) - 1

	t := fs()

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

var bytes []byte
var l, maxV int

func fs() int {
	b := bytes[l]

	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > maxV {
			return result
		}
		b = bytes[l]
	}
	return result
}

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int

var ans bool

func solve() {
	ans = true
	n := fs()
	m := fs()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = fs()
		good[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = fs()
	}
	tree := make([][]int, n)

	for i := 0; i < n-1; i++ {
		x := fs()
		y := fs()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1, tree)

	fmt.Println(tree)
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int, tree [][]int) {
	if !ans {
		return
	}
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id, tree)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}
	defer in.Close()

	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	maxV = len(bytes) - 1

	t := fs()

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

var bytes []byte
var l, maxV int

func fs() int {
	b := bytes[l]

	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > maxV {
			return result
		}
		b = bytes[l]
	}
	return result
}

package main

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

const N = 1e5 + 10

var p, hap, tot, good [N]int

var ans bool

func solve() {
	ans = true
	n := fs()
	m := fs()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = fs()
		good[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = fs()
	}
	tree := make([][]int, n)

	for i := 0; i < n-1; i++ {
		x := fs()
		y := fs()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1, tree)

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int, tree [][]int) {
	if !ans {
		return
	}
	tot[id] = p[id]

	for _, child := range tree[id] {
		if child == parent {
			continue
		}

		dfs(child, id, tree)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if (hap[id]+tot[id])%2 != 0 {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

func main() {

	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}
	defer in.Close()

	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	maxV = len(bytes) - 1

	t := fs()

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

var bytes []byte
var l, maxV int

func fs() int {
	b := bytes[l]

	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > maxV {
			return result
		}
		b = bytes[l]
	}
	return result
}

package main

import (
	"fmt"
	"os"
)

const N = 1e5 + 10

var p, hap, tot, good []int
var tree[][]int
var ans bool

func init(){
	ans = true
	p = make([]int, N)
	hap = make([]int, N)
	tot = make([]int, N)
	good = make([]int, N)
	tree = make([][]int, N)
}

func main() {
	var t int

	f, err := os.Open("input.txt")

	if err == nil {
		os.Stdin = f
	}
	defer f.Close()

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

func solve() {
	var n, m int
	fmt.Scan(&n, &m)

	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
		good[i] = 0
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&hap[i])
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n - 1; i++ {
		var x, y int
		fmt.Scan(&x)
		fmt.Scan(&y)
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	}else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range(tree[id]) {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if ((hap[id] + tot[id]) % 2 != 0) {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}

package main

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

const N = 1e5 + 10

var p, hap, tot, good []int
var tree[][]int
var ans bool

func init(){
	p = make([]int, N)
	hap = make([]int, N)
	tot = make([]int, N)
	good = make([]int, N)
	tree = make([][]int, N)
}

func solve() {
	var n, m int
	ans = true
	n = fs()
	m = fs()
	_ = m

	for i := 0; i < n; i++ {
		p[i] = fs()
		good[i] = 0
	}
	for i := 0; i < n; i++ {
		hap[i] = fs()
	}
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n - 1; i++ {
		var x, y int
		x = fs()
		y = fs()
		x--
		y--
		tree[x] = append(tree[x], y)
		tree[y] = append(tree[y], x)
	}

	dfs(0, -1)

	if ans {
		fmt.Println("YES")
	}else {
		fmt.Println("NO")
	}
}

func dfs(id, parent int) {
	tot[id] = p[id]

	for _, child := range(tree[id]) {
		if child == parent {
			continue
		}

		dfs(child, id)
		tot[id] += tot[child]
		good[id] += good[child]
	}

	if ((hap[id] + tot[id]) % 2 != 0) {
		ans = false
	}

	goodMood := (hap[id] + tot[id]) / 2
	if goodMood < 0 || goodMood > tot[id] {
		ans = false
	}

	if goodMood < good[id] {
		ans = false
	}

	good[id] = goodMood
}
func main() {

	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}
	defer in.Close()

	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	maxV = len(bytes) - 1

	t := fs()

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

var bytes []byte
var l, maxV int

func fs() int {
	b := bytes[l]

	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > maxV {
			return result
		}
		b = bytes[l]
	}
	return result
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	n := io.nextInt()
	a, b := io.nextInts(n), io.nextInts(n)

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

	ans := int64(0)
	later := [][]int{}
	var dfs func(u, p int) (int64, []int)
	dfs = func(u, p int) (int64, []int) {
		now, t := []int{}, int64(0)
		for _, v := range g[u] {
			s, y := dfs(v, u)
			t += s
			if len(now) < len(y) {
				now, y = y, now
			}
			now = append(now, y...)
		}
		cur := int64(a[u-1])
		ans += t + cur
		now = append(now, u)
		if t+cur <= 0 {
			later = append(later, now)
			return 0, []int{}
		}
		return t + cur, now
	}

	for i := 0; i < n; i++ {
		if b[i] == -1 {
			_, y := dfs(i+1, i+1)
			later = append(later, y)
		}
	}

	out := []int{}
	for i := len(later) - 1; i >= 0; i-- {
		out = append(out, later[i]...)
	}

	io.println(ans)
	io.printlnInts(out...)
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}


Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these n cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities.All cities are numbered 1 to n. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city.Help Shapur find how much He should travel.

First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities. Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.

A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

package main

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

// github.com/EndlessCheng/codeforces-go
func CF61D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	var v, w, wt, ans, mx uint
	Fscan(in, &n)
	type edge struct{ to, wt uint }
	g := make([][]edge, n+1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w, &wt)
		g[v] = append(g[v], edge{w, wt})
		g[w] = append(g[w], edge{v, wt})
		ans += 2 * wt
	}
	var f func(v, fa, s uint)
	f = func(v, fa, s uint) {
		if s > mx {
			mx = s
		}
		for _, e := range g[v] {
			if w := e.to; w != fa {
				f(w, v, s+e.wt)
			}
		}
	}
	f(1, 0, 0)
	Fprint(out, ans-mx)
}

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


You are given $$$n$$$ lengths of segments that need to be placed on an infinite axis with coordinates.The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $$$0$$$. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not the start. The "start" of each following segment must coincide with the "end" of the previous one. Thus, if the length of the next segment is $$$d$$$ and the "end" of the previous one has the coordinate $$$x$$$, the segment can be placed either on the coordinates $$$[x-d, x]$$$, and then the coordinate of its "end" is $$$x - d$$$, or on the coordinates $$$[x, x+d]$$$, in which case its "end" coordinate is $$$x + d$$$.The total coverage of the axis by these segments is defined as their overall union which is basically the set of points covered by at least one of the segments. It's easy to show that the coverage will also be a segment on the axis. Determine the minimal possible length of the coverage that can be obtained by placing all the segments on the axis without changing their order.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases.  The first line of each test case description contains an integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of segments. The second line of the description contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 1000$$$) — lengths of the segments in the same order they should be placed on the axis. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be a single integer — the minimal possible length of the axis coverage.

NoteIn the third sample test case the segments should be arranged as follows: $$$[0, 6] \rightarrow [4, 6] \rightarrow [4, 7] \rightarrow [-2, 7]$$$. As you can see, the last segment $$$[-2, 7]$$$ covers all the previous ones, and the total length of coverage is $$$9$$$.In the fourth sample test case the segments should be arranged as $$$[0, 6] \rightarrow [-2, 6] \rightarrow [-2, 2] \rightarrow [2, 7]$$$. The union of these segments also occupies the area $$$[-2, 7]$$$ and has the length of $$$9$$$.

package main

import (
	"fmt"
)

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func solve() {
	var n int
	fmt.Scan(&n)
	maxl := 3000
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, maxl)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < maxl; j++ {
			o1 := maxl
			if j+a[i] < maxl {
				o1 = a[i] + dp[i+1][j+a[i]]
			}
			o2 := maxl
			if j-a[i] >= 0 {
				o2 = max(0, dp[i+1][j-a[i]]-a[i])
			}
			dp[i][j] = min(o1, o2)
		}
	}

	best := maxl
	for i := 0; i < maxl; i++ {
		best = min(best, dp[0][i]+i)
	}
	fmt.Println(best)
}

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

package main

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

// https://space.bilibili.com/206214
func CF1579G(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 1e9
	const mx = 2001
	pre := make([]int, mx)
	f := make([]int, mx)

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		for i := range pre {
			pre[i] = inf
		}
		pre[0] = 0
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			for i := range f {
				f[i] = inf
			}
			for j, dis := range pre {
				if pre[j] == inf {
					continue
				}
				if j+v < mx {
					f[j+v] = min(f[j+v], max(dis, j+v))
				}
				if j >= v {
					f[j-v] = min(f[j-v], dis)
				} else {
					f[0] = min(f[0], dis-j+v)
				}
			}
			pre, f = f, pre
		}
		ans := inf
		for _, x := range pre {
			ans = min(ans, x)
		}
		Fprintln(out, ans)
	}
}
func main() { CF1579G(os.Stdin, os.Stdout) }
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if b > a {
		return b
	}
	return a
}

package main

import (
	"fmt"
)

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func solve() {
	var n int
	fmt.Scan(&n)
	maxl := 3*n + 10
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, maxl)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < maxl; j++ {
			o1 := maxl
			if j+a[i] < maxl {
				o1 = a[i] + dp[i+1][j+a[i]]
			}
			o2 := maxl
			if j-a[i] >= 0 {
				o2 = max(0, dp[i+1][j-a[i]]-a[i])
			}
			dp[i][j] = min(o1, o2)
		}
	}

	best := maxl
	for i := 0; i < maxl; i++ {
		best = min(best, dp[0][i]+i)
	}
	fmt.Println(best)
}

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

package main

import (
	"fmt"
)

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}
func solve() {
	var n int
	fmt.Scanf("%d", &n)
	maxl := 3*n + 10
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, maxl)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < maxl; j++ {
			o1 := maxl
			if j+a[i] < maxl {
				o1 = a[i] + dp[i+1][j+a[i]]
			}
			o2 := maxl
			if j-a[i] >= 0 {
				o2 = max(0, dp[i+1][j-a[i]]-a[i])
			}
			dp[i][j] = min(o1, o2)
		}
	}

	best := maxl
	for i := 0; i < maxl; i++ {
		best = min(best, dp[0][i]+i)
	}
	fmt.Println(best)
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for tt := 0; tt < t; tt++ {
		solve()
	}
}


Vlad has $$$n$$$ friends, for each of whom he wants to buy one gift for the New Year.There are $$$m$$$ shops in the city, in each of which he can buy a gift for any of his friends. If the $$$j$$$-th friend ($$$1 \le j \le n$$$) receives a gift bought in the shop with the number $$$i$$$ ($$$1 \le i \le m$$$), then the friend receives $$$p_{ij}$$$ units of joy. The rectangular table $$$p_{ij}$$$ is given in the input.Vlad has time to visit at most $$$n-1$$$ shops (where $$$n$$$ is the number of friends). He chooses which shops he will visit and for which friends he will buy gifts in each of them.Let the $$$j$$$-th friend receive $$$a_j$$$ units of joy from Vlad's gift. Let's find the value $$$\alpha=\min\{a_1, a_2, \dots, a_n\}$$$. Vlad's goal is to buy gifts so that the value of $$$\alpha$$$ is as large as possible. In other words, Vlad wants to maximize the minimum of the joys of his friends.For example, let $$$m = 2$$$, $$$n = 2$$$. Let the joy from the gifts that we can buy in the first shop: $$$p_{11} = 1$$$, $$$p_{12}=2$$$, in the second shop: $$$p_{21} = 3$$$, $$$p_{22}=4$$$.Then it is enough for Vlad to go only to the second shop and buy a gift for the first friend, bringing joy $$$3$$$, and for the second — bringing joy $$$4$$$. In this case, the value $$$\alpha$$$ will be equal to $$$\min\{3, 4\} = 3$$$Help Vlad choose gifts for his friends so that the value of $$$\alpha$$$ is as high as possible. Please note that each friend must receive one gift. Vlad can visit at most $$$n-1$$$ shops (where $$$n$$$ is the number of friends). In the shop, he can buy any number of gifts.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. An empty line is written before each test case. Then there is a line containing integers $$$m$$$ and $$$n$$$ ($$$2 \le n$$$, $$$2 \le n \cdot m \le 10^5$$$) separated by a space — the number of shops and the number of friends, where $$$n \cdot m$$$ is the product of $$$n$$$ and $$$m$$$. Then $$$m$$$ lines follow, each containing $$$n$$$ numbers. The number in the $$$i$$$-th row of the $$$j$$$-th column $$$p_{ij}$$$ ($$$1 \le p_{ij} \le 10^9$$$) is the joy of the product intended for friend number $$$j$$$ in shop number $$$i$$$. It is guaranteed that the sum of the values $$$n \cdot m$$$ over all test cases in the test does not exceed $$$10^5$$$.

Print $$$t$$$ lines, each line must contain the answer to the corresponding test case — the maximum possible value of $$$\alpha$$$, where $$$\alpha$$$ is the minimum of the joys from a gift for all of Vlad's friends.

package main

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

var o [][]int

func check(x, n, m int) bool {
	c, pair := make([]bool, m), false
	for i := 0; i < n; i++ {
		cnt := 0
		for j := 0; j < m; j++ {
			if o[i][j] >= x {
				c[j] = true
				cnt++
			}
		}
		if cnt > 1 {
			pair = true
		}
	}
	if !pair {
		return false
	}
	ans := true
	for _, v := range c {
		ans = ans && v
	}
	return ans
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m)
		o = make([][]int, n)
		for j := 0; j < n; j++ {
			o[j] = make([]int, m)
		}
		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				fmt.Fscan(f, &o[j][k])
			}
		}
		l, r := 1, 2
		for check(r, n, m) {
			r *= 2
		}
		for r-l > 1 {
			mid := (l + r) >> 1
			if check(mid, n, m) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintln(w, l)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var o [][]int

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

func check(x, n, m int) bool {
	c, pair := make([]bool, m), false
	for i := 0; i < n; i++ {
		cnt := 0
		for j := 0; j < m; j++ {
			if o[i][j] >= x {
				c[j] = true
				cnt++
			}
		}
		if cnt > 1 {
			pair = true
		}
	}
	if !pair {
		return false
	}
	ans := true
	for _, v := range c {
		ans = ans && v
	}
	return ans
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, MAX := 0, 0, 0, -1000
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m)
		o = make([][]int, n)
		for j := 0; j < n; j++ {
			o[j] = make([]int, m)
		}
		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				fmt.Fscan(f, &o[j][k])
				MAX = max(MAX, o[j][k])
			}
		}
		l, r := 1, MAX+1
		for r-l > 1 {
			mid := (l + r) >> 1
			if check(mid, n, m) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintln(w, l)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var o [][]int

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

func check(x, n, m int) bool {
	c, pair := make([]bool, m), false
	for i := 0; i < n; i++ {
		cnt := 0
		for j := 0; j < m; j++ {
			if o[i][j] >= x {
				c[j] = true
				cnt++
			}
		}
		if cnt > 1 {
			pair = true
		}
	}
	if !pair {
		return false
	}
	ans := true
	for _, v := range c {
		ans = ans && v
	}
	return ans
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m)
		o = make([][]int, n)
		for j := 0; j < n; j++ {
			o[j] = make([]int, m)
		}
		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				fmt.Fscan(f, &o[j][k])
			}
		}
		l, r := 1, 2
		for check(r, n, m) {
			r *= 2
		}
		for r-l > 1 {
			mid := (l + r) >> 1
			if check(mid, n, m) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintln(w, l)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)
)

func main() {

	var t int64
	fmt.Fscan(rr, &t)

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

		var m int64
		fmt.Fscan(rr, &m)

		var n int64
		fmt.Fscan(rr, &n)

		var ar [][]int64

		var min int64
		var max int64

		for j := int64(0); j < m; j++ {
			var arr []int64

			for k := int64(0); k < n; k++ {
				var tmp int64
				fmt.Fscan(rr, &tmp)

				arr = append(arr, tmp)
			}

			ar = append(ar, arr)
		}

		min = ar[0][0]
		max = ar[0][0]

		for j := int64(0); j < m; j++ {

			for k := int64(0); k < n; k++ {
				if ar[j][k] > max {
					max = ar[j][k]
				}

				if ar[j][k] < min {
					min = ar[j][k]
				}
			}

		}
		ans := int64(-1)

		for min <= max {
			mid := min + (max-min)/2
			// fmt.Println(mid)

			if check(ar, mid, n, m) {
				ans = mid
				min = mid + 1
			} else {
				max = mid - 1
			}
		}

		// ans := min

		fmt.Fprintln(ww, ans)
		ww.Flush()

	}
	ww.Flush()
}

func check(ar [][]int64, mid int64, n int64, m int64) bool {

	a := int64(-1)
	b := int64(-1)
	counter := int64(0)

	for j := int64(0); j < m; j++ {
		counter = 0
		a = -1
		b = -1

		for k := int64(0); k < n; k++ {
			if ar[j][k] >= mid {
				counter++
				// fmt.Println(a, b)
				if a == -1 {
					a = k
					// fmt.Println(a, b)

				} else if b == -1 {
					b = k
					break
				}
			}
		}
		if counter >= 2 {
			break
		}

	}

	if counter < 2 {
		return false
	}
	// fmt.Println(counter)

	// fmt.Println(a, b)

	for j := int64(0); j < n; j++ {
		isValid := false

		if j == a || j == b {
			continue
		}

		for k := int64(0); k < m; k++ {
			// fmt.Println(ar[k][j])
			if ar[k][j] >= mid {
				isValid = true
			}
		}

		if isValid == false {
			return false
		}

	}
	return true

	// if toUse <= (n-1) && toUse > 0 {
	// 	return true
	// }
	// return false
}

package main

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

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

	var T, n, m int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
		}
		Fprintln(out, sort.Search(1e9, func(low int) bool {
		o:
			for j := range a[0] {
				for _, r := range a {
					if r[j] > low {
						continue o
					}
				}
				return true
			}
			for _, r := range a {
				ok := false
				for _, v := range r {
					if v > low {
						if ok {
							return false
						}
						ok = true
					}
				}
			}
			return true
		}))
	}
}

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

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, m int
	scan(&m, &n)
	p := make([][]int, m)
	for i := range p {
		p[i] = make([]int, n)
		for j := range p[i] {
			scan(&p[i][j])
		}
	}

	chk1 := func(x int) bool {
		set := map[int]int{}
		for i := 0; i < m; i++ {
			for j := range p[i] {
				if p[i][j] >= x {
					set[j]++
				}
			}
		}
		return len(set) == n
	}

	chk2 := func(x int) bool {
		cntByFriends := make([]int, n)
		cntByShops := make([]int, m)
		for i := range p {
			for j := range p[i] {
				if p[i][j] >= x {
					cntByFriends[j]++
					cntByShops[i]++
				}
			}
		}
		for i := range p {
			if cntByShops[i] >= 2 {
				ok := true
				for j := range p[i] {
					if p[i][j] < x && cntByFriends[j] == 0 {
						ok = false
					}
				}
				if ok {
					return true
				}
			}
		}
		return false
	}

	check := func(x int) bool {
		if n > m {
			return chk1(x)
		}
		return chk2(x)
	}

	l, r := 1, int(1e9+1)
	for r-l > 1 {
		x := l + (r-l)/2
		if check(x) {
			l = x
		} else {
			r = x
		}
	}

	printf("%v\n", l)
}

package main

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

/*
* lets try some fancy go :)
we need to binary search the maximum possible min of joy.

So, for given joy x check if we can buy a gift foreach friend.
How to implement?
Since we can buy multiple presents in each shop,
we need to find a set of n-1 shops so that
all friends are satisfied.

Most likely there are more shops than n-1, since else we would
simply buy in all shops.

We could solve with max flow algo, but that maybe TLE?

Can we choose one shop per friend?
Ok, we need to find one shop that works for two (or more) friends.
If such shop exists, then we are done since we can
choose any shop for any other friend.
*/

func main() {
    re, w, e := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout), bufio.NewWriter(os.Stderr)
    defer w.Flush()
    defer e.Flush()

    var t int=0
    Fscan(re, &t)

    for i:=0; i<t; i++ {
        var m,n int64
        Fscan(re, &m, &n)

        var ma=make([]int64,n)    // max joy friend i can get in any shop
        var p=make([][]int64, m)

        var i int64=0
        var j int64=0
        for ; i<m; i++ {
            p[i]=make([]int64, n)
        }

        // max two joys of any friends in shop i
        var ma2=make([][]int64, m)

        for i=0; i<m; i++ {
            ma2[i]=make([]int64, 2)
        }

        for i=0; i<m; i++ {
            for j=0; j<n; j++  {
                Fscan(re, &p[i][j])
                if p[i][j]>ma[j] {
                    ma[j]=p[i][j]
                }
                if ma2[i][0]<p[i][j] {
                    ma2[i][1]=ma2[i][0]
                    ma2[i][0]=p[i][j]
                } else if ma2[i][1]<p[i][j] {
                    ma2[i][1]=p[i][j]
                }
            }
        }

        var mi int64=1000000000  // min max joy of any friend, upper bound for ans
        for i=0; i<n; i++ {
            if mi>ma[i] {
                mi=ma[i]
            }
        }

        var l int64=0
        var r int64=mi+1

        for ; l+1<r ; {
            mid:=(l+r)/2
            ok:=false
            for i=0; !ok && i<m; i++ {
                if ma2[i][1]>=mid  {
                    ok=true
                }
            }
            if ok {
                l=mid
            } else {
                r=mid
            }
        }

        Fprintf(w, "%d\n", l)
    }
}

package main

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

var o [][]int

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

func check(x, n, m int) bool {
	c, pair := make([]bool, m), false
	for i := 0; i < n; i++ {
		cnt := 0
		for j := 0; j < m; j++ {
			if o[i][j] >= x {
				c[j] = true
				cnt++
			}
		}
		if cnt > 1 {
			pair = true
		}
	}
	if !pair {
		return false
	}
	ans := true
	for _, v := range c {
		ans = ans && v
	}
	return ans
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, MAX := 0, 0, 0, -1000
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m)
		o = make([][]int, n)
		for j := 0; j < n; j++ {
			o[j] = make([]int, m)
		}
		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				fmt.Fscan(f, &o[j][k])
				MAX = max(MAX, o[j][k])
			}
		}
		l, r := 1, MAX
		for r-l > 1 {
			mid := (l + r) >> 1
			if check(mid, n, m) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Fprintln(w, l)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)
)

func main() {

	var t int64
	fmt.Fscan(rr, &t)

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

		var m int64
		fmt.Fscan(rr, &m)

		var n int64
		fmt.Fscan(rr, &n)

		var ar [][]int64

		var min int64
		var max int64

		for j := int64(0); j < m; j++ {
			var arr []int64

			for k := int64(0); k < n; k++ {
				var tmp int64
				fmt.Fscan(rr, &tmp)

				arr = append(arr, tmp)
			}

			ar = append(ar, arr)
		}

		min = ar[0][0]
		max = ar[0][0]

		for j := int64(0); j < m; j++ {

			for k := int64(0); k < n; k++ {
				if ar[j][k] > max {
					max = ar[j][k]
				}

				if ar[j][k] < min {
					min = ar[j][k]
				}
			}

		}
		ans := int64(-1)

		for min <= max {
			mid := min + (max-min)/2
			// fmt.Println(mid)

			if check(ar, mid, n, m) {
				ans = mid
				min = mid + 1
			} else {
				max = mid - 1
			}
		}

		// ans := min

		fmt.Fprintln(ww, ans)
		ww.Flush()

	}
	ww.Flush()
}

func check(ar [][]int64, mid int64, n int64, m int64) bool {

	a := int64(-1)
	b := int64(-1)
	counter := int64(0)

	for j := int64(0); j < m; j++ {
		counter = 0
		a = 0
		b = 0

		for k := int64(0); k < n; k++ {
			if ar[j][k] >= mid {
				counter++
				if a == 0 {
					a = j
				} else if b == 0 {
					b = j
				}
			}
		}
		if counter >= 2 {
			break
		}

	}

	if counter < 2 {
		return false
	}

	for j := int64(0); j < n; j++ {
		isValid := false

		if j == a || j == b {
			continue
		}

		for k := int64(0); k < m; k++ {
			if ar[k][j] >= mid {
				isValid = true
			}
		}

		if isValid == false {
			return false
		}

	}
	return true

	// if toUse <= (n-1) && toUse > 0 {
	// 	return true
	// }
	// return false
}


We call two numbers $$$x$$$ and $$$y$$$ similar if they have the same parity (the same remainder when divided by $$$2$$$), or if $$$|x-y|=1$$$. For example, in each of the pairs $$$(2, 6)$$$, $$$(4, 3)$$$, $$$(11, 7)$$$, the numbers are similar to each other, and in the pairs $$$(1, 4)$$$, $$$(3, 12)$$$, they are not.You are given an array $$$a$$$ of $$$n$$$ ($$$n$$$ is even) positive integers. Check if there is such a partition of the array into pairs that each element of the array belongs to exactly one pair and the numbers in each pair are similar to each other.For example, for the array $$$a = [11, 14, 16, 12]$$$, there is a partition into pairs $$$(11, 12)$$$ and $$$(14, 16)$$$. The numbers in the first pair are similar because they differ by one, and in the second pair because they are both even.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains an even positive integer $$$n$$$ ($$$2 \le n \le 50$$$) — length of array $$$a$$$. The second line contains $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$).

For each test case print:   YES if the such a partition exists,  NO otherwise.  The letters in the words YES and NO can be displayed in any case.

NoteThe first test case was explained in the statement.In the second test case, the two given numbers are not similar.In the third test case, any partition is suitable.

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)

		res := solve(n, A)

		if res {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

func solve(n int, A []int) bool {
	var cnt int

	for i := 0; i < n; i++ {
		cnt += A[i] & 1
	}

	if cnt&1 == 0 {
		return true
	}

	sort.Ints(A)

	for i := 0; i < n-1; i++ {
		if A[i]+1 == A[i+1] {
			return true
		}
	}
	return false
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n := s.NextInt()
		arr := make([]int, n)
		m := map[int]int{}
		var c int
		var next bool
		for j := 0; j < n; j++ {
			arr[j] = s.NextInt()
			m[arr[j]]++

			if arr[j]%2 == 0 {
				c++
			}

			if _, ok := m[arr[j]+1]; ok {
				next = true
			}

			if _, ok := m[arr[j]-1]; ok {
				next = true
			}
		}

		if c%2 == 0 || next {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	even, odd, d := 0, 0, 0
	table := make([]int, 101)
	for i := 0; i < n; i++ {
		var t int
		fmt.Fscan(input, &t)
		table[t]++
		if t%2 == 1 {
			odd++
		} else {
			even++
		}
	}

	for i := 1; i < len(table); i++ {
		d += min(table[i], table[i-1])
	}

	if odd&1 != even&1 {
		fmt.Println("NO")
	} else if odd&1 == 1 && d == 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

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

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n:= reader.NextInt64()
		aa := make([]int, n)
		for i := 0; i < len(aa); i++ {
			aa[i] = reader.NextInt()
		}
		sort.Ints(aa)
		sol(aa)
	}
}

func sol(aa []int) {
	numOdd:=0
	numEven:=0
	for i:=0;i<len(aa);i++{
		if(aa[i]%2==0){
			numEven++
		}else{
			numOdd++
		}
	}
	if(numOdd%2==0 && numEven%2==0){
		writer.Printf("YES \n")
		return
	}else{
		for i:=0;i<len(aa)-1;i++ {
		if(aa[i]+1==aa[i+1]){
			aa[i]=-1
			aa[i+1]=-1
			numEven--
			numOdd--
			if(numOdd%2==0 && numEven%2==0){
				writer.Printf("YES \n")
				return
			}
		}
	}
	writer.Printf("NO \n")
	}
	// fmt.Println(aa)

	// fmt.Println(numEven,numOdd)
	// if(numOdd%2==0 && numEven%2==0){
	// 	writer.Printf("YES \n")
	// }else{
	// 	writer.Printf("NO \n")
	// }

}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

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

package main

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

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

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

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

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

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

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

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

var (
	t int
	n int
	A []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		solve(n, A)
	}
}

func solve(n int, A []int) {
	sort.Sort(sort.IntSlice(A))

	odd, even := 0, 0
	for i := 0; i < n; i++ {
		if A[i]%2 == 0 {
			even++
		} else {
			odd++
		}
	}

	if even%2 == 0 && odd%2 == 0 {
		fmt.Println("YES")
		return
	}

	for i := 1; i < n; i++ {
		if AbsInt(A[i]-A[i-1]) == 1 {
			fmt.Println("YES")
			return
		}
	}

	fmt.Println("NO")
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

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

package main

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

func solve() {
	t := readInt()
next:
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		sort.Ints(a)
		even := make([]int, 0)
		odd := make([]int, 0)
		for i := 0; i < len(a); i++ {
			if a[i]%2 == 0 {
				even = append(even, a[i])
			} else {
				odd = append(odd, a[i])
			}
		}
		if len(even) % 2 == 0 {
			fmt.Println("YES")
		} else {
			for _, v1 := range even {
				for _, v2 := range odd {
					if abs(v1-v2) == 1 {
						fmt.Println("YES")
						continue next
					}
				}
			}
			fmt.Println("NO")
		}
	}
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	var t, n int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		odd := 0
		for i := range a {
			Fscan(in, &a[i])
			if a[i]&1 == 1 {
				odd++
			}
		}
		if odd&1 == 0 {
			Fprintln(out, "YES")
			continue
		}
		for i, v := range a {
			for j, w := range a {
				if j == i {
					continue
				}
				if v&1 != w&1 && abs(v-w) == 1 {
					Fprintln(out, "YES")
					continue o
				}
			}
		}
		Fprintln(out, "NO")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	var t, n int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		odd := 0
		for i := range a {
			Fscan(in, &a[i])
			if a[i]&1 == 1 {
				odd++
			}
		}
		if odd&1 == 0 {
			Fprintln(out, "YES")
			continue
		}
		for _, v := range a {
			for _, w := range a {
				if abs(v-w) == 1 {
					Fprintln(out, "YES")
					continue o
				}
			}
		}
		Fprintln(out, "NO")
	}
}

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

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		solve()
	}

}

func solve() {
	n := ScanInt()
	a := ScanInts(n)
	mevn := make([]int, 0, n)
	modd := make([]int, 0, n)

	for i := 0; i < n; i++ {
		if a[i]%2 == 0 {
			mevn = append(mevn, a[i])
		} else {
			modd = append(modd, a[i])
		}
	}

	if len(mevn)%2 == 0 {
		P("YES")
		return
	}

	for i := 0; i < len(mevn); i++ {
		for j := 0; j < len(modd); j++ {
			if Abs(mevn[i]-modd[j]) == 1 {
				P("YES")
				return
			}
		}
	}
	P("NO")
	return
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"sort"
)

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		even := 0
		for i := 0; i < n; i++ {
		    fmt.Scanf("%d", &a[i])
		    if a[i] % 2 == 0 {
		        even++
		    }
		}
		fmt.Scanf("\n")
		if even % 2 == 0 {
		    fmt.Println("YES")
		    continue
		}
		flag := false
		sort.Ints(a)
		for i := 0; i < n - 1; i++ {
		    if (a[i] + 1 == a[i + 1]) {
		        flag = true
		        break
		    }
		}
		if flag {
		    fmt.Println("YES")
		} else {
		    fmt.Println("NO")
		}
	}
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for tt := rd(); tt > 0; tt-- {
		n := rd()
		even, odd := []int{}, []int{}
		for i := 0; i < n; i++ {
			x := rd()
			if x%2 == 0 {
				even = append(even, x)
			} else {
				odd = append(odd, x)
			}
		}
		if len(even)%2 == 0 {
			Fprintln(out, "YES")
		} else {
			for _, it := range even {
				for _, j := range odd {
					if it-j == 1 || it-j == -1 {
						Fprintln(out, "YES")
						goto next
					}
				}
			}
			Fprintln(out, "NO")
		}
	next:
	}
}

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 rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

import (
	"fmt"
	"sort"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scan(&n)
		A := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&A[i])
		}
		sort.Ints(A)
		var odd, even [] int
		neibours := false
		for i := 0; i < n; i++ {
			if (A[i] & 1) == 1 {
				odd = append(odd, A[i])
			} else {
				even = append(even, A[i])
			}
			if i+1 < n && A[i]+1 == A[i+1] {
				neibours = true
			}
		}
		// fmt.Println(A, neibours)
		if len(odd)%2 == 0 || neibours{
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		a := make([]int64, n)
		for i := range a {
			a[i] = reader.NextInt64()
		}
		writer.Printf("%s\n", sol(a))
	}
}

func sol(a []int64) string {
	if len(a)&1 == 1 {
		// should not happen
		return "NO"
	}
	numEven := 0
	numOdd := 0
	for _, ai := range a {
		if ai&1 == 1 {
			numOdd++
		} else {
			numEven++
		}
	}
	if numEven&1 == 0 && numOdd&1 == 0 {
		return "YES"
	}
	sort.Slice(a, func(x, b int) bool {
		return a[x] < a[b]
	})
	for i := 1 ; i < len(a); i++ {
		if a[i] - a[i-1] == 1 {
			return "YES"
		}
	}
	return "NO"
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n := s.NextInt()
		arr := make([]int, n)
		for j := 0; j < n; j++ {
			arr[j] = s.NextInt()
		}

		sort.Ints(arr)

		var c int
		for j := 0; j < n-1; j++ {
			if arr[j+1]-arr[j] == 1 {
				j++
			} else {
				if arr[j]%2 == 0 {
					c++
				}
				if j == n-2 && arr[j+1]%2 == 0 {
					c++
				}
			}
		}

		if c%2 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n := s.NextInt()
		arr := make([]int, n)
		for j := 0; j < n; j++ {
			arr[j] = s.NextInt()
		}

		sort.Ints(arr)

		ex := []int{}
		for j := 0; j < n-1; j++ {
			if arr[j+1]-arr[j] == 1 {
				j++
			} else {
				ex = append(ex, arr[j])
				if j == n-2 {
					ex = append(ex, arr[j+1])
				}
			}
		}

		c := 0
		for _, e := range ex {
			if e%2 == 0 {
				c++
			}
		}

		if c%2 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n := s.NextInt()
		arr := make([]int, n)
		m := map[int]int{}
		for j := 0; j < n; j++ {
			arr[j] = s.NextInt()
			m[arr[j]]++
		}

		var c int
		for j := 0; j < n; j++ {
			if v, ok := m[arr[j]]; ok && v == 0 {
				continue
			}
			m[arr[j]]--
			if v, ok := m[arr[j]+1]; ok && v > 0 {
				m[arr[j]+1]--
				continue
			}

			if v, ok := m[arr[j]-1]; ok && v > 0 {
				m[arr[j]-1]--
				continue
			}

			if arr[j]%2 == 0 {
				c++
			}
		}

		if c%2 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	even, odd := 0, 0
	table := make([]int, 101)
	for i := 0; i < n; i++ {
		var t int
		fmt.Fscan(input, &t)
		table[t]++
	}

	for i := 1; i < len(table); i++ {
		d := min(table[i], table[i - 1])
		table[i] -= d
		table[i - 1] -= d
	}

	for i := 0; i < len(table); i++ {
		if i & 1 == 1 && table[i] > 0 {
			odd += table[i]
		}
		if i & 1 == 0 && table[i] > 0 {
			even += table[i]
		}
	}

	if odd & 1 == 1 || even & 1 == 1 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

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

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	a := make([]int, n)
	even, odd, d := 0, 0, 0
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])
		if a[i] & 1 == 1 {
			odd++
		} else {
			even++
		}
	}

	sort.Ints(a)
	i := 1
	for i < n {
		if a[i] - a[i - 1] == 1 {
			d++
			i+=2
		} else {
			i++
		}
	}

	odd -= d
	even -= d

	if odd & 1 == 1 || even & 1 == 1 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	even, odd := 0, 0
	for i := 0; i < n; i++ {
		var t int
		fmt.Fscan(input, &t)
		if t % 2 == 0 {
			even++
		} else {
			odd++
		}
	}

	if odd % 2 == 0 && even % 2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

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

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n:= reader.NextInt64()
		aa := make([]int, n)
		for i := 0; i < len(aa); i++ {
			aa[i] = reader.NextInt()
		}
		sort.Ints(aa)
		sol(aa)
	}
}

func sol(aa []int) {
	numOdd:=0
	numEven:=0
	for i:=0;i<len(aa)-1;i++ {
		if(aa[i]+1==aa[i+1]){
			aa[i]=-1
			aa[i+1]=-1
			i++
		}
	}
	// fmt.Println(aa)
	for i:=0;i<len(aa);i++{
		if(aa[i]==-1){
			continue;
		}
		if(aa[i]%2==0){
			numEven++
		}else{
			numOdd++
		}
	}
	// fmt.Println(numEven,numOdd)
	if(numOdd%2==0 && numEven%2==0){
		writer.Printf("YES \n")
	}else{
		writer.Printf("NO \n")
	}

}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n:= reader.NextInt64()
		aa := make([]int, n)
		for i := 0; i < len(aa); i++ {
			aa[i] = reader.NextInt()
		}
		sort.Ints(aa)
		sol(aa)
	}
}

func sol(aa []int) {
	numOdd:=0
	numEven:=0
	for i:=0;i<len(aa)-1;i++ {
		if(aa[i]+1==aa[i+1]){
			aa[i]=-1
			aa[i+1]=-1
		}
	}
	// fmt.Println(aa)
	for i:=0;i<len(aa);i++{
		if(aa[i]==-1){
			continue;
		}
		if(aa[i]%2==0){
			numEven++
		}else{
			numOdd++
		}
	}
	// fmt.Println(numEven,numOdd)
	if(numOdd%2==0 && numEven%2==0){
		writer.Printf("YES \n")
	}else{
		writer.Printf("NO \n")
	}

}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n:= reader.NextInt64()
		aa := make([]int, n)
		for i := 0; i < len(aa); i++ {
			aa[i] = reader.NextInt()
		}
		sort.Ints(aa)
		sol(aa)
	}
}

func sol(aa []int) {
	numOdd:=0
	numEven:=0
	for i:=0;i<len(aa);i++{
		if(aa[i]%2==0){
			numEven++
		}else{
			numOdd++
		}
	}
	for i:=0;i<len(aa)-1;i++ {
		if(aa[i]+1==aa[i+1]){
			aa[i]=-1
			aa[i+1]=-1
			numEven--
			numOdd--
		}
	}
	// fmt.Println(aa)

	// fmt.Println(numEven,numOdd)
	if(numOdd%2==0 && numEven%2==0){
		writer.Printf("YES \n")
	}else{
		writer.Printf("NO \n")
	}

}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		sort.Ints(a)
		for i := 1; i < len(a); i++ {
			if a[i - 1] + 1 == a[i] {
				a[i-1] = -10000
				a[i] = -10000
			}
		}
		revB := make([]int, 2)
		for _, v := range a {
			revB[v % 2]++
		}
		if revB[0] % 2 == 0 && revB[1] % 2 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		sort.Ints(a)
		used := make([]bool, len(a))
		if dfs(a, used, 0) && usedAll(used){
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func usedAll(used []bool) bool {
	for _, yes := range used {
		if !yes {
			return false
		}
	}
	return true
}

func dfs(a []int, used []bool, pos int) bool {
	if pos >= len(a) {
		return true
	}
	used[pos] = true
	for i := pos + 1; i < len(a); i++ {
		if !used[i] && (a[pos]%2 == a[i]%2 || (abs(a[pos]-a[i])) <= 1) {
			used[i] = true
			res := dfs(a, used, i + 1)
			if res {
				// fmt.Println("YES", a[pos], a[i])
				return true
			}
			used[i] = false
		}
	}
	used[pos] = false
	return false
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}