Given an array $$$a=[a_1,a_2,\dots,a_n]$$$ of $$$n$$$ positive integers, you can do operations of two types on it:  Add $$$1$$$ to every element with an odd index. In other words change the array as follows: $$$a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots$$$.  Add $$$1$$$ to every element with an even index. In other words change the array as follows: $$$a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, \dots$$$.Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^3$$$) — the elements of the array. Note that after the performed operations the elements in the array can become greater than $$$10^3$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteFor the first test case, we can increment the elements with an even index, obtaining the array $$$[1, 3, 1]$$$, which contains only odd numbers, so the answer is "YES".For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO".For the third test case, all elements already have the same parity so the answer is "YES".For the fourth test case, we can perform one operation and increase all elements at odd positions by $$$1$$$, thus obtaining the array $$$[1001, 1, 1001, 1, 1001]$$$, and all elements become odd so the answer is "YES".

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	n := 0
	scan(&n)
	a := []int{}
	for i, x := 0, 0; i < n; i++ {
		scan(&x)
		a = append(a, x)
	}
	for i := 0; i+2 < n; i += 2 {
		// printf("%d %d %d\n", a[i], a[i+2], math.Abs(float64(a[i+2]-a[i]))%2)
		if (a[i+2]-a[i])&1 == 1 {
			printf("NO\n")
			return
		}
	}
	for i := 1; i+2 < n; i += 2 {
		if (a[i+2]-a[i])&1 == 1 {
			printf("NO\n")
			return
		}
	}
	printf("YES\n")
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

func readNumbers(reader *bufio.Reader, n int) []int {
	line, _ := reader.ReadString('\n')

	s := strings.TrimSpace(line)
	// skip empty lines
	if len(s) == 0 {
		return readNumbers(reader, n)
	}
	r := make([]int, n, n)
	ir := bufio.NewReader(strings.NewReader(s))
	for i := 0; i < n; i++ {
		ss, _ := ir.ReadString(' ')
		r[i], _ = strconv.Atoi(strings.TrimSpace(ss))
	}
	return r
}

func sameCase(n1, n2 int) bool {
	return n1%2 == n2%2
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	cases := readNumbers(reader, 1)[0]
	for t := 0; t < cases; t++ {
		n := readNumbers(reader, 1)[0]
		ns := readNumbers(reader, n)
		if n <= 2 {
			fmt.Println("YES")
			continue
		}
		// skip first two, and n is size
		i := 2
		for ; i < n; i++ {
			if i%2 == 0 && sameCase(ns[0], ns[i]) || i%2 == 1 && sameCase(ns[1], ns[i]) {
				continue
			}
			break
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		recent_odd:=0
		recent_even:=0
		counter:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Scan(&x)
			if j%2 != 0 {
				if j == 1 {
					recent_odd= x
				} else {
					if even_check(recent_odd) != even_check(x) {
						counter++
					}
				}
			} else {
				if j == 0 {
					recent_even= x
				} else {
					if even_check(recent_even) != even_check(x) {
						counter++
					}
				}
			}
		}
		if counter == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func even_check(x int) bool {
	if x % 2 == 0 {
		return true
	}
	return false
}

package main

import (
	"fmt"
)

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

	for test := 0; test < t; test++ {
		var n, a, i int
		fmt.Scanln(&n)

		fmt.Scan(&a)
		odd := a % 2
		fmt.Scan(&a)
		even := a % 2

		flag := false
		for i = 2; i < n; i++ {
			fmt.Scan(&a)
			if flag {
				continue
			}

			if (i%2 == 0 && a%2 != odd) || (i%2 == 1 && a%2 != even) {
				fmt.Println("NO")
				flag = true
			}
		}

		if !flag {
			fmt.Println("YES")
		}

		fmt.Scanf("\n")
	}
}

package main

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

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

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

		even, odd := -1, -1
		ans := true

		for i := 0; i < n; i++ {
			var num int
			fmt.Fscan(in, &num)

			if i%2 == 0 {
				if even == -1 {
					even = num % 2
					continue
				}

				if even != num%2 {
					ans = false
				}
			} else {
				if odd == -1 {
					odd = num % 2
					continue
				}

				if odd != num%2 {
					ans = false
				}
			}
		}

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

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

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

func solve() {
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	ok1 := true
	for i := 2; i < n; i += 2 {
		ok1 = ok1 && ((a[i-2] & 1) == (a[i] & 1))
	}
	ok2 := true
	for i := 3; i < n; i += 2 {
		ok2 = ok2 && ((a[i-2] & 1) == (a[i] & 1))
	}

	if ok1 && ok2 {
		out("YES")
	} else {
		out("NO")
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

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

func solve() {
	n := nextInt()
	a := make([]int, n)

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

	ok1 := true
	for i := 2; i < n; i += 2 {
		ok1 = ok1 && (a[i]%2 == a[i-2]%2)
	}

	ok2 := true
	for i := 3; i < n; i += 2 {
		ok2 = ok2 && (a[i]%2 == a[i-2]%2)
	}
	if ok1 && ok2 {
		out("YES\n")
	} else {
		out("NO\n")
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		flag1, flag2 := true, true
		for i := 0; i+2 < n; i++ {
			if (arr[i] % 2) != (arr[i+2] % 2) {
				flag1 = false
				break
			}
		}
		for i := 1; i+2 < n; i++ {
			if (arr[i] % 2) != (arr[i+2] % 2) {
				flag2 = false
				break
			}
		}
		if flag1 && flag2 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t, n int
	fmt.Fscan(inp, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(inp, &n)
		a := make([]uint16, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(inp, &a[j])
		}
		if a[0]&1 != a[1]&1 {
			for j := 1; j < n; j += 2 {
				a[j]++
			}
		}
		for j := 0; j < n; j++ {
			a[j] &= 1
		}
		ans := "YES"
		for j := 1; j < n; j++ {
			if a[j] != a[j-1] {
				ans = "NO"
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		a1 := 1
		a2 := 1
		scanner.Scan()
		scanner.Scan()
		sl := strings.Split(scanner.Text(), " ")
		for j := 0; j < len(sl); j++ {
			temp, _ := strconv.Atoi(sl[j])
			if j%2 == 0 {
				if temp%2 == 0 {
					a1 *= 3
				} else {
					a1 *= 5
				}
			} else {
				if temp%2 == 0 {
					a2 *= 3
				} else {
					a2 *= 5
				}
			}
		}
		if a1%15 == 0 || a2%15 == 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

func pl(a ...interface{})                { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{})              { fmt.Fscan(in, a...) }

func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	c := a[0]%2 == 0
	for i := 2; i < n; i += 2 {
		if (a[i]%2 == 0) != c {
			pl("NO")
			return
		}
	}
	c = a[1]%2 == 0
	for i := 1; i < n; i += 2 {
		if (a[i]%2 == 0) != c {
			pl("NO")
			return
		}
	}
	pl("YES")
}

func main() {
	var T int
	scan(&T)
	for ; T > 0; T-- {
		solve()
	}
}

func ys(b bool) string { return map[bool]string{true: "YES", false: "NO"}[b] }

package main

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

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

func check(a []int) bool {
	for i := 2; i < len(a); i++ {
		if a[i-2]%2 != a[i]%2 {
			return false
		}
	}
	return true
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		if check(a) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	str, _ := reader.ReadString('\n')
	t, _ := strconv.ParseInt(strings.TrimSpace(str), 10, 32)
	tt := int(t)
	for i := 0; i < tt; i++ {
		solve(reader)
	}
}

func solve(reader *bufio.Reader) {
	n := ReadInteger(reader, '\n')
	if n == 1 {
		n = ReadInteger(reader, '\n')
		fmt.Println("YES")
		return
	}

	var fir, sec int
	var c bool = true
	for i := 0; i < n; i++ {
		var cur int
		if i == n-1 {
			cur = ReadInteger(reader, '\n')
		} else {
			cur = ReadInteger(reader, ' ')
		}
		if i == 0 {
			fir = cur
		} else if i == 1 {
			sec = cur
		}
		if i%2 == 0 && cur%2 != fir%2 {
			c = false
		}
		if i%2 == 1 && cur%2 != sec%2 {
			c = false
		}
	}

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

}

func ReadInteger(reader *bufio.Reader, lst byte) int {
	str, _ := reader.ReadString(lst)
	n, _ := strconv.ParseInt(strings.TrimSpace(str), 10, 32)
	return int(n)
}

package main

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

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

	var T, n int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0;i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		flag := true
		for i := 3;i < n; i += 2 {
			if (a[i] + a[i - 2]) % 2 == 1 {
				flag = false
			}
		}
		for i := 2;i < n; i += 2 {
			if (a[i] + a[i - 2]) % 2 == 1 {
				flag = false
			}
		}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	T:=nextInt()
	for Case:=1;Case<=T;Case++{
		solve()
	}
}

func solve() {
	res:=true
	n:=nextInt()
	a:= make([]int,n,n)
	for i:=0;i<n;i++{
		a[i]=nextInt()
	}

	for i:=2;i<n;i+=2{
		if(a[i]&1!=a[i-2]&1){
			res=false
			break
		}
	}

	for i:=3;i<n;i+=2{
		if(a[i]&1!=a[i-2]&1){
			res=false
			break
		}
	}
	if res{
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}

package main

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

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

func main(){
    defer writer.Flush()

    var numTests int
    fmt.Fscan(reader,&numTests)

    for t := 1; t <= numTests; t++ {
        var n int
        fmt.Fscan(reader,&n)

        arr := make([]int,n + 1)

        for i := 1; i <= n; i++ {
            fmt.Fscan(reader,&arr[i])
        }

        var f = true
        for i := 1; i <= n; i++ {
            if i % 2 == 0 {
                if arr[i] % 2 != arr[2] % 2 {
                    f = false
                }
            } else {
                if arr[i] % 2 != arr[1] % 2 {
                    f = false
                }
            }
        }

        if f == true {
            fmt.Fprintf(writer,"%s\n","YES")
        } else {
            fmt.Fprintf(writer,"%s\n","NO")
        }
    }
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1669C
Date: 24/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1669/C
Problem: CF1669C
**/
func (in *CF1669C) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		oddodd := false
		oddeven := false

		eveneven := false
		evenodd := false
		ans := true
		for i := 0; i < n; i++ {
			val := in.NextInt()
			if i%2 == 0 {
				if val%2 == 0 {
					oddodd = true
				} else {
					oddeven = true
				}
			} else {
				if val%2 == 0 {
					evenodd = true
				} else {
					eveneven = true
				}
			}
		}

		if oddeven && oddodd {
			ans = false
		}
		if eveneven && evenodd {
			ans = false
		}
		if ans{
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
	}

}

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

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

// @Title
// @Description
// @Author
// @Update
package main

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

func main() {
        var t int
        fmt.Scan(&t)
        in := bufio.NewReader(os.Stdin)
        for l := 1; l <= t; l++ {
                n := 1
                fmt.Fscan(in, &n)
                arr := make([]int, n)
                for i := 0; i < n; i++ {
                        fmt.Fscan(in, &arr[i])
                }
                flag := true
                for i := 3; i < n; i += 2 {
                        flag = flag && ((arr[i]+arr[i-2])%2 == 0)
                }
                for i := 2; i < n; i += 2 {
                        flag = flag && ((arr[i]+arr[i-2])%2 == 0)
                }
                if flag {
                        fmt.Println("YES")
                }
                if !flag {
                        fmt.Println("NO")
                }
        }

}

package main
import ("fmt"
    "bufio"
    "os")

func solve(reader *bufio.Reader) {
    var n int
    fmt.Fscan(reader, &n)
    a := make([]int, n)
    //fmt.Println(n)
    for  i := 0; i < n; i++ {
        fmt.Fscan(reader, &a[i])
        a[i] %= 2
    }
    var odd, even int = a[0], a[1]
    for i := 0; i < n; i += 2 {
        if a[i] != odd {
            fmt.Println("NO")
            return
        }
    }
    for i := 1; i < n; i += 2 {
        if a[i] != even {
            fmt.Println("NO")
            return
        }
    }
    fmt.Println("YES")
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    var tc int
    fmt.Scan(&tc)
    for i := 0; i < tc; i++ {
        solve(reader)
    }
    return;
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	a := cin.NextInts(n)
	for i := 0; i + 2 < n; i++ {
		if a[i + 2] % 2 != a[i] % 2 {
			cout.Println("nO")
			return
		}
	}
	cout.Println("YeS")
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

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

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

func main(){
	//var v []int = make([] int, 200000)
	var t int
	var i int
	Reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(Reader, &t)
	for ;t>0; t--{
		var n int
		fmt.Fscan(Reader, &n)
		arr := make([]int, n)
		od := false
		ev := false
		for i =0;i<n;i++{
			fmt.Fscan(Reader, &arr[i])
		}
		for i=0;i<n;i+=2{
			if arr[i] % 2 == 0{
				ev = true
			}else{
				od = true
			}
		}
		//fmt.Println(ev, od)
		if ev && od{
			fmt.Println("NO")
			continue
		}
		od = false
		ev = false
		for i =1;i<n;i+=2{
			if arr[i] % 2 ==0{
				ev = true
			}else{
				od = true
			}
		}
		if ev && od{
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var T int
	var N int
	var A [2]int
	var x int
	fmt.Fscan(in, &T)
	for i := 0; i < T; i++ {
		fmt.Fscan(in, &N)
		var no bool
		fmt.Fscan(in, &A[0])
		fmt.Fscan(in, &A[1])
		for ii := 2; ii < N; ii++ {
			fmt.Fscan(in, &x)
			if !no {
				no = ((ii%2) == 0 && (A[0]%2) != (x%2)) || ((ii%2) == 1 && (A[1]%2) != (x%2))
			}
		}
		if no {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,N,a,even,odd int

	fmt.Fscan(in, &T)

	for i := 0;i < T;i++{
		anc := "YES"
		fmt.Fscan(in, &N)
		for j := 0;j < N;j++{
			fmt.Fscan(in, &a)
			if j%2 == 0{
				if j == 0{
					even = a%2
				}else{
					if even != a%2{
						anc = "NO"
					}
				}
			}else{
				if j == 1{
					odd = a%2
				}else{
					if odd != a%2{
						anc = "NO"
					}
				}
			}
		}
		fmt.Println(anc)
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan() // toss num of test cases

	for scanner.Scan() {
		scanner.Scan() // toss array length

		line := scanner.Text()

		fields := strings.Fields(line)

		values := []int{}

		for _, f := range fields {
			v, err := strconv.Atoi(f)
			if err != nil {
				panic(err)
			}

			values = append(values, v)
		}

		fmt.Println(f(values))
	}
}

func f(values []int) string {
	parity := make(map[int]int)
	ret := "yes"

	for i, v := range values {
		p, found := parity[i%2]
		if !found {
			parity[i%2] = v % 2
			continue
		}

		if p != v%2 {
			ret = "no"
			break
		}
	}

	return ret
}

package main

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

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

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

	var T int
	var x int
	var n int

loop:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

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

		for i := 0; i < len(r); i += 2 {
			if r[i]%2 != r[0]%2 {
				Fprintln(out, "NO")
				continue loop
			}
		}
		for i := 1; i < len(r); i += 2 {
			if r[i]%2 != r[1]%2 {
				Fprintln(out, "NO")
				continue loop
			}
		}

		Fprintln(out, "YES")
	}
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	for k := 0; k < t; k++ {
		n := 0
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		cnt1 := [2]int{}
		cnt2 := [2]int{}
		for i := 1; i <= n; i++ {
			if i%2 == 1 {
				cnt1[a[i-1]%2]++
			} else {
				cnt2[a[i-1]%2]++
			}
		}
		if (cnt1[0] != 0 && cnt1[1] != 0) || (cnt2[0] != 0 && cnt2[1] != 0) {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	// var a, f int
	var a []int
	// var freq map[int]int
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		a = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j])
		}

		f := true
		lastPart := a[1] % 2
		for j := 1; j < n; j += 2 {
			if a[j]%2 != lastPart {
				f = false
			}
		}

		lastPart = a[0] % 2
		for j := 0; j < n; j += 2 {
			if a[j]%2 != lastPart {
				f = false
			}
		}

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

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		var arr []int64
		for j := 0; j < x; j++ {
			var value int64
			fmt.Scan(&value)
			arr = append(arr, value)
		}
		var check bool = false
		for j := 0; j < x; j++ {
			if j%2 == 0 {
				if arr[0]%2 == 0 && arr[j]%2 == 0 {
				} else if arr[0]%2 != 0 && arr[j]%2 != 0 {
				} else {
					check = true
				}
			} else {
				if arr[1]%2 == 0 && arr[j]%2 == 0 {
				} else if arr[1]%2 != 0 && arr[j]%2 != 0 {
				} else {
					check = true
				}
			}
		}
		if check {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

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

func solve() {
	var n, num int
	scanf("%d\n", &n)

	ans := true
	arr := make([]int, n)

	for i := 0; i < n; i++ {
		scanf("%d ", &num)
		arr[i] = num
	}

	scanf("\n")

	flag := 0
	for i := 0; i < n; i += 2 {
		if arr[i]%2 == 0 {
			if flag == 2 {
				ans = false
				break
			} else {
				flag = 1
			}
		} else if arr[i]%2 != 0 {
			if flag == 1 {
				ans = false
				break
			} else {
				flag = 2
			}
		}
	}

	if !ans {
		printf("NO\n")
	} else {
		flag = 0
		ans = true
		for i := 1; i < n; i += 2 {
			if arr[i]%2 == 0 {
				if flag == 2 {
					ans = false
					break
				} else {
					flag = 1
				}
			} else if arr[i]%2 != 0 {
				if flag == 1 {
					ans = false
					break
				} else {
					flag = 2
				}
			}
		}

		if ans {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

func main() {
	defer writer.Flush()
	var cases int

	scanf("%d\n", &cases)
	// cases = 1

	for c := 0; c < cases; c++ {
		solve()
	}
}

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

func IntArray(size int) []int {
	arr := make([]int, size)
	for i := 0; i < size; i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}

func Max(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] > m {
			m = args[i]
		}
	}
	return m
}

func Min(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] < m {
			m = args[i]
		}
	}
	return m
}

package main

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

/*

 */

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

	a := make([]int, n)

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

	for i := 0; i < n; i += 2 {
		if a[i]%2 != a[0]%2 {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	for i := 1; i < n; i += 2 {
		if a[i]%2 != a[1]%2 {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

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

	return factors
}

package main

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

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

func Scan(a ...interface{}) { fmt.Fscan(in, a...) }
func Scanln(s *string) {
	for *s, _ = in.ReadString('\n'); *s == "\n"; {
		*s, _ = in.ReadString('\n')
	}
	*s = (*s)[:len(*s)-1]
}
func Print(a ...interface{})                 { fmt.Fprint(out, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func Log(a ...interface{}) {
	pc, _, line, _ := runtime.Caller(1)
	fmt.Fprint(out, "log ", runtime.FuncForPC(pc).Name(), ":", line, " ")
	fmt.Fprint(out, a...)
	fmt.Fprint(out, "\n")
}

const N = 1e2 + 10

func solve() bool {
	var (
		n int
		a [N]int
	)
	Scan(&n)
	for i := 1; i <= n; i++ {
		Scan(&a[i])
	}

	for i := 3; i <= n; i += 2 {
		if a[i]%2 != a[i-2]%2 {
			return false
		}
	}
	for i := 4; i <= n; i += 2 {
		if a[i]%2 != a[i-2]%2 {
			return false
		}
	}
	return true
}

func main() {
	defer out.Flush()

	T := 1
	Scan(&T)
	for test := 0; test < T; test++ {
		if solve() {
			Print("YES\n")
		} else {
			Print("NO\n")
		}
	}
}

package main

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

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

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

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

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

		f := true
		for i := 2; i < n; i++ {
			if m[i-2]%2 != m[i]%2 {
				f = false
				break
			}
		}

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

package main

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

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

func slove() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	for i:=0;i<n;i++ {
		if nums[i]%2 != nums[i%2]%2 {
			fmt.Fprintln(w, "No")
			return
		}
	}
	fmt.Fprintln(w, "Yes")
}

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

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

package main

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

const MOD int64 = 1000000007

var n int

var a []int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {
	even := true
	par := a[0] % 2

	for i := 2; i < n; i+=2 {
		if a[i] % 2 != par {
			even = false
			break
		}
	}
	if !even {
		fmt.Println("NO")
		return
	}

	odd := true
	par = a[1] % 2

	for i := 3; i < n; i+=2 {
		if a[i] % 2 != par {
			odd = false
			break
		}
	}

	if !odd {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
}

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

package main

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

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

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		can := true
		for i := 3; i < n; i += 2 {
			if nums[i]&1 != (nums[i-2] & 1) {
				can = false
				break
			}
		}
		for i := 0; i+2 < n; i += 2 {
			if nums[i]&1 != (nums[i+2] & 1) {
				can = false
				break
			}
		}
		if can {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

package main

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

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

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i, v := range a {
			if v%2 != a[i&1]%2 {
				Fprintln(out, "NO")
				return
			}
		}
		Fprintln(out, "YES")
	}

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

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

}

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

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	n := 0
	scan(&n)
	a := []int{}
	for i, x := 0, 0; i < n; i++ {
		scan(&x)
		a = append(a, x)
	}
	for i := 0; i+2 < n; i += 2 {
		// printf("%d %d %d\n", a[i], a[i+2], math.Abs(float64(a[i+2]-a[i]))%2)
		if (a[i+2]-a[i]) & 1 == 1 {
			printf("NO\n")
			return
		}
	}
	for i := 1; i+2 < n; i += 2 {
		if (a[i+2]-a[i])%2 == 1 {
			printf("NO\n")
			return
		}
	}
	printf("YES\n")
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	n := 0
	scan(&n)
	a := []int{}
	for i, x := 0, 0; i < n; i++ {
		scan(&x)
		a = append(a, x)
	}
	for i := 0; i+2 < n; i += 2 {
		if (a[i+2]-a[i])%2 == 1 {
			printf("NO\n")
			return
		}
	}
	for i := 1; i+2 < n; i += 2 {
		if (a[i+2]-a[i])%2 == 1 {
			printf("NO\n")
			return
		}
	}
	printf("YES\n")
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	for {
		line, err := reader.ReadString('\n')
		if err != nil {
			break
		}
		fmt.Printf("%s", line)
	}
}

package main

import (
	"fmt"
)

func readInt(delim byte) int {
	var i int
	// format := fmt.Sprintf("%%d%b", delim)
	fmt.Scanf("%d", &i)
	return i
}

func sameCase(n1, n2 int) bool {
	return n1%2 == n2%2
}

func main() {
	cases := readInt('\n')
	for t := 0; t < cases; t++ {
		n := readInt('\n')
		if n <= 2 {
			_, _ = fmt.Scanf("%s\n")
			fmt.Println("YES")
			continue
		}
		n0 := readInt(' ')
		n1 := readInt(' ')

		// skip first two, and n is size
		matching := true
		for i := 2; i < n; i++ {
			ni := readInt(' ')
			if i%2 == 0 && sameCase(n0, ni) || i%2 == 1 && sameCase(n1, ni) {
				continue
			}
			matching = false
			break
		}
		if matching {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		recent_odd:=0
		recent_even:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if j%2 != 0 { // odd indices
				if j == 1 {
					recent_odd= x // first
				} else {
					if even_check(recent_odd) != even_check(x) {
						fmt.Fprintln(out,"NO")
						goto out
					}
				}
			} else { // even indices
				if j == 0 {
					recent_even= x // first
				} else {
					if even_check(recent_even) != even_check(x) {
						fmt.Fprintln(out,"NO")
						goto out
					}
				}
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

func even_check(x int) bool {
	if x % 2 == 0 {
		return true
	}
	return false
}

package main

import (
	"fmt"
)

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

	for test := 0; test < t; test++ {
		var n, a, i int
		fmt.Scanln(&n)

		fmt.Scan(&a)
		odd := a % 2
		fmt.Scan(&a)
		even := a % 2

		for i = 2; i < n; i++ {
			fmt.Scan(&a)
			if (i%2 == 0 && a%2 != odd) || (i%2 == 1 && a%2 != even) {
				fmt.Println("NO")
				break
			}
		}

		if i == n {
			fmt.Println("YES")
		}

		fmt.Scanf("\n")
	}
}

package main

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

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

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

		even, odd := -1, -1
		ans := true

		for i := 0; i < n; i++ {
			var num int
			fmt.Fscan(in, &num)

			if i%2 == 0 {
				if even == -1 {
					even = num % 2
					continue
				}

				if even != num%2 {
					ans = false
					break
				}
			} else {
				if odd == -1 {
					odd = num % 2
					continue
				}

				if odd != num%2 {
					ans = false
					break
				}
			}
		}

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

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		flag1, flag2 := true, true
		for i := 0; i+2 < n; i++ {
			if (arr[i] % 2) != (arr[i+2] % 2) {
				flag1 = false
				break
			}
		}
		for i := 1; i+2 < n; i++ {
			if (arr[i] % 2) != (arr[i+2] % 2) {
				flag2 = false
				break
			}
		}
		if flag1 || flag2 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t, n int
	fmt.Fscan(inp, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(inp, &n)
		a := make([]uint16, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(inp, &a[j])
		}
		if a[0] != a[1] {
			for j := 1; j < n; j += 2 {
				a[j]++
			}
		}
		for j := 0; j < n; j++ {
			a[j] &= 1
		}
		ans := "YES"
		for j := 1; j < n; j++ {
			if a[j] != a[j-1] {
				ans = "NO"
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}


Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.   Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where  f1 = 1,  f2 = 1,  fn = fn - 2 + fn - 1 (n > 2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.

The first and only line of input contains an integer n (1 ≤ n ≤ 1000).

Print Eleven's new name on the first and only line of output.

package main

import (
	"fmt"
)

func main() {
	n := 0
	fmt.Scan(&n)
	arr := make([]int, 1e5)
	fn_2 := 1
	fn_1 := 1

	arr[1] = 1
	for fn_2 <= 1000 {
		temp := fn_2

		fn_2 += fn_1
		fn_1 = temp
		arr[fn_2] = 1
	}
	ans := ""
	for i := 1; i<=n; i++ {
		if arr[i] == 1 {
			ans += "O"
		}else {
			ans += "o"
		}
	}
	fmt.Println(ans)
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()
	a, b := 1, 1
	for i := 1; i < n+1; i += 1 {
		for i > b {
			a, b = b, a+b
		}
		if b == i {
			fmt.Print("O")
		} else {
			fmt.Print("o")
		}

	}

}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	fib := make(map[int]bool)
	a, b := 1, 1
	for b <= 1000 {
		fib[b] = true
		a, b = b, a+b
	}
	for i := 1; i <= n; i++ {
		if fib[i] {
			fmt.Print("O")
		} else {
			fmt.Print("o")
		}
	}
}

package main

import "fmt"

var (
	scan  = fmt.Scan
	print = fmt.Println
)

func main() {

	fib := map[int]int{}

	var n int
	scan(&n)

	var fib_1 = 0
	var fib_2 = 1

	var fib_n = fib_1 + fib_2

	for fib_n <= n {
		fib[fib_n] = 1
		fib_1 = fib_2
		fib_2 = fib_n
		fib_n = fib_1 + fib_2
	}

	for i := 1; i <= n; i++ {
		if fib[i] == 1 {
			fmt.Print("O")
		} else {
			fmt.Print("o")
		}
	}
}

package main

/*
int fib[1002];
mkfib(int max) {
  int a,b;
  for(a=b=1;a<=max;b=a+b,a=b-a)
    fib[a] = 1;
}
*/
import "C"

import (
  "fmt"
  "strings"
)

func main() {
  var n int
  buf := []string{}
  fmt.Scanf("%d", &n)
  C.mkfib(C.int(n))
  for i:=1;i<=n;i++ {
    var x string
    if C.fib[i]!=0 {
      x = "O"
    } else {
      x = "o"
    }
    buf = append(buf, x)
  }
  fmt.Println(strings.Join(buf,""))
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	//fmt.Println("Hello, world!")

	n := gsli(reader)[0]

	curFib := 1
	fib := 1

	if n == 1 {
		fmt.Println("O")
	} else if n == 2 {
		fmt.Println("OO")
	} else {
		for i := 1; i <= n; i++ {
			if i == curFib {
				fmt.Printf("O")
				temp := curFib
				curFib += fib
				fib = temp
			} else {
				fmt.Printf("o")
			}
		}
	}

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

package main

import "fmt"

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	var n int
	fmt.Scan(&n)
	var a, b = 1, 1
	var fib = make(map[int]bool)
	fib[1] = true
	for {
		var c = a + b
		fib[c] = true
		a = b
		b = c
		if c > 1000 {
			break
		}
	}
	// fmt.Println(fib)
	for i := 1; i <= n; i++ {
		if ok := fib[i]; ok {
			fmt.Print("O")
		} else {
			fmt.Print("o")
		}
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    f1, f2, f3 := 0, 1, 1
    for i:=1; i<=n; i++ {
        if i == f3 {
            f1 = f2
            f2 = f3
            f3 = f1+f2
            fmt.Print("O")
        } else {
            fmt.Print("o")
        }
    }
}

package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scanln(&n)
    var fib [20]int
    fib[0] = 1
    fib[1] = 2
    for i:=2 ; i<=15 ; i++ {
        fib[i]=fib[i-1]+fib[i-2]
    }
    temp := 0
    for i:=1 ; i<=n ; i++ {
        if i==fib[temp] {
            fmt.Printf("%s","O")
            temp++
        } else {
            fmt.Printf("%s","o")
        }
    }
}

package main

import "fmt"

const (
	MaxN = 1000
)

var (
	fib [MaxN + 1]int
	n   int
)

func main() {
	fmt.Scanf("%d", &n)
	// fib = make([]int, MaxN+11)
	output := make([]byte, n)

	if n >= 1 {
		output[0] = 'O'
	}

	if n >= 2 {
		output[1] = 'O'
	}

	for i := 2; i < n; i++ {
		output[i] = 'o'
	}

	fib[1] = 1
	fib[2] = 1

	// fmt.Println(output)

	// fmt.Println(fib[1], fib[2])

	for i := 3; i <= MaxN && fib[i-1] <= n; i++ {
		fib[i] = fib[i-1] + fib[i-2]
		// fmt.Println(i, fib[i], fib[i-1], fib[i-2])
		if fib[i] <= n {
			output[fib[i]-1] = 'O'
		}
	}

	fmt.Println(string(output))
}

package main

import "fmt"

func main() {
	var n int = 1000
	fib := make(map[int]bool)
	a, b := 1, 1
	for b <= 1000 {
		fib[b] = true
		a, b = b, a+b
	}
	for i := 1; i <= n; i++ {
		if fib[i] {
			fmt.Print("O")
		} else {
			fmt.Print("o")
		}
	}
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	//fmt.Println("Hello, world!")

	n := gsli(reader)[0]

	curFib := 2
	fib := 1

	if n == 1 {
		fmt.Println("O")
	} else if n == 2 {
		fmt.Println("OO")
	} else {
		fmt.Printf("OO")
		for i := 1; i <= n; i++ {
			if i == curFib {
				fmt.Printf("O")
				temp := curFib
				curFib += fib
				fib = temp
			} else {
				fmt.Printf("o")
			}
		}
	}

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(n)
    f1, f2, f3 := 0, 1, 1
    for i:=1; i<=n; i++ {
        if i == f3 {
            f1 = f2
            f2 = f3
            f3 = f1+f2
            fmt.Print("O")
        } else {
            fmt.Print("o")
        }
    }
    fmt.Print("\n")
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(n)
    f1, f2, f3 := 0, 1, 1
    for i:=1; i<=n; i++ {
        if i == f3 {
            f1 = f2
            f2 = f3
            f3 = f1+f2
            fmt.Print("O")
        } else {
            fmt.Print("o")
        }
    }
}


You are given an array $$$a$$$ of $$$n$$$ positive integers.You can use the following operation as many times as you like: select any integer $$$1 \le k \le n$$$ and do one of two things:   decrement by one $$$k$$$ of the first elements of the array.  decrement by one $$$k$$$ of the last elements of the array. For example, if $$$n=5$$$ and $$$a=[3,2,2,1,4]$$$, then you can apply one of the following operations to it (not all possible options are listed below):   decrement from the first two elements of the array. After this operation $$$a=[2, 1, 2, 1, 4]$$$;  decrement from the last three elements of the array. After this operation $$$a=[3, 2, 1, 0, 3]$$$;  decrement from the first five elements of the array. After this operation $$$a=[2, 1, 1, 0, 3]$$$; Determine if it is possible to make all the elements of the array equal to zero by applying a certain number of operations.

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 30000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$1 \le n \le 30000$$$) — the number of elements in the array. The second line of each test case contains $$$n$$$ integers $$$a_1 \ldots a_n$$$ ($$$1 \le a_i \le 10^6$$$). The sum of $$$n$$$ over all test cases does not exceed $$$30000$$$.

For each test case, output on a separate line:    YES, if it is possible to make all elements of the array equal to zero by applying a certain number of operations.  NO, otherwise.  The letters in the words YES and NO can be outputed in any case.

package main

//import "fmt"

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

func ArrayStringToInt(a []string) []int {
	var r []int
	for i := 0; i < len(a); i++ {
		num, _ := strconv.Atoi(a[i])
		r = append(r, num)
	}
	return r
}

func res(a []int) {
	d := 0
	for i := 1; i < len(a); i++ {
		if a[i] < d {
			fmt.Println("NO")
			return
		}

		if a[i] > a[i-1] {
			d += a[i] - a[i-1]
		}
	}

	fmt.Println("YES")
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	trie, _ := strconv.Atoi(sc.Text())
	for trie > 0 {
		sc.Scan()
		sc.Text()
		sc.Scan()
		input := ArrayStringToInt(strings.Fields(sc.Text()))
		res(input)
		trie--
	}

}

package main

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

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

	var T, n, v, p int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &p)
		s := p
		for n--; n > 0; n-- {
			Fscan(in, &v)
			if v < p {
				s -= p - v
			}
			p = v
		}
		if s < 0 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

/*
URL:
https://codeforces.com/contest/1443/problem/D
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

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

		solve()
	}
}

func solve() {
	befB := 0
	for i := 1; i < n; i++ {
		diff := max(0, A[i]-A[i-1])
		chmax(&diff, befB)

		nextA := A[i] - diff
		if nextA < 0 {
			printf("NO\n")
			return
		}
		A[i] = nextA
		befB = diff
	}

	printf("YES\n")
}

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

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

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

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

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

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

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

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

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, a, desc, asc int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		desc = 2000000
		asc = 0
		result := true
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a)
			if a < asc {
				result = false
			}
			if result {
				if a-desc < asc {
					desc = a - asc
				} else {
					asc = a - desc
				}
			}
		}
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

//import "fmt"

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

func ArrayStringToInt(a []string) []int {
	var r []int
	for i := 0; i < len(a); i++ {
		num, _ := strconv.Atoi(a[i])
		r = append(r, num)
	}
	return r
}

func res(a []int) {
	right_index := 0
	right := a[right_index]
	for i := 1; i < len(a); i++ {
		if a[i] <= right {
			right_index = i
			right = a[right_index]
		} else {
			break
		}
	}
	left_index := len(a) - 1
	left := a[left_index]
	for i := left_index - 1; i > right_index; i-- {
		if a[i] <= left {
			left_index = i
			left = a[left_index]
		} else {
			break
		}
	}
	diff := left_index - right_index
	if diff == 1 || diff == 0 {
		fmt.Println("YES")
		return
	} else if diff == 2 {
		if a[left_index-1] <= a[left_index]+a[right_index] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	} else {
		fmt.Println("NO")
	}
}

func main() {

	//a := []int{1, 2, 6}
	//1 2 1
	//11 7 9 6 8
	//1 3 1 3 1
	//4
	//5 2 1 10
	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	trie, _ := strconv.Atoi(sc.Text())
	for trie > 0 {
		sc.Scan()
		sc.Text()
		sc.Scan()
		input := ArrayStringToInt(strings.Fields(sc.Text()))
		res(input)
		trie--
	}

}

/*
URL:
https://codeforces.com/contest/1443/problem/D
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

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

		solve()
	}
}

func solve() {
	if n <= 2 {
		printf("YES\n")
		return
	}

	R := make([]int, n)
	R[n-1] = A[n-1]
	mini := A[n-1]
	for i := n - 2; i >= 0; i-- {
		chmin(&mini, A[i])
		R[i] = mini
	}

	mini = A[0]
	flag := true
	for i := 1; i < n; i++ {
		chmin(&mini, A[i])
		diff := max(0, A[i]-R[i])
		if mini-diff < 0 {
			flag = false
			break
		}
	}
	if flag {
		printf("YES\n")
		return
	}

	L := make([]int, n)
	L[0] = A[0]
	mini = A[0]
	for i := 1; i < n; i++ {
		chmin(&mini, A[i])
		L[i] = mini
	}

	mini = A[n-1]
	flag = true
	for i := n - 2; i >= 0; i-- {
		chmin(&mini, A[i])
		diff := max(0, A[i]-R[i])
		if mini-diff < 0 {
			flag = false
			break
		}
	}
	if flag {
		printf("YES\n")
		return
	}

	printf("NO\n")
}

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

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

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

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

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

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

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

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

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

/*
URL:
https://codeforces.com/contest/1443/problem/D
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

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

		solve()
	}
}

func solve() {
	if n <= 2 {
		printf("YES\n")
		return
	}

	R := make([]int, n)
	R[n-1] = A[n-1]
	mini := A[n-1]
	for i := n - 2; i >= 0; i-- {
		chmin(&mini, A[i])
		R[i] = mini
	}
	ds := 0
	flag := true
	for i := n - 1; i >= 0; i-- {
		delta := max(0, A[i]-R[i])
		ds += delta
		if A[i]-ds < 0 {
			flag = false
			break
		}
	}
	if flag {
		printf("YES\n")
		return
	}

	// mini = A[0]
	// flag := true
	// for i := 1; i < n; i++ {
	// 	chmin(&mini, A[i])
	// 	diff := max(0, A[i]-R[i])
	// 	if mini-diff < 0 {
	// 		flag = false
	// 		break
	// 	}
	// }
	// if flag {
	// 	printf("YES\n")
	// 	return
	// }

	L := make([]int, n)
	L[0] = A[0]
	mini = A[0]
	for i := 1; i < n; i++ {
		chmin(&mini, A[i])
		L[i] = mini
	}
	ds = 0
	flag = true
	for i := 0; i < n; i++ {
		delta := max(0, A[i]-L[i])
		ds += delta
		if A[i]-ds < 0 {
			flag = false
			break
		}
	}
	if flag {
		printf("YES\n")
		return
	}

	// mini = A[n-1]
	// flag = true
	// for i := n - 2; i >= 0; i-- {
	// 	chmin(&mini, A[i])
	// 	diff := max(0, A[i]-R[i])
	// 	if mini-diff < 0 {
	// 		flag = false
	// 		break
	// 	}
	// }
	// if flag {
	// 	printf("YES\n")
	// 	return
	// }

	printf("NO\n")
}

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

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

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

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

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

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

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

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

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

/*
URL:
https://codeforces.com/contest/1443/problem/D
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

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

		solve()
	}
}

func solve() {
	if n <= 2 {
		printf("YES\n")
		return
	}

	R := make([]int, n)
	R[n-1] = A[n-1]
	mini := A[n-1]
	for i := n - 2; i >= 0; i-- {
		chmin(&mini, A[i])
		R[i] = mini
	}
	ds := 0
	flag := true
	for i := n - 2; i >= 0; i-- {
		delta := max(0, A[i]-R[i+1])
		ds += delta
		if A[i]-ds < 0 {
			flag = false
			break
		}
	}
	if flag {
		printf("YES\n")
		return
	}

	L := make([]int, n)
	L[0] = A[0]
	mini = A[0]
	for i := 1; i < n; i++ {
		chmin(&mini, A[i])
		L[i] = mini
	}
	ds = 0
	flag = true
	for i := 1; i < n; i++ {
		delta := max(0, A[i]-L[i-1])
		ds += delta
		if A[i]-ds < 0 {
			flag = false
			break
		}
	}
	if flag {
		printf("YES\n")
		return
	}

	printf("NO\n")
}

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

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

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

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

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

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

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

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

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

/*
URL:
https://codeforces.com/contest/1443/problem/D
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

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

		solve()
	}
}

func solve() {
	if n <= 2 {
		printf("YES\n")
		return
	}

	R := make([]int, n)
	R[n-1] = A[n-1]
	mini := A[n-1]
	for i := n - 2; i >= 0; i-- {
		chmin(&mini, A[i])
		R[i] = mini
	}

	mini = A[0]
	for i := 1; i < n; i++ {
		chmin(&mini, A[i])
		diff := max(0, A[i]-R[i])
		if mini-diff < 0 {
			printf("NO\n")
			return
		}
	}

	printf("YES\n")
}

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

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

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

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

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

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

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

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

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}