You are given an array $$$a$$$ of $$$n$$$ integers. You are asked to find out if the inequality $$$$$$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{j}) \geq a_i + a_{i + 1} + \dots + a_{j - 1} + a_{j}$$$$$$ holds for all pairs of indices $$$(i, j)$$$, where $$$1 \leq i \leq j \leq n$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$)  — the size of the array. The next line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, on a new line output "YES" if the condition is satisfied for the given array, and "NO" otherwise. You can print each letter in any case (upper or lower).

NoteIn test cases $$$1$$$ and $$$2$$$, the given condition is satisfied for all $$$(i, j)$$$ pairs. In test case $$$3$$$, the condition isn't satisfied for the pair $$$(1, 2)$$$ as $$$\max(2, 3) < 2 + 3$$$.

package main

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

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

func main() {
	defer _w.Flush()
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	suf := make([]int64, n)
	suf[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		suf[i] = suf[i+1] + a[i]
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	st = make([]int, 0)
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1] - 1
		}
		st = append(st, i)
	}
	sgr := make(seg, (n+1)<<2)
	sgr.init(1, 0, n-1, pre)
	sgl := make(seg, (n+1)<<2)
	sgl.init(1, 0, n-1, suf)
	for i := range a {
		lmx := sgl.que(1, 0, n-1, l[i], i-1).Mx - suf[i]
		rmx := sgr.que(1, 0, n-1, i+1, r[i]).Mx - pre[i]
		if max(lmx, rmx) > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mx = v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

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

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

func (FastRead *FastIO) ReadInt() (x int) {
	rc := FastRead.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == 0 { //EOF
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

var FastRead *FastIO

func check(a []int) bool {
	n := len(a)
	ps := make([]int64, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (int64)(a[i])

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1
		}
		if minl < mins {
			return false
		}
		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := FastRead.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = FastRead.ReadInt()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	//debug.SetGCPercent(-1)
	FastRead = &FastIO{
		os.Stdin,
		bufio.NewWriter(os.Stdout),
		0, 0, make([]byte, 1<<12),
	}

	var t = 1
	t = FastRead.ReadInt()
	for ; t > 0; t-- {
		if sol() {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func (FastRead *FastIO) ReadInt() (x int) {
	rc := FastRead.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == 0 { //EOF
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

var FastRead *FastIO

func check(a []int) bool {
	n := len(a)
	ps := make([]int64, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (int64)(a[i])

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1
		}
		if minl < mins {
			return false
		}
		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := FastRead.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = FastRead.ReadInt()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	debug.SetGCPercent(-1)
	FastRead = &FastIO{
		os.Stdin,
		bufio.NewWriter(os.Stdout),
		0, 0, make([]byte, 1<<12),
	}

	var t = 1
	t = FastRead.ReadInt()
	for ; t > 0; t-- {
		if sol() {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

const eof = 0

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

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

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

var FastRead *FastIO

func check(a []int) bool {
	n := len(a)
	ps := make([]int64, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (int64)(a[i])

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1
		}
		if minl < mins {
			return false
		}
		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := FastRead.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = FastRead.ReadInt()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	debug.SetGCPercent(-1)
	FastRead = &FastIO{
		os.Stdin,
		bufio.NewWriter(os.Stdout),
		0, 0, make([]byte, 1<<12),
	}

	var t = 1
	t = FastRead.ReadInt()
	for ; t > 0; t-- {
		if sol() {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

const eof = 0

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

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

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

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

var FastRead *FastIO

func check(a []int) bool {
	n := len(a)
	ps := make([]int64, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (int64)(a[i])

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1
		}
		if minl < mins {
			return false
		}
		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := FastRead.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = FastRead.ReadInt()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	FastRead = NewIO(in, out)

	var t = 1
	t = FastRead.ReadInt()
	for ; t > 0; t-- {
		if sol() {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

/* begin of FastIO */
const eof = 0

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

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

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

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

var FastRead *FastIO

func ri() int {
	return FastRead.ReadInt()
}

/* End of FastIO */

func check(a []int) bool {
	n := len(a)
	ps := make([]int64, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (int64)(a[i])

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1 // [minl, i) 区间 小于a[i]
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1 // ps[i]-ps[mins+1]>0
		}

		if minl < mins {
			return false
		}

		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := ri()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ri()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	FastRead = NewIO(in, out)
	//defer FastRead.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		if sol() {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int64, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	prefix := make([]int64, n + 1)
	for i:=1;i<=n;i++ {
		prefix[i] = prefix[i-1] + nums[i-1]
	}
	for i:=1;i<n;i++ {
		if nums[i] > 0 && nums[i-1] > 0 {
			fmt.Fprintln(w, "NO")
			return
		}
	}
	st := newSegmentTree(prefix)
	left := make([]int, n)
	stack := make([]int, 0)
	for i := range nums {
		for len(stack) != 0 && nums[stack[len(stack)-1]] <= nums[i] {
			stack = stack[:len(stack)-1]
		}
		if len(stack) == 0 {
			left[i] = -1
		} else {
			left[i] = stack[len(stack)-1]
		}
		stack = append(stack, i)
	}
	right := make([]int, n)
	stack = make([]int, 0)
	for i:=n-1;i>=0;i-- {
		for len(stack) != 0 && nums[stack[len(stack)-1]] <= nums[i] {
			stack = stack[:len(stack)-1]
		}
		if len(stack) == 0 {
			right[i] = n
		} else {
			right[i] = stack[len(stack)-1]
		}
		stack = append(stack, i)
	}
	for i := range nums {
		if nums[i] > 0 && i != 0 {
			m := st.queryMin(1, left[i]+2, i)
			if prefix[i] - m > 0 {
				fmt.Fprintln(w, "NO")
				return
			}
		}
		if nums[i] > 0 && i != n - 1 {
			m := st.queryMax(1, i+3, right[i]+1)
			if m - prefix[i+1] > 0 {
				fmt.Fprintln(w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(w, "YES")
}

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

type seg []struct {
	l, r int
	min  int64
	max  int64
}

// 单点更新：build 和 update 通用
func (t seg) set(o int, min int64) {
	t[o].min = min
	t[o].max = min
}

// 合并两个节点上的数据：maintain 和 query 通用
// 要求操作满足区间可加性
// 例如 + * | & ^ min max gcd mulMatrix 摩尔投票 最大子段和 ...
func (seg) op(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func (t seg) maintain(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].min = t.op(lo.min, ro.min)
	t[o].max = t.op2(lo.max, ro.max)
}

func (t seg) build(a []int64, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t.set(o, a[l-1])
		return
	}
	m := (l + r) >> 1
	t.build(a, o<<1, l, m)
	t.build(a, o<<1|1, m+1, r)
	t.maintain(o)
}

// o=1  1<=i<=n
func (t seg) update(o, i int, min int64) {
	if t[o].l == t[o].r {
		t.set(o, min)
		return
	}
	if m := (t[o].l + t[o].r) >> 1; i <= m {
		t.update(o<<1, i, min)
	} else {
		t.update(o<<1|1, i, min)
	}
	t.maintain(o)
}

// o=1  [l,r] 1<=l<=r<=n
func (t seg) queryMin(o, l, r int) int64 {
	if l <= t[o].l && t[o].r <= r {
		return t[o].min
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.queryMin(o<<1, l, r)
	}
	if m < l {
		return t.queryMin(o<<1|1, l, r)
	}
	vl := t.queryMin(o<<1, l, r)
	vr := t.queryMin(o<<1|1, l, r)
	return t.op(vl, vr)
}

func (t seg) queryMax(o, l, r int) int64 {
	if l <= t[o].l && t[o].r <= r {
		return t[o].max
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.queryMax(o<<1, l, r)
	}
	if m < l {
		return t.queryMax(o<<1|1, l, r)
	}
	vl := t.queryMax(o<<1, l, r)
	vr := t.queryMax(o<<1|1, l, r)
	return t.op2(vl, vr)
}

func newSegmentTree(a []int64) seg {
	t := make(seg, 4*len(a))
	t.build(a, 1, 1, len(a))
	return t
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

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

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

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

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

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

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

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

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

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

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

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

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

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

func check(a []int) bool {
	n := len(a)
	ps := make([]int64, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (int64)(a[i])

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1 // [minl, i) 区间 小于a[i]
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1 // ps[i]-ps[mins+1]>0
		}

		if minl < mins {
			return false
		}

		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := ri()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ri()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		if sol() {
			myio.Println("YES")
		} else {
			myio.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }

func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }

type segtree struct { n, size, log int; op func(int64, int64) int64; e int64; d []int64 }
func Newsegtree(n int, op func(int64, int64) int64, e int64) *segtree {
	v := make([]int64, n); for i := 0; i < n; i++ { v[i] = e }; return NewsegtreeVec(v, op, e)
}
func NewsegtreeVec(v []int64, op func(int64, int64) int64, e int64) *segtree {
	n, sz, log := len(v), 1, 0; for sz < n { sz <<= 1; log += 1 }; d := make([]int64, 2*sz); d[0] = e
	for i := 0; i < n; i++ { d[sz+i] = v[i] }; st := &segtree{n, sz, log, op, e, d}
	for i := sz - 1; i >= 1; i-- { st.update(i) }; return st
}
func (q *segtree) Set(p int, v int64) {
	p += q.size; q.d[p] = v; for i := 1; i <= q.log; i++ { q.update(p >> uint(i)) }
}
func (q *segtree) Get(p int) int64 { return q.d[p+q.size] }
func (q *segtree) Prod(l int, r int) int64 {
	if r < l { return q.e }; r += 1; sml, smr := q.e, q.e; l += q.size; r += q.size
	for l < r {
		if l&1 != 0 { sml = q.op(sml, q.d[l]); l++ }; if r&1 != 0 { r--; smr = q.op(q.d[r], smr) }; l >>= 1; r >>= 1
	}
	return q.op(sml, smr)
}
func (q *segtree) Allprod() int64 { return q.d[1] }
func (q *segtree) MaxRight(l int, f func(int64) bool) int {
	if l == q.n { return q.n - 1 }; l += q.size; sm := q.e
	for {
		for l%2 == 0 { l >>= 1 }
		if !f(q.op(sm, q.d[l])) {
			for l < q.size { l *= 2; if f(q.op(sm, q.d[l])) { sm = q.op(sm, q.d[l]); l++ } }; return l - q.size - 1
		}
		sm = q.op(sm, q.d[l]); l++; if l&-l == l { break }
	}
	return q.n - 1
}
func (q *segtree) MinLeft(r int, f func(int64) bool) int {
	if r < 0 { return 0 }; r += q.size; sm := q.e; r++
	for {
		r--; for r > 1 && r%2 == 1 { r >>= 1 }
		if !f(q.op(q.d[r], sm)) {
			for r < q.size { r = 2*r + 1; if f(q.op(q.d[r], sm)) { sm = q.op(q.d[r], sm); r-- } }; return r + 1 - q.size
		}
		sm = q.op(q.d[r], sm); if r&-r == r { break }
	}
	return 0
}
func (q *segtree) update(k int) { q.d[k] = q.op(q.d[2*k], q.d[2*k+1]) }

type stack struct { buf []xxx; l int }
func Newstack() *stack { buf := make([]xxx, 0); return &stack{buf, 0} }
func (q *stack) IsEmpty() bool { return q.l == 0 }
func (q *stack) Clear() { q.buf = q.buf[:0]; q.l = 0 }
func (q *stack) Len() int { return q.l }
func (q *stack) Push(x xxx) { q.buf = append(q.buf, x); q.l++ }
func (q *stack) Pop() xxx {
	if q.l == 0 { panic("Empty stack Pop()") }; v := q.buf[q.l-1]; q.l--; q.buf = q.buf[:q.l]; return v
}
func (q *stack) Head() xxx { if q.l == 0 { panic("Empty stack Head()") }; return q.buf[q.l-1] }
func (q *stack) Top() xxx { return q.Head() }

type xxx struct { i,v int }

func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); A := gis(N)
		cum := make([]int64,N+1); cum[0] = 0; for i:=0;i<N;i++ { cum[i+1] = cum[i] + int64(A[i])  } // Add 1 to deal with zero on left
		// Just use a segtree for RMQs -- lazy
		stmin := NewsegtreeVec(cum,min64 ,1000000000000000000)
		stmax := NewsegtreeVec(cum,max64,-1000000000000000000)
		larr,rarr := ia(N),ia(N)
		st := Newstack()
		for i:=0;i<N;i++ {
			for !st.IsEmpty() && st.Head().v <= A[i] { st.Pop() }
			if st.IsEmpty() { larr[i] = 0 } else { larr[i] = st.Head().i+1 }
			st.Push(xxx{i,A[i]})
		}
		st.Clear()
		for i:=N-1;i>=0;i-- {
			for !st.IsEmpty() && st.Head().v <= A[i] { st.Pop() }
			if st.IsEmpty() { rarr[i] = N-1 } else { rarr[i] = st.Head().i-1 }
			st.Push(xxx{i,A[i]})

		}
		good := true
		for i,a := range A {
			lsum := stmin.Prod(larr[i],i)
			rsum := stmax.Prod(i+1,rarr[i]+1)
			if rsum-lsum > int64(a) { good = false; break }
		}
		if good { fmt.Fprintln(wrtr,"YES") } else { fmt.Fprintln(wrtr,"NO") }
	}
}

package main

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

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

func main() {
	defer _w.Flush()
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	st = make([]int, 0)
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1] - 1
		}
		st = append(st, i)
	}
	sg := make(seg, (n+1)<<2)
	sg.init(1, 0, n-1, pre)
	for i := range a {
		if a[i] >= 0 {
			v := sg.que(1, 0, n-1, l[i], i)
			if pre[i]-v.Mi > a[i] {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
		if a[i] >= 0 {
			v := sg.que(1, 0, n-1, i, r[i])
			if v.Mx-pre[i] > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mi int64
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mi, t[x].Mx = v.(int64), v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		min(x.Mi, y.Mi),
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mi = min(t[x<<1].Mi, t[x<<1|1].Mi)
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			1e18,
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

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

func main() {
	defer _w.Flush()
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	st = make([]int, 0)
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1] - 1
		}
		st = append(st, i)
	}
	sg := make(seg, (n+1)<<2)
	sg.init(1, 0, n-1, pre)
	for i := range a {
		if a[i] > 0 {
			v := sg.que(1, 0, n-1, l[i], i)
			if pre[i]-v.Mi > a[i] {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
		if a[i] >= 0 {
			v := sg.que(1, 0, n-1, i, r[i])
			if v.Mx-pre[i] > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mi int64
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mi, t[x].Mx = v.(int64), v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		min(x.Mi, y.Mi),
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mi = min(t[x<<1].Mi, t[x<<1|1].Mi)
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			1e18,
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

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

func main() {
	defer _w.Flush()
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	st = make([]int, 0)
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1] - 1
		}
		st = append(st, i)
	}
	sg := make(seg, (n+1)<<2)
	sg.init(1, 0, n-1, pre)
	for i := range a {
		if a[i] > 0 {
			v := sg.que(1, 0, n-1, l[i], i)
			if pre[i]-v.Mi > a[i] {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
		if a[i] < 0 {
			v := sg.que(1, 0, n-1, i, r[i])
			if v.Mx-pre[i] > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mi int64
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mi, t[x].Mx = v.(int64), v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		min(x.Mi, y.Mi),
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mi = min(t[x<<1].Mi, t[x<<1|1].Mi)
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			1e18,
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

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

/*
1
5
-1 2 -3 2 -1
*/
func main() {
	defer _w.Flush()
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	st = make([]int, 0)
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1] - 1
		}
		st = append(st, i)
	}
	sg := make(seg, (n+1)<<2)
	sg.init(1, 0, n-1, pre)
	for i := range a {
		if a[i] >= 0 {
			v := sg.que(1, 0, n-1, l[i], i)
			if pre[i]-v.Mi > a[i] {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
		if a[i] < 0 {
			v := sg.que(1, 0, n-1, i, r[i])
			if v.Mx-pre[i] > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mi int64
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mi, t[x].Mx = v.(int64), v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		min(x.Mi, y.Mi),
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mi = min(t[x<<1].Mi, t[x<<1|1].Mi)
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			1e18,
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

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

func main() {
	defer _w.Flush()
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1]
		}
		st = append(st, i)
	}
	sg := make(seg, (n+1)<<2)
	sg.init(1, 0, n-1, a)
	for i := range a {
		if a[i] >= 0 {
			v := sg.que(1, 0, n-1, l[i], i)
			if pre[i]-v.Mi > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
		if a[i] < 0 {
			v := sg.que(1, 0, n-1, i, r[i])
			if v.Mx-pre[i] > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mi int64
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mi, t[x].Mx = v.(int64), v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		min(x.Mi, y.Mi),
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mi = min(t[x<<1].Mi, t[x<<1|1].Mi)
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			1e18,
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

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

func main() {
	var t int
	fmt.Fscan(_r, &t)
	for ; t > 0; t-- {
		solve()
	}
}
func min(x, y int64) int64 {
	if x <= y {
		return x
	}
	return y
}
func max(x, y int64) int64 {
	if x >= y {
		return x
	}
	return y
}
func solve() {
	var n int
	fmt.Fscan(_r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	pre := make([]int64, n)
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
		if a[i] > 0 && a[i-1] > 0 {
			fmt.Fprintln(_w, "NO")
			return
		}
	}
	st := make([]int, 0)
	l, r := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			l[i] = 0
		} else {
			l[i] = st[len(st)-1] + 1
		}
		st = append(st, i)
	}
	for i := n - 1; i >= 0; i-- {
		for len(st) > 0 && a[st[len(st)-1]] <= a[i] {
			st = st[:len(st)-1]
		}
		if len(st) == 0 {
			r[i] = n - 1
		} else {
			r[i] = st[len(st)-1]
		}
		st = append(st, i)
	}
	sg := make(seg, (n+1)<<2)
	sg.init(1, 0, n-1, a)
	for i := range a {
		if a[i] >= 0 {
			v := sg.que(1, 0, n-1, l[i], i)
			if pre[i]-v.Mi > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
		if a[i] < 0 {
			v := sg.que(1, 0, n-1, i, r[i])
			if v.Mx-pre[i] > 0 {
				fmt.Fprintln(_w, "NO")
				return
			}
		}
	}
	fmt.Fprintln(_w, "YES")
}

type nod struct {
	Mi int64
	Mx int64
}
type seg []nod

func (t seg) set(x int, v interface{}) {
	t[x].Mi, t[x].Mx = v.(int64), v.(int64)
}

func (t seg) merge(x, y nod) nod {
	return nod{
		min(x.Mi, y.Mi),
		max(x.Mx, y.Mx),
	}
}

func (t seg) poll(x int) {
	t[x].Mi = min(t[x<<1].Mi, t[x<<1|1].Mi)
	t[x].Mx = max(t[x<<1].Mx, t[x<<1|1].Mx)
}

func (t seg) init(x, l, r int, a []int64) {
	if l == r {
		t.set(x, a[l])
		return
	}
	mid := (l + r) >> 1
	t.init(x<<1, l, mid, a)
	t.init(x<<1|1, mid+1, r, a)
	t.poll(x)
}

func (t seg) que(x, l, r, L, R int) nod {
	if l > R || r < L {
		return nod{
			1e18,
			-1e18,
		}
	}
	if L <= l && r <= R {
		return t[x]
	}
	mid := (l + r) >> 1
	return t.merge(t.que(x<<1, l, mid, L, R), t.que(x<<1|1, mid+1, r, L, R))
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

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

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

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

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

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

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

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

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

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

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

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

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

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

func check(a []int) bool {
	n := len(a)
	ps := make([]int, n+1)
	ps[0] = 0
	t1, t2 := 0, 0
	s1, s2 := make([]int, 0), make([]int, 0)

	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + a[i]

		for t1 > 0 && a[i] >= a[s1[t1-1]] {
			t1--
			s1 = s1[:t1]
		}

		minl := 0
		if t1 > 0 {
			minl = s1[t1-1] + 1 // [minl, i) 区间 小于a[i]
		}

		for t2 > 0 && ps[i] <= ps[s2[t2-1]] {
			t2--
			s2 = s2[:t2]
		}

		mins := 0
		if t2 > 0 {
			mins = s2[t2-1] + 1 // ps[i]-ps[mins+1]>0
		}

		if minl < mins {
			return false
		}

		s1 = append(s1, i)
		t1++
		s2 = append(s2, i)
		t2++
	}
	return true
}

func sol() bool {
	n := ri()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ri()
	}
	if !check(a) {
		return false
	}
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	if !check(a) {
		return false
	}
	return true
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		if sol() {
			myio.Println("YES")
		} else {
			myio.Println("NO")
		}
	}
}


Polycarp has $$$26$$$ tasks. Each task is designated by a capital letter of the Latin alphabet.The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.For example, if Polycarp solved tasks in the following order: "DDBBCCCBBEZ", then the teacher will see that on the third day Polycarp began to solve the task 'B', then on the fifth day he got distracted and began to solve the task 'C', on the eighth day Polycarp returned to the task 'B'. Other examples of when the teacher is suspicious: "BAB", "AABBCCDDEEBZZ" and "AAAAZAAAAA".If Polycarp solved the tasks as follows: "FFGZZZY", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: "BA", "AFFFCC" and "YYYYY".Help Polycarp find out if his teacher might be suspicious.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of days during which Polycarp solved tasks. The second line contains a string of length $$$n$$$, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.

For each test case output:    "YES", if the teacher cannot be suspicious;  "NO", otherwise.  You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

5
3
ABA
11
DDBBCCCBBEZ
7
FFGZZZY
1
Z
2
AB

package main

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

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

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
}

const MAXN = 1e3 + 5

func Solve() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	tag := make([]int, 26)
	for i := 0; i < 26; i++ {
		tag[i] = 0
	}
	for i := 0; i < n; i++ {
		if tag[s[i]-'A'] == 0 {
			tag[s[i]-'A'] = 1
		} else {
			if i-1 >= 0 && s[i-1] != s[i] {
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}

package main
import "fmt"
import "bufio"
import "os"
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) {fmt.Fprintf(writer, f, a...)}
func scanf(f string, a ...interface{}) {fmt.Fscanf(reader, f, a...)}
func main() {
    defer writer.Flush()
    var T int
    scanf("%d\n", &T)
    for cas := 1; cas <= T; cas++ {
        var N int
        var tasks string
        scanf("%d\n", &N)
        scanf("%s\n", &tasks)
        mp := make(map[byte]bool)
        mp[tasks[0]] = true
        check := func() bool {
            for idx := 1; idx < N; idx++ {
                if mp[tasks[idx]] != true {
                    mp[tasks[idx]] = true;
                } else {
                    if tasks[idx - 1] != tasks[idx] {
                        return false
                    }
                }
            }
            return true
        }
        res := check()
        if res {
            // fmt.Println("YES")
            printf("YES\n")
        } else {
            // fmt.Println("NO")
            printf("NO\n")
        }
    }
    return
}

package main
import "fmt"
import "bufio"
import "os"
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func main() {
    defer writer.Flush()
    var T int
    scanf("%d\n", &T)
    for cas := 1; cas <= T; cas++ {
        var N int
        var tasks string
        scanf("%d\n", &N)
        scanf("%s\n", &tasks)
        mp := make(map[byte]bool)
        mp[tasks[0]] = true
        check := func() bool {
            for idx := 1; idx < N; idx++ {
                if mp[tasks[idx]] != true {
                    mp[tasks[idx]] = true;
                } else {
                    if tasks[idx - 1] != tasks[idx] {
                        return false
                    }
                }
            }
            return true
        }
        res := check()
        if res {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
    return
}

package main
import "fmt"
func main() {
    var T int
    fmt.Scan(&T)
    for cas := 1; cas <= T; cas++ {
        var N int
        var tasks string
        fmt.Scan(&N)
        fmt.Scan(&tasks)
        mp := make(map[byte]bool)
        mp[tasks[0]] = true
        check := func() bool {
            for idx := 1; idx < N; idx++ {
                if mp[tasks[idx]] != true {
                    mp[tasks[idx]] = true;
                } else {
                    if tasks[idx - 1] != tasks[idx] {
                        return false
                    }
                }
            }
            return true
        }
        res := check()
        if res {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
    return
}

package main
import "fmt"
func main() {
    var T int
    fmt.Scan(&T)
    for cas := 1; cas <= T; cas++ {
        var N int
        var tasks string
        fmt.Scan(&N)
        fmt.Scan(&tasks)
        mp := make(map[byte]bool)
        mp[tasks[0]] = true
        res := func() bool {
            for idx := 1; idx < N; idx++ {
                if mp[tasks[idx]] != true {
                    mp[tasks[idx]] = true;
                } else {
                    if tasks[idx - 1] != tasks[idx] {
                        return false
                    }
                }
            }
            return true
        }()
        if res {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
    return
}

package main
import "fmt"
func main() {
    var T int
    fmt.Scan(&T)
    for cas := 1; cas <= T; cas++ {
        var N int
        var tasks string
        fmt.Scan(&N)
        fmt.Scan(&tasks)
        mp := make(map[byte]bool)
        mp[tasks[0]] = true
        var res bool = true
        for idx := 1; idx < N; idx++ {
            if mp[tasks[idx]] != true {
                mp[tasks[idx]] = true;
            } else {
                if tasks[idx - 1] != tasks[idx] {
                    res = false
                    break
                }
            }
        }
        if res {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
    return
}

package main
import (
	"fmt"
	"strings"
	//"os"
)
var n int
func main() {
	fmt.Scan(&n)
	for i:=0;i<n;i++{
		var len int
		fmt.Scan(&len)
		var list []string = make([]string,0,len)
		var str string
		fmt.Scan(&str)
		for k:=0;k<len;k++{
			list = append(list,strings.ToLower(string(str[k])))
		}
		no:=0
		for k:=1;k<len;k++{
			if list[k] == list[k-1]{
				continue
			} else {
				for l:=0;l<k;l++{
					if list[k] == list[l] {
						no++
						break
					}
				}
			}
		}
		if no == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var TestCaseNum int
	var result bool
	var LastCase byte
	fmt.Scanln(&TestCaseNum)
	for i := 0; i < TestCaseNum; i++ {
		var SolveDay int
		var SolveCase []byte
		var SolvedCase []byte

		result = true
		LastCase = 0
		fmt.Scanln(&SolveDay)
		fmt.Scanln(&SolveCase)
		for j := 0; j < SolveDay; j++ {
			if SolveCase[j] == LastCase {
				continue
			} else if CheckContain(SolveCase[j], SolvedCase) {
				result = false
				break
			} else {
				LastCase = SolveCase[j]
				SolvedCase = append(SolvedCase, SolveCase[j])
			}
		}
		if result == false {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

func CheckContain(Checkbyte byte, CheckSlice []byte) bool {
	result := false
	for _, element := range CheckSlice {
		if element == Checkbyte {
			result = true
			break
		}
	}
	return result
}

package main

import (
	"fmt"
)

func main() {
	var (
		t   int
		n   int
		str string
	)
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		fmt.Scanf("%s\n", &str)
		if n == 1 {
			fmt.Println("YES")
		} else {
			var (
				c []string
				q int
			)
			x := string(str[0])
			c = append(c, x)
			for j := 1; j < n; j++ {
				x := string(str[j])
				b := SliceContains(c, x)
				if !b {
					c = append(c, x)
				} else {
					if str[j] != str[j-1] {
						q++
					}
				}
			}
			if q == 0 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

func SliceContains(s []string, e string) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

package main

import(
	"fmt"
)

func solve(val string) string{
	mapper := map[rune]bool{}

	prev := rune(val[0])
	for _, i := range val{
		if i == prev{
			mapper[i] = true
			prev = i
			continue
		}
		if mapper[i] == true{
			return "NO"
		}

		mapper[i] = true
		prev = i
	}
	return "YES"
}

func main(){
	var testcases int
	fmt.Scanf("%d\n", &testcases)

	for ; testcases > 0; testcases-- {
		var n int
		fmt.Scanf("%d\n", &n)

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

		fmt.Println(solve(val))
	}
}

package main

import "fmt"

func main()  {
	var t, n int
	fmt.Scanf("%d\n", &t);
	for c := 0; c < t; c++ {
		fmt.Scanf("%d\n", &n);
		var s string
		ans := "YES"
		fmt.Scanln(&s)
		mp := make(map[uint8]bool)
		for i := 0; i < len(s); i++ {
			res := mp[s[i]]
			if(res != false && s[i-1] != s[i]) {
				ans = "NO"
				break
			} else {
				mp[s[i]] = true
			}
		}
		fmt.Println(ans)
	}

}

package main

import "fmt"

func solve_task(str string) string {
    var is_used [26]bool
    var shift = "A"[0]
    var last = str[0]
    is_used[last - shift] = true

    for i := 1; i < len(str); i++ {
        if str[i] != last {
            if is_used[str[i] - shift] {
                return "NO"
            }
            is_used[str[i] - shift] = true
            last = str[i]
        }
    }
    return "YES"
}

func main() {
    var n_tasks int
    fmt.Scanf("%d\n", &n_tasks)
    for i := 0; i < n_tasks; i++ {
        var strlen int
        var str string
        fmt.Scanln(&strlen)
        fmt.Scanln(&str)
        fmt.Printf("%s\n", solve_task(str))
    }
}

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

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

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	outputs := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		s := ScanString()
		c := map[byte]bool{}
		res := true

		for i := 0; i < n; i++ {
			if c[s[i]] && s[i] != s[i-1] {
				res = false
				break
			}

			c[s[i]] = true
		}

		fmt.Println(outputs[res])
	}
}

package main

import (
	"fmt"
)

func main1() {
	var N int
	var A string
	var occ []int

	fmt.Scanf("%d\n", &N)
	fmt.Scanf("%s\n", &A)

	for i := 0; i < 26; i++ {
		occ = append(occ, -1)
	}

	for i := 0; i < N; i++ {
		if occ[A[i] - 'A'] != -1 && occ[A[i] - 'A'] != i - 1 {
			fmt.Printf("NO\n")
			return
		}

		occ[A[i] - 'A'] = i
	}

	fmt.Printf("YES\n")
	return
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)

	for i := 0; i < T; i++ {
		main1()
	}
}

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

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var t int
	// fmt.Scanf("%d\n", &t)
	fmt.Fscanf(r, "%d\n", &t)
	for t > 0 {
		var length int
		// fmt.Scanf("%d\n", &length)
		fmt.Fscanf(r, "%d\n", &length)
		var word string
		fmt.Fscanf(r, "%s\n", &word)
		solve(length, word)
		t--
	}
}

func solve(l int, w string) {
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()
	s := strings.Split(w, "")
	sl := make([]string, 0)
	for i := 0; i < len(s); i++ {
		if i == len(s)-1 {
			if ok := strings.Contains(strings.Join(sl, ""), s[i]); ok {
				fmt.Fprintln(wr, "NO")
				return
			}
			break
		}
		// fmt.Println(s[i])
		if s[i] == s[i+1] {
			continue
		} else {
			if ok := strings.Contains(strings.Join(sl, ""), s[i]); ok {
				fmt.Fprintln(wr, "NO")
				return
			}
			sl = append(sl, s[i])
		}
	}
	fmt.Fprintln(wr, "YES")
}

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

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		var length int
		fmt.Scanf("%d\n", &length)
		var word string
		fmt.Scanf("%s\n", &word)
		solve(length, word)
		t--
	}
}

func solve(l int, w string) {
	s := strings.Split(w, "")
	sl := make([]string, 0)
	for i := 0; i < len(s); i++ {
		if i == len(s)-1 {
			if ok := strings.Contains(strings.Join(sl, ""), s[i]); ok {
				fmt.Println("NO")
				return
			}
			break
		}
		// fmt.Println(s[i])
		if s[i] == s[i+1] {
			continue
		} else {
			if ok := strings.Contains(strings.Join(sl, ""), s[i]); ok {
				fmt.Println("NO")
				return
			}
			sl = append(sl, s[i])
		}
	}
	fmt.Println("YES")
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanString(s *string) { fmt.Fscanln(reader, s) }

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

	scanf("%d\n", &t)
	for t > 0 {
		var str string
		var n int
		scanf("%d\n", &n)
		scanString(&str)

		ok := true
		var vis = map[byte]bool{}
		var i, j int
		for i = 0; i < n; i = j {
			j = i

			for j < n && str[i] == str[j] {
				j++
			}
			if vis[str[i]] {
				ok = false
			}
			vis[str[i]] = true
		}

		if ok {
			println("YES")
		} else {
			println("NO")
		}
		t--
	}

}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

		var len int
		var taskSolved string
		var res string = "YES\n"
		scanf("%v \n %v \n", &len, &taskSolved)

		solved := make(map[rune]bool)
		prev := '1'
		for _, char := range taskSolved {
			if solved[char] && char != prev {
				res = "NO\n"
				break
			} else if char != prev {
				solved[prev] = true
				prev = char
			}
		}

		printf(res)
	}
}

package main

import "fmt"

func distracted(str string) string {
	seen := make(map[rune]bool)
	last := ' '
	for _, v := range str {
		_, s := seen[v]
		if v != last && s {
			return "NO"
		}
		seen[v] = true
		last = v
	}
	return "YES"
}

func main() {
	var nTests int
	fmt.Scanf("%d\n", &nTests)
	for i := 0; i < nTests; i++ {
		var str string
		var days int
		fmt.Scanf("%d\n", &days)
		fmt.Scanf("%s\n", &str)
		fmt.Println(distracted(str))
	}
}

package main

import "fmt"

func solve() {
	ted := map[int]int{}
	var l int
	var line string

	fmt.Scan(&l)
	fmt.Scan(&line)

	ted[int(line[0])]++

	for i := 1; i < l; i++ {
		if line[i] != line[i-1] && ted[int(line[i])] != 0 {
			fmt.Println("NO")
			return
		}

		ted[int(line[i])]++
	}

	fmt.Println("YES")
}

func main() {
	var t int

	fmt.Scanln(&t)

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

package main

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

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

type Readable interface {
	bool | int | uint64 | int64 | double | float | byte
}

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

func print(arg ...interface{})            { fmt.Fprint(out, arg...) }
func println(arg ...interface{})          { fmt.Fprintln(out, arg...) }
func printf(f string, arg ...interface{}) { fmt.Fprintf(out, f, arg...) }
func scanf(f string, arg ...interface{})  { fmt.Fscanf(in, f, arg...) }

func readLn() string {
	ln, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}

	return strings.Trim(ln, " \n\r")
}

func readString() string {
	return readLn()
}

func readStrings() []string {
	return strings.Split(readLn(), " ")
}

func read[T Readable](f func(string) (T, error), input ...string) T {
	if len(input) == 0 {
		input = []string{readLn()}
	}

	res, err := f(input[0])
	if err != nil {
		panic(err)
	}

	return res
}

func readMany[T Readable](f func(...string) T) []T {
	input := readStrings()
	arr := make([]T, len(input))
	for i := 0; i < len(arr); i++ {
		arr[i] = f(input[i])
	}

	return arr
}

func readBool(input ...string) bool {
	return read(strconv.ParseBool, input...)
}

func readInt(input ...string) int {
	return read(strconv.Atoi, input...)
}

func readByte(input ...string) byte {
	return byte(read(func(s string) (uint64, error) {
		return strconv.ParseUint(s, 10, 8)
	}, input...))
}

func readDouble(input ...string) double {
	return read(func(s string) (float64, error) {
		return strconv.ParseFloat(s, 64)
	}, input...)
}

func readFloat(input ...string) float {
	return float32(read(func(s string) (float64, error) {
		return strconv.ParseFloat(s, 32)
	}, input...))
}

func readLong(input ...string) long {
	return read(func(s string) (int64, error) {
		return strconv.ParseInt(s, 10, 64)
	}, input...)
}

func readULong(input ...string) ulong {
	return read(func(s string) (uint64, error) {
		return strconv.ParseUint(s, 10, 64)
	}, input...)
}

func readBinary(input ...string) long {
	return read(func(s string) (int64, error) {
		return strconv.ParseInt(s, 2, 64)
	}, input...)
}

func readBools() []bool {
	return readMany(readBool)
}

func readInts() []int {
	return readMany(readInt)
}

func readBytes() []byte {
	return readMany(readByte)
}

func readDoubles() []double {
	return readMany(readDouble)
}

func readFloats() []float {
	return readMany(readFloat)
}

func readLongs() []long {
	return readMany(readLong)
}

func readULongs() []ulong {
	return readMany(readULong)
}

func main() {
	defer out.Flush()

	// solution
	t := readInt()
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		n := readInt()
		s := readString()
		ans[i] = "YES"
		arr := make([]bool, 26)
		for j := 0; j < n; j++ {
			ch := s[j] - 'A'
			if j != 0 && s[j] != s[j-1] && arr[ch] {
				ans[i] = "NO"
				break
			}
			arr[ch] = true
		}
	}

	for i := 0; i < t; i++ {
		println(ans[i])
	}
}

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

	return x
}

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

	return y
}

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

	return x
}

/*
Polycarp has 26

tasks. Each task is designated by a capital letter of the Latin alphabet.

The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.

Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.

For example, if Polycarp solved tasks in the following order: "DDBBCCCBBEZ", then the teacher will see that on the third day Polycarp began to solve the task 'B', then on the fifth day he got distracted and began to solve the task 'C', on the eighth day Polycarp returned to the task 'B'. Other examples of when the teacher is suspicious: "BAB", "AABBCCDDEEBZZ" and "AAAAZAAAAA".

If Polycarp solved the tasks as follows: "FFGZZZY", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: "BA", "AFFFCC" and "YYYYY".

Help Polycarp find out if his teacher might be suspicious.
Input

The first line contains an integer t
(1≤t≤1000). Then t

test cases follow.

The first line of each test case contains one integer n
(1≤n≤50

) — the number of days during which Polycarp solved tasks.

The second line contains a string of length n

, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.
Output

For each test case output:

    "YES", if the teacher cannot be suspicious;
    "NO", otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).
*/

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		tasks := scanner.Text()
		var solvedTasks []bool = make([]bool, 26)
		var result string = "YES"
		solvedTasks[tasks[0]-'A'] = true
		for j := 1; j < n; j++ {
			if tasks[j-1] == tasks[j] {
				continue
			}
			if solvedTasks[tasks[j]-'A'] {
				result = "NO"
				break
			} else {
				solvedTasks[tasks[j]-'A'] = true
			}
		}
		writer.WriteString(result + "\n")
	}
	writer.Flush()
}

// 1520A. Do Not Be Distracted!
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		var n int
		fmt.Fscan(reader, &n, &s)
		so_far := make(map[byte]bool)
		distracted := false
		so_far[s[0]] = true
		for i := 1; i < len(s); i++ {
			if s[i] != s[i-1] && so_far[s[i]] {
				distracted = true
				break
			}
			so_far[s[i]] = true
		}
		if distracted {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

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

	var n, t int
	var line string
	for fmt.Fscan(r, &t); t > 0; t-- {
		var char rune
		isOk := true
		fmt.Fscan(r, &n)
		fmt.Fscan(r, &line)
		chars := make(map[rune]int)

		for _, c := range line {
			char = c
			chars[c]++
			break
		}

		for _, c := range line {
			if char == c {
				chars[c]++
			} else {
				if _, ok := chars[c]; ok {
					isOk = false
					break
				} else {
					char = c
					chars[c]++
				}
			}
		}

		if isOk {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		var n int
		var s string
		m := make(map[string]struct{})
		fmt.Scanf("%d\n %s\n", &n, &s)
		if len(s) == 1 {
			fmt.Println("YES")
		} else {
			for i := 1; i < len(s); i++ {
				if _, ok := m[string(s[i])]; ok {
					fmt.Println("NO")
					break
				}
				if s[i-1] != s[i] {
					m[string(s[i-1])] = struct{}{}
				}
				if i == len(s)-1 {
					fmt.Println("YES")
				}
			}
		}

		t--
	}

}

package main

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

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

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

		var s string
		fmt.Fscan(in, &s)

		f := true
	Loop:
		for i := 0; i < n; i++ {
			var done bool
			for j := i + 1; j < n; j++ {
				if s[j] != s[i] {
					done = true
				} else if done && s[j] == s[i] {
					f = false
					break Loop
				}
			}
		}

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

package main

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

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

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

	for ; test > 0; test-- {
		days := parseInt(getString(reader))
		work := []byte(getString(reader))

		changeWorks := make([]byte, 0, days)
		changeWorks = append(changeWorks, work[0])
		current := work[0]
		for i := 1; i < days; i++ {
			if current != work[i] {
				current = work[i]
				changeWorks = append(changeWorks, current)
			}
		}

		suspision := false
		root := new(Node)
		root.data = changeWorks[0]

		for _, v := range changeWorks[1:] {
			check := root.add(v)
			if check == nil {
				suspision = true
				break
			}
		}

		if suspision {
			writer.WriteString("NO\n")
		} else {
			writer.WriteString("YES\n")
		}
	}
	writer.Flush()
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

type Node struct {
	data  byte
	left  *Node
	right *Node
}

func (N *Node) add(value byte) *Node {
	if N.data > value {
		if N.left == nil {
			N.left = new(Node)
			N.left.data = value
			return N.left
		} else {
			return N.left.add(value)
		}
	} else if N.data < value {
		if N.right == nil {
			N.right = new(Node)
			N.right.data = value
			return N.right
		} else {
			return N.right.add(value)
		}
	}
	return nil
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt8() int8 {
	i, err := strconv.ParseInt(scan(), 10, 8)
	if err != nil {
		panic(err)
	}
	return int8(i)
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

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

func min(ints ...int) int {
	a := ints[0]
	n := len(ints)
	for i := 1; i < n; i++ {
		if ints[i] < a {
			a = ints[i]
		}
	}
	return a
}

func max(ints ...int) int {
	a := ints[0]
	n := len(ints)
	for i := 1; i < n; i++ {
		if ints[i] > a {
			a = ints[i]
		}
	}
	return a
}

type Noop struct{}

var noop = Noop{}

func proc() {
	n := scanInt()
	s := scan()
	m := make(map[byte]Noop)
	var has bool
	var i int
	for i = 0; i+1 < n; i++ {
		if s[i+1] != s[i] {
			if _, has = m[s[i+1]]; has {
				fmt.Println("NO")
				return
			}
			m[s[i]] = noop
		}
	}
	fmt.Println("YES")
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		proc()
	}
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	n := mustReadInt(r)
	for i := int64(0); i < n; i++ {
		mustReadInt(r)
		alreadySolved := make(map[int64]bool)
		previous := rune(-1)
		tasks := strings.TrimSpace(mustReadLine(r))
		failed := false
		for _, t := range tasks {
			if previous != t {
				if alreadySolved[int64(t)] {
					failed = true
					break
				} else {
					previous = t
					alreadySolved[int64(t)] = true
				}
			}
		}
		if failed {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

}
func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}
func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

var (
	localEnv       = flag.Bool("local", false, "Enable Local environment")
	inputFileName  = flag.String("input", "input.txt", "Input filename")
	outputFileName = flag.String("output", "output.txt", "Output filename")
)

func main() {
	flag.Parse()

	setScanner()
	setWriter()

	defer writer.Flush()

	scanner.Split(bufio.ScanWords)

	t := getInt()

	for i := 0; i < t; i++ {
		n := getInt()
		s := getString()
		alphabet := initAlphabet()
		f := 0

		alphabet[rune(s[0])]++

		for j := 1; j < n; j++ {
			ch := rune(s[j])

			if alphabet[ch] == 0 || rune(s[j-1]) == ch {
				alphabet[ch]++
			} else {
				f = 1
				break
			}
		}

		if f == 1 {
			writeString("NO")
		} else {
			writeString("YES")
		}
	}
}

func initAlphabet() map[rune]int {
	return map[rune]int{
		'A': 0,
		'B': 0,
		'C': 0,
		'D': 0,
		'E': 0,
		'F': 0,
		'G': 0,
		'H': 0,
		'I': 0,
		'J': 0,
		'K': 0,
		'L': 0,
		'M': 0,
		'N': 0,
		'O': 0,
		'P': 0,
		'Q': 0,
		'R': 0,
		'S': 0,
		'T': 0,
		'U': 0,
		'V': 0,
		'W': 0,
		'X': 0,
		'Y': 0,
		'Z': 0,
	}
}

func getString() string {
	scanner.Scan()

	return scanner.Text()
}

func getInt64() int64 {
	scanner.Scan()

	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)

	return x
}

func getInt() int {
	return int(getInt64())
}

func setScanner() {
	if *localEnv {
		inputFile, err := os.Open(*inputFileName)

		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}

		scanner = bufio.NewScanner(inputFile)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
}

func setWriter() {
	if *localEnv {
		outputFile, err := os.Create(*outputFileName)

		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}

		writer = bufio.NewWriter(outputFile)
	} else {
		writer = bufio.NewWriter(os.Stdout)
	}
}

func writeString(str string) {
	_, _ = writer.WriteString(fmt.Sprintf("%s\n", str))
}

package main

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

func solve(n int, s string) string {
	for i := byte('A'); i <= byte('Z'); i++ {
		p, q := -1, -1
		for j := range s {
			if s[j] == i {
				if p == -1 {
					p = j
				}
				q = j
			}
		}
		if p > -1 {
			for j := p; j <= q; j++ {
				if s[j] != i {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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

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

package main

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

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

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

		var alphabets [27]int
		left, right, flag := 0, 0, true
		for left < n && right < n {
			if alphabets[int(s[left]) - int('A')] != 0 {
				flag = false
				break
			}
			// expand the window
			for right < n && s[right] == s[left] {
				right++
			}
			alphabets[int(s[left]) - int('A')] = right - left
			// Shrink the window
			left = right
		}
		if flag {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

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

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

package main

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

func solve(n int32, tasks string) string {
	mapping := map[byte]int32{}
	for i := 'A'; i <= 'Z'; i++ {
		mapping[byte(i)] = int32(-1)
	}

	current := byte('0')
	for i := int32(0); i < n; i++ {
		if current != tasks[i] && mapping[tasks[i]] != -1 {
			return "NO"
		}
		current = tasks[i]
		mapping[current] = i
	}

	return "YES"
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		tasks := ""
		fmt.Fscanf(in, "%d\n", &n)
		fmt.Fscanf(in, "%s\n", &tasks)
		fmt.Fprintf(out, "%s\n", solve(n, tasks))
		tt--
	}
	out.Flush()
}

package main

import "fmt"

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

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

		var s string
		fmt.Scan(&s)

		mp := make(map[string]bool)
		mp[string(s[0])] = true

		var flag bool

		for i := 1; i < len(s); i++ {
			if mp[string(s[i])] && string(s[i]) != string(s[i-1]) {
				fmt.Println("NO")
				flag = true
				break
			}
			mp[string(s[i])] = true
		}

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

package main

import "fmt"

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 main() {
	var T int
	fmt.Scan(&T)

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

		var s string
		fmt.Scan(&s)

		mp := make(map[string]bool)
		mp[string(s[0])] = true

		var flag bool

		for i := 1; i < len(s); i++ {
			if mp[string(s[i])] && string(s[i]) != string(s[i-1]) {
				fmt.Println("NO")
				flag = true
				break
			}
			mp[string(s[i])] = true
		}

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

package main

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

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

	solve := func(Case int) {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)
		pre := map[byte]int{}
		last := byte('$')
		for i := range s {
			if byte(s[i]) == last {
				continue
			}
			if _, ok := pre[byte(s[i])]; ok {
				fmt.Fprintln(out, "NO")
				return
			}
			pre[byte(s[i])] = i
			last = s[i]
		}
		fmt.Fprintln(out, "YES")
	}

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

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

func min(a []int) int {
	mn := int(1e9)
	for i := range a {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

func main()  {
	scanner := bufio.NewScanner(os.Stdin)

	cases := 0
	if scanner.Scan() {
		cases ,_ =  strconv.Atoi(scanner.Text())
	}

	mainloop: for i:=0; i<cases; i++ {
		scanner.Scan()
		scanner.Scan()
		s := scanner.Text()
		if len(s) < 2{
			os.Stdout.WriteString("YES\n")
			continue

		}

		cur := s[0]
		m := make(map [byte] int)
		m[cur] = 1
		for j:=1 ; j<len(s); j++ {
			if s[j] == cur {
				continue
			} else {
				if m[s[j]] != 0 {
					os.Stdout.WriteString("NO\n")
					continue mainloop
				} else {
					cur = s[j]
					m[cur] = 1
				}
			}

		}
		os.Stdout.WriteString("YES\n")
	}

}

package main

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

const (
	MOD int = int(1e9 + 7)
)

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

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

	for i := 0; i < t; i++ {
		var l int
		fmt.Fscan(_r, &l)
		var s []byte
		var ans string = "YES"
		fmt.Fscan(_r, &s)
		s = append(s, '?')
		l++

		mp := make(map[byte]bool)

		for j := 1; j < l; j++ {
			if s[j-1] != s[j] {
				if mp[s[j-1]] {
					ans = "NO"
				} else {
					mp[s[j-1]] = true
				}
			}
		}
		fmt.Fprintf(_w, "%s\n", ans)

	}

}

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1520A
 Date: 16/05/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1520/A
 Problem: CF1520A
**/
func (in *CF1520A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		line := in.NextString()
		data := map[uint8]int{}
		ws := false
		for i := 0; n > 0; n-- {
			index, ok := data[line[i]]
			if ok && index+1 != i {
				fmt.Println("NO")
				ws = true
				break
			}
			data[line[i]] = i
			i++
		}
		if !ws {
			fmt.Println("YES")
		}

	}
}

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

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

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Scanln(&n)
		var s string
		fmt.Scanln(&s)

		var was [26]bool
		allRight := true

		for j := 0; j < len(s); j++ {
			lwas := &was[int(s[j])-int('A')]
			if j != 0 && s[j] != s[j-1] && *lwas {
				allRight = false
				break
			}
			*lwas = true
		}

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

package main
import "fmt"

var chars =[]rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
var charTaskMap map[rune]bool
func resetTask() {
	charTaskMap = make(map[rune]bool)
	for _, char:= range chars {
		charTaskMap[char] = false
	}
}

func main() {
	var q int
	_, err := fmt.Scan(&q)
	if err != nil {
		return
	}
	for i := 0; i<q; i++ {
		resetTask()
		var n int
		var s string
		_, err := fmt.Scan(&n,&s)
		if err != nil {
			return
		}
		var suspicious = false
		var previousChar = 'a'
		for _, char:= range s {
			if !charTaskMap[char] {
				if previousChar != 'a' {
					if char != previousChar {
						charTaskMap[previousChar] = true
						previousChar = char
					}
				} else {
					previousChar = char
				}
			} else {
				suspicious = true
				break
			}
		}
		if suspicious {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	var s string

	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		Fscan(in, &s)
		chk := [26]bool{}
		i := 0
		for i < N {
			ch := s[i]
			idx := ch - 65
			if !chk[idx] {
				chk[idx] = true
				j := i
				for j < N && s[j] == ch {
					j++
				}
				i = j
			} else {
				break
			}
		}
		if i == N {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n int
	var str string
	fmt.Scanln(&t)
	for t > 0 {
		fmt.Scanln(&n)
		fmt.Scanln(&str)
		last := '-'
		var done [26]bool
		answer := true
		for _, ch := range str {
			index := byte(ch) - 65
			if done[index] == true && last != ch {
				answer = false
				break
			}
			done[index] = true
			last = ch
		}
		if answer {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
	}
}

package main

import (
	"fmt"
)

func main() {

	var t int
	fmt.Scan(&t)
	for t > 0{
		t -= 1
		var n int
		var s string
		fmt.Scan(&n)
		fmt.Scan(&s)
		ch := 0
		for i:=0; i < len(s); i++{
			for j:= i + 1; j <len(s); j++{
				if s[j]==s[i]{
					if j - i != 1{
						ch = 1
					}
					break
				}
			}
		}
		if ch == 0{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

/*

https://codeforces.com/contest/1520/problem/A
5
3
ABA
11
DDBBCCCBBEZ
7
FFGZZZY
1
Z
2
AB
*/

func isSuspicious(s string) bool {
	last := s[0]
	visited := make(map[uint8]bool)
	visited[s[0]] = true

	for i := 1; i < len(s); i++ {
		if last == s[i] {
			continue
		} else {
			if _, ok := visited[s[i]]; ok {
				return false
			} else {
				visited[s[i]] = true
				last = s[i]
			}
		}
	}
	return true
}

func main() {

	var t int

	fmt.Scanf("%d\n", &t)
	//fmt.Scanf("%d\n", &days)

	tests := make([]string, t, t)
	for i := 0; i < t; i++ {
		var s string
		var l int
		fmt.Scanf("%v\n", &l) // we don't need it though
		fmt.Scanf("%v\n", &s)
		tests[i] = s
		if isSuspicious(s) {
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}

	//fmt.Println(tests)

}

package main

import (
	"fmt"
	"os"
)

func main() {
	var t, n int

	fmt.Fscanln(os.Stdin ,&t)

	for i := 0; i < t; i++ {
		fmt.Fscanln(os.Stdin ,&n)

		var str string

		fmt.Fscanln(os.Stdin, &str)

		runes := []rune(str)
		runeSet := map[rune]bool{runes[0]: true}
		isDistracted := false
		for i := 1; i < n; i++ {
			if runes[i - 1] != runes[i] {
				if runeSet[runes[i]] {
					isDistracted = true
					break
				} else {
					runeSet[runes[i]] = true
				}
			}
		}

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

// @problemURL https://codeforces.com/contest/1520/problem/A
package main

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

func nt(s *bufio.Scanner) string {
	if !s.Scan() {
		fmt.Println(s.Err().Error())
		panic("Could not read input")
	}
	return s.Text()
}

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	T := ni(s)
	for ; T > 0; T-- {
		_ = ni(s)
		st := nt(s)
		seen := make(map[byte]bool)
		seen[st[0]] = true
		ans := true
		for i := 1; i < len(st) && ans; i++ {
			if st[i] != st[i-1] {
				if seen[st[i]] {
					ans = false
				} else {
					seen[st[i]] = true
				}
			}
		}

		if ans {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		SR := make([]byte, 0)
		fmt.Fscan(input, &SR)
		ARRAY := make([]string, 0)
		ll := len(SR)
		current := string(SR[0])
		ARRAY = append(ARRAY, string(SR[0]))
		w := 0
		for i := 1; i < ll; i++ {
			pp := len(ARRAY)
			ss := 0
			q := 0
			for j := 0; j < pp; j++ {
				if ARRAY[j] == string(SR[i]) {
					if current == string(SR[i]) {
						break
					} else {
						ss++
					}
				} else {
					q++
				}
			}
			if q == pp {
				current = string(SR[i])
				ARRAY = append(ARRAY, string(SR[i]))
			}
			if ss == 1 {
				w = 1
				fmt.Println("NO")
				break
			}
		}
		if w == 0 {
			fmt.Println("YES")
		}

	}
}

package main

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

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

	var t, n int

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		var s string
		fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
		var had [26]bool
		suspicious := false

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

			if i+1 < n && s[i] == s[i+1] {
				continue
			}

			if had[s[i]-'A'] {
				suspicious = true
				break
			}

			had[s[i]-'A'] = true
		}

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

package main

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

const maxN = 100023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n int
    var a string
    var mp[26] int
    var pr byte
    fmt.Fscan(in, &n)
    fmt.Fscan(in, &a)
    flag := true
    pr = '-'
    for i := 0; i < n; i++ {
      c := a[i] - 'A'
      if mp[c] == 1 && pr != c {
        flag = false
      }
      pr = c
      mp[c] = 1
    }
    if flag {
      fmt.Fprintln(out, "YES")
    }else {
      fmt.Fprintln(out, "NO")
    }
  }
}

package main

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

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

func main() {
	defer writer.Flush()
	var testcases int
	fmt.Fscanln(reader, &testcases)

	for testcase := 0; testcase < testcases; testcase++ {
		reader.ReadString('\n')
		text, _ := reader.ReadString('\n')
		text = strings.TrimSpace(text)
		if isDistracted([]byte(text)) {
			fmt.Fprintln(writer, "NO")
		} else {
			fmt.Fprintln(writer, "YES")
		}
	}
}

func isDistracted(bts []byte) bool {
	res := false
	board := make(map[byte]bool)
	prev := byte('0')
	for _, curr := range bts {
		if curr != prev {
			_, exists := board[curr]
			if exists {
				return true
			}
		}
		board[curr] = true
		prev = curr
	}
	return res
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var  n int

		fmt.Fscan(r, &n)

		var str string
		fmt.Fscan(r, &str)

		fmt.Println(solve(str))
	}
}

func solve(str string) string {
	mp := make(map[byte]bool)

	var prev byte = str[0]

	for i := 1; i < len(str); i++ {
		b := str[i]

		if _, ok := mp[b]; ok {
			return "NO"
		}

		if b != prev {
			mp[prev] = true
		}

		prev = b
	}

	return "YES"

}

package main

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

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

	var t, n int
	var s string
	fmt.Fscan(in, &t)
MainLoop:
	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		started := make([]bool, 26)
		for i := range s {
			if started[int(s[i]-'A')] && s[i] != s[i-1] {
				fmt.Println("NO")
				continue MainLoop
			}
			started[int(s[i]-'A')] = true
		}

		fmt.Println("YES")
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
var s string
		Fscan(in, &s)
		vis := map[rune]bool{}
		for i, b := range s {
			if vis[b] && s[i] != s[i-1] {
				Fprintln(out, "NO")
				return
			}
			vis[b]=true
		}
		Fprintln(out, "YES")
	}

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

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

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

package main
import (
	"fmt"
	"strings"
	//"os"
)
var n int
var alphabet = []string{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
func main() {
	fmt.Scan(&n)
	//map alphabet
	m:= make(map[string]int)
	for i:=0;i<len(alphabet);i++{
		m[alphabet[i]]= i
	}
	for i:=0;i<n;i++{
		var len int
		fmt.Scan(&len)
		var list []string = make([]string,0,len)
		var str string
		fmt.Scan(&str)
		for k:=0;k<len;k++{
			list = append(list,strings.ToLower(string(str[k])))
		}
		no:=0
		for k:=1;k<len;k++{
			if list[k] == list[k-1]{
				continue
			} else {
				if m[string(list[k])] < m[string(list[k-1])] {
					for l:=0;l<k;l++{
						if list[k] == list[l] {
							no++
							break
						}
					}

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

package main
import (
	"fmt"
	"strings"
	//"os"
)
var n int
var alphabet = []string{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
func main() {
	fmt.Scan(&n)
	//map alphabet
	m:= make(map[string]int)
	for i:=0;i<len(alphabet);i++{
		m[alphabet[i]]= i
	}
	for i:=0;i<n;i++{
		var len int
		fmt.Scan(&len)
		var list []string = make([]string,0,len)
		var str string
		fmt.Scan(&str)
		for k:=0;k<len;k++{
			list = append(list,strings.ToLower(string(str[k])))
		}
		no:=0
		for k:=1;k<len;k++{
			if list[k] == list[k-1]{
				continue
			} else {
				if m[string(list[k])] < m[string(list[k-1])] {
					no++
					break
				}
			}
		}
		if no == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var TestCaseNum int
	var result bool
	var LastCase byte
	fmt.Scanln(&TestCaseNum)
	for i := 0; i < TestCaseNum; i++ {
		var SolveDay int
		var SolveCase []byte
		var SolvedCase []byte

		result = true
		LastCase = 0
		fmt.Scanln(&SolveDay)
		fmt.Scanln(&SolveCase)
		for j := 0; j < SolveDay; j++ {
			if SolveCase[j] == LastCase {
				fmt.Println("Same")
				continue
			} else if CheckContain(SolveCase[j], SolvedCase) {
				fmt.Println("Check Contain")
				result = false
				break
			} else {
				LastCase = SolveCase[j]
				SolvedCase = append(SolvedCase, SolveCase[j])
			}
		}
		if result == false {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

func CheckContain(Checkbyte byte, CheckSlice []byte) bool {
	result := false
	for _, element := range CheckSlice {
		if element == Checkbyte {
			result = true
			break
		}
	}
	return result
}

package main

import (
	"fmt"
)

func main() {
	var (
		t   int
		n   int
		str string
	)
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		fmt.Scanf("%s\n", &str)
		if n == 1 {
			fmt.Println("YES")
		} else {
			var (
				c []string
				q int
			)
			x := string(str[0])
			c = append(c, x)
			for j := 1; j < n; j++ {
				x := string(str[j])
				b := SliceContains(c, x)
				if !b {
					c = append(c, x)
				} else {
					if str[j] != str[j-1] {
						q++
					}
				}
			}
			if q == 0 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

func SliceContains(s []string, e string) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

package main

import(
	"fmt"
	"math"
	"sort"
	// "strconv"
)

func gen(i , j int) int{
	ret := i
	for ;j > 0; j--{
		ret += i * int(math.Pow10(j))
	}

	return ret
}

func main(){
	// generating the map
	library := []int{}

	for i := 1 ; i <= 9 ; i++{
		library = append(library , i)
		for j := 1; j <= 9 ; j++{
			library = append(library , gen(i,j))
		}
	}

	sort.Ints(library)

	var testcases int
	fmt.Scanf("%d\n", &testcases)

	for ; testcases > 0; testcases-- {
		var n int
		fmt.Scanf("%d\n", &n)

		index := sort.SearchInts(library, n)
		if n == library[index]{
			fmt.Println(index + 1)
		}else{
			fmt.Println(index)
		}

	}
}

package main

import "fmt"

func main()  {
	var t, n int
	fmt.Scanf("%d", &t);
	for c := 0; c < t; c++ {
		fmt.Scanf("%d", &n);
		var s string
		ans := "YES"
		fmt.Scanln(&s)
		mp := make(map[uint8]bool)
		for i := 0; i < len(s); i++ {
			res := mp[s[i]]
			if(res != false) {
				ans = "NO"
				break
			} else {
				mp[s[i]] = true
			}
		}
		fmt.Println(ans)
	}

}

package main

import "fmt"

func solve_task(str string) string {
    var last = str[0]
    for i := 1; i < len(str); i++ {
        if str[i] < last {
            return "NO"
        } else {
            last = str[i]
        }
    }
    return "YES"
}

func main() {
    var n_tasks int
    fmt.Scanf("%d\n", &n_tasks)
    for i := 0; i < n_tasks; i++ {
        var strlen int
        var str string
        fmt.Scanln(&strlen)
        fmt.Scanln(&str)
        fmt.Printf("%s\n", solve_task(str))
    }
}

package main

import (
	"fmt"
)

func main1() {
	var N int
	var A string
	var occ []int

	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &A)

	for i := 0; i < 26; i++ {
		occ = append(occ, -1)
	}

	for i := 0; i < N; i++ {
		if occ[A[i] - 'A'] != -1 && occ[A[i] - 'A'] != i - 1 {
			fmt.Printf("NO\n")
			return
		}

		occ[A[i] - 'A'] = i
	}

	fmt.Printf("YES\n")
	return
}

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

	for i := 0; i < T; i++ {
		main1()
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

	fmt.Scanf("%d", &t)
	for t > 0 {
		var str string
		var n int
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &str)

		ok := true
		var vis = map[byte]bool{}
		var i, j int
		for i = 0; i < n; i = j {
			j = i

			for j < n && str[i] == str[j] {
				j++
			}
			if vis[str[i]] {
				ok = false
			}
			vis[str[i]] = true
		}

		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
	}

}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

		var len int
		var taskSolved string
		var res string = "YES\n"
		scanf("%v \n %v \n", &len, &taskSolved)

		solved := make(map[rune]bool)
		for _, char := range taskSolved {
			if solved[char] {
				res = "NO\n"
				break
			}
			solved[char] = true
		}

		printf(res)
	}
}