Pchelyonok decided to give Mila a gift. Pchelenok has already bought an array $$$a$$$ of length $$$n$$$, but gifting an array is too common. Instead of that, he decided to gift Mila the segments of that array!Pchelyonok wants his gift to be beautiful, so he decided to choose $$$k$$$ non-overlapping segments of the array $$$[l_1,r_1]$$$, $$$[l_2,r_2]$$$, $$$\ldots$$$ $$$[l_k,r_k]$$$ such that:  the length of the first segment $$$[l_1,r_1]$$$ is $$$k$$$, the length of the second segment $$$[l_2,r_2]$$$ is $$$k-1$$$, $$$\ldots$$$, the length of the $$$k$$$-th segment $$$[l_k,r_k]$$$ is $$$1$$$  for each $$$i<j$$$, the $$$i$$$-th segment occurs in the array earlier than the $$$j$$$-th (i.e. $$$r_i<l_j$$$)  the sums in these segments are strictly increasing (i.e. let $$$sum(l \ldots r) = \sum\limits_{i=l}^{r} a_i$$$ — the sum of numbers in the segment $$$[l,r]$$$ of the array, then $$$sum(l_1 \ldots r_1) < sum(l_2 \ldots r_2) < \ldots < sum(l_k \ldots r_k)$$$). Pchelenok also wants his gift to be as beautiful as possible, so he asks you to find the maximal value of $$$k$$$ such that he can give Mila a gift!

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain the descriptions of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print the maximum possible value of $$$k$$$.

package main

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

const MAXK = 500

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || (dp[i-j][j-1] > 0 && presum[i]-presum[i-j] < dp[i-j][j-1])) && (presum[i]-presum[i-j] > dp[i-1][j]) {
					dp[i][j] = presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main
import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)
/*
题意：从数组中获取若干不相交的子数组，要求子数组长度以1递减、和递增，求最大的子数组个数。

设f(i)为a[i:]的解。从i开始往右取（或不取）j个元素，分割成 子数组a[i:i+j] 和 子问题f(i+j)，
由于子数组的和递增，那么用贪心策略，下一个子数组的和最大时子数组个数最大，
所以定义f(i,j)为“考虑a[i:]、长度为j的子数组的最大和”
f(i,j)>0表示第一个子数组可以与后续子数组形成和递增，分成j个成立，所以答案为f(0,j)>0时最大的j。
*/
var sc *bufio.Scanner
func max(a,b int)int{if a>b{return a};return b}
func I()int{sc.Scan();v,_:=strconv.Atoi(sc.Text());return v}
func main(){
  inp,out:=os.Stdin,os.Stdout
  sc=bufio.NewScanner(inp);W:=bufio.NewWriter(out);sc.Split(bufio.ScanWords);defer W.Flush()

  t:=I();inf:=int(1e9)+7
  for i:=0;i<t;i++{
    n:=I();a,p:=make([]int,n+1),make([]int,n+1);k,z:=0,0
    for (k+1)*k/2<=n{k++}
    for j:=0;j<n;j++{v:=I();a[j]=v;p[j+1]=p[j]+v}
    f:=make([][]int,n+1);for i:=range f{f[i]=make([]int,k)};f[n][0]=inf
    for j:=1;j<k;j++{f[n][j]=-inf}
    for i:=n-1;i>=0;i--{for j:=0;j<k;j++{
      f[i][j]=f[i+1][j]
      if j>0 && i+j<=n && p[i+j]-p[i]<f[i+j][j-1]{
        f[i][j]=max(f[i][j],p[i+j]-p[i])
      }
      if f[0][j]>0{z=j}
    }}
    fmt.Fprintln(W,z)
  }
}

package main
import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)
/*
题意：从数组中获取若干不相交的子数组，要求子数组长度以1递减、和递增，求最大的子数组个数。

设f(i)为a[i:]的解。从i开始往右取（或不取）j个元素，分割成 子数组a[i:i+j] 和 子问题f(i+j)，
由于子数组的和递增，那么用贪心策略，下一个子数组的和最大时子数组个数最大，
所以定义f(i,j)为“考虑a[i:]、长度为j的子数组的最大和”
*/
var sc *bufio.Scanner
func max(a,b int)int{if a>b{return a};return b}
func I()int{sc.Scan();v,_:=strconv.Atoi(sc.Text());return v}
func main(){
  inp,out:=os.Stdin,os.Stdout
  sc=bufio.NewScanner(inp);W:=bufio.NewWriter(out);sc.Split(bufio.ScanWords);defer W.Flush()

  t:=I();inf:=int(1e9)+7
  for i:=0;i<t;i++{
    n:=I();a,p:=make([]int,n+1),make([]int,n+1);k,z:=0,0
    for (k+1)*k/2<=n{k++}
    for j:=0;j<n;j++{v:=I();a[j]=v;p[j+1]=p[j]+v}
    f:=make([][]int,n+1);for i:=range f{f[i]=make([]int,k)};f[n][0]=inf
    for j:=1;j<k;j++{f[n][j]=-inf}
    for i:=n-1;i>=0;i--{for j:=0;j<k;j++{
      f[i][j]=f[i+1][j]
      if j>0 && i+j<=n && p[i+j]-p[i]<f[i+j][j-1]{
        f[i][j]=max(f[i][j],p[i+j]-p[i])
      }
      if f[0][j]>0{z=j}
    }}
    fmt.Fprintln(W,z)
  }
}

package main
import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)
var sc *bufio.Scanner
func max(a,b int)int{if a>b{return a};return b}
func I()int{sc.Scan();v,_:=strconv.Atoi(sc.Text());return v}
func main(){
  inp,out:=os.Stdin,os.Stdout
  sc=bufio.NewScanner(inp);W:=bufio.NewWriter(out);sc.Split(bufio.ScanWords);defer W.Flush()

  t:=I();inf:=int(1e9)+7
  for i:=0;i<t;i++{
    n:=I();a,p:=make([]int,n+1),make([]int,n+1);k,z:=0,0
    for (k+1)*k/2<=n{k++}
    for j:=0;j<n;j++{v:=I();a[j]=v;p[j+1]=p[j]+v}
    f:=make([][]int,n+1);for i:=range f{f[i]=make([]int,k)};f[n][0]=inf
    for j:=1;j<k;j++{f[n][j]=-inf}
    for i:=n-1;i>=0;i--{for j:=0;j<k;j++{
      f[i][j]=f[i+1][j]
      if j>0 && i+j<=n && p[i+j]-p[i]<f[i+j][j-1]{
        f[i][j]=max(f[i][j],p[i+j]-p[i])
      }
      if f[0][j]>0{z=j}
    }}
    fmt.Fprintln(W,z)
  }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1582E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		suf := make([]int64, n+1)
		for i := n - 1; i >= 0; i-- {
			suf[i] = max(suf[i+1], a[i])
			a[i] += a[i+1]
		}
		suf2 := make([]int64, n)
		k := 2
		for l := n - 1; l >= k; l -= k - 1 {
			suf2[l-k+1] = 0
			for i := l - k; i >= 0; i-- {
				s := a[i] - a[i+k]
				if suf2[i+1] < s && s < suf[i+k] {
					suf2[i] = s
				} else {
					suf2[i] = suf2[i+1]
				}
			}
			if suf2[0] == 0 {
				break
			}
			suf, suf2 = suf2, suf
			k++
		}
		Fprintln(out, k-1)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1582E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		suf := make([]int64, n+1)
		for i := n - 1; i >= 0; i-- {
			suf[i] = max(suf[i+1], a[i])
			a[i] += a[i+1]
		}
		suf2 := make([]int64, n)
		k := 2
		for l := n - 1; l >= k; l -= k - 1 {
			suf2[l-k+1] = 0
			for i := l - k; i >= 0; i-- {
				s := a[i] - a[i+k]
				if suf2[i+1] < s && s < suf[i+k] {
					suf2[i] = s
				} else {
					suf2[i] = suf2[i+1]
				}
			}
			if suf2[0] == 0 {
				break
			}
			suf, suf2 = suf2, suf
			k++
		}
		Fprintln(out, k-1)
	}
}

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

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

package main

import (
    "bufio"
    "bytes"
    "fmt"
    "io"
    "math"
    "os"
    "path"
    "runtime"
    "sort"
    "strings"
    "time"
)

/**
https://codeforces.com/contest/1582/problem/e

输入 t(t≤100) 表示 t 组数据。
每组数据输入 n(1≤n≤1e5) 和长为 n 的整数数组 a (1≤a[i]≤1e9)，所有数据的 n 之和不超过 1e5。

从 a 中选尽可能多的互不相交的子数组，设有 k 个子数组，需满足：
1. 从左到右第一个子数组的长度恰好是 k，第二个的长度恰好是 k-1，……，最后一个的长度恰好是 1；
2. 从左到右第 i 个子数组的元素和严格小于第 i+1 个子数组的元素和。
输出 k 的最大值。

注：子数组是连续的。
*/

func main() {
    StdIO(func(fio *fastIO) { cf1582e(fio) })
    // CaseIO(func(fio *fastIO) { cf1582e(fio) })
}

func cf1582e(fio *fastIO) {
    T := fio.r1i()
    for I := 0; I < T; I++ {
        n := fio.r1i()
        a := make([]int, n)
        s := make([]int64, n+1)
        for i := n - 1; i >= 0; i-- {
            a[i] = fio.r1i() // 将数组a逆序，方便处理
        }
        for i := 0; i < n; i++ {
            s[i+1] = s[i] + int64(a[i])
        }
        mak := int(math.Sqrt(float64(n << 1)))
        if mak*(mak+1) > n<<1 {
            mak--
        }
        if mak == 1 {
            fio.wln(1)
        } else {
            // dp[k][i]表示前i个元素选出k个子数组，第k个子数组的元素和的最大值
            // 根据是否选择第i个元素作为第k个子数组的末尾元素进行状态转移
            // 如果不选择，则最大值dp[k][i-1]；如果选择，且满足s[j]-s[j-i] < dp[k-1]，则最大值为s[j]-s[j-i]
            // 空间优化：使用滚动数组优化掉第一个维度
            dp := make([]int64, n+1)
            prev := make([]int64, n+1)
            for i := 1; i <= n; i++ {
                prev[i] = Max(prev[i-1], int64(a[i-1]))
            }
            k := 2
            for ; k <= mak; k++ {
                start := (k * (k + 1)) >> 1
                dp[start-1] = 0
                for i := start; i <= n; i++ {
                    if v := s[i] - s[i-k]; v < prev[i-k] && v > dp[i-1] {
                        dp[i] = v
                    } else {
                        dp[i] = dp[i-1]
                    }
                }
                if dp[n] == 0 {
                    break
                }
                prev, dp = dp, prev
            }
            fio.wln(k - 1)
        }
    }
}

// ================== utils ==================

type _integer_ interface {
    ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int8 | ~int16 | ~int32 | ~int64 | ~int | ~uint
}

type _float_ interface {
    ~float32 | ~float64
}

type _number_ interface {
    _integer_ | _float_
}

type _ordered_ interface {
    _number_ | ~string
}

func _select_[T _ordered_](f func(x, t T) bool, ts ...T) T {
    n := len(ts)
    if n == 0 {
        panic("At Least One Argument")
    } else {
        x := ts[0]
        for i := 1; i < n; i++ {
            if f(x, ts[i]) {
                x = ts[i]
            }
        }
        return x
    }
}

func Max[T _ordered_](ts ...T) T {
    return _select_(func(x, t T) bool { return x < t }, ts...)
}
func Min[T _ordered_](ts ...T) T {
    return _select_(func(x, t T) bool { return x > t }, ts...)
}
func SumI[T _integer_](ts []T) (sum uint64) {
    for _, t := range ts {
        sum += uint64(t)
    }
    return
}
func SumF[T _float_](ts []T) (sum float64) {
    for _, t := range ts {
        sum += float64(t)
    }
    return
}
func SortASC[T _ordered_](ts []T) {
    sort.Slice(ts, func(i, j int) bool { return ts[i] < ts[j] })
}
func SortDESC[T _ordered_](ts []T) {
    sort.Slice(ts, func(i, j int) bool { return ts[i] > ts[j] })
}

func InitSlice[T _ordered_ | bool](n int, v T) []T {
    arr := make([]T, n)
    for i := range arr {
        arr[i] = v
    }
    return arr
}

// InitSlice2 M * N
func InitSlice2[T _ordered_ | bool](m, n int, v T) [][]T {
    arr := make([][]T, m)
    for i := range arr {
        arr[i] = InitSlice(n, v)
    }
    return arr
}

func MakeSlice2[T any](m, n int) [][]T {
    arr := make([][]T, m)
    for i := range arr {
        arr[i] = make([]T, n)
    }
    return arr
}

// InitSlice3 L * M * N
func InitSlice3[T _ordered_ | bool](l, m, n int, v T) [][][]T {
    arr := make([][][]T, l)
    for i := range arr {
        arr[i] = InitSlice2(m, n, v)
    }
    return arr
}

func MakeSlice3[T any](l, m, n int) [][][]T {
    arr := make([][][]T, l)
    for i := range arr {
        arr[i] = MakeSlice2[T](m, n)
    }
    return arr
}

func b2i[T _integer_](b bool) T {
    if b {
        return 1
    } else {
        return 0
    }
}

// ================== fastIO ==================

// StdIO 标准输入输出，用于提交
func StdIO(f func(fio *fastIO)) {
    fio := newFastIO(os.Stdin, os.Stdout)
    f(fio)
    fio.flush()
}

// CaseIO 测试用例文件输入输出，用于测试，不支持多种答案的情况
// 读入`main`函数文件同目录的`inputs.txt`文件中的测试用例进行测试，文件格式参考`datafiles/inputs.txt`
func CaseIO(f func(fio *fastIO)) {
    _, file, _, _ := runtime.Caller(0)
    inputs, _ := os.Open(path.Dir(file) + "/inputs.txt")
    all, _ := io.ReadAll(inputs)
    buf := new(bytes.Buffer)
    pass := true
    for i, testcase := range strings.Split(string(all), "input\n")[1:] {
        items := strings.Split(testcase, "\noutput\n")
        input, expect := items[0], items[1]
        if expect[len(expect)-1] != '\n' {
            expect += "\n"
        }
        fmt.Printf("=== RUN   CASE %d\n", i+1)
        start := time.Now().UnixMilli()
        fio := newFastIO(strings.NewReader(input), buf)
        f(fio)
        fio.flush()
        cost := time.Now().UnixMilli() - start
        answer := buf.String()
        if expect == answer {
            fmt.Printf("--- PASS: CASE %d (%dms)\n", i+1, cost)
        } else {
            pass = false
            fmt.Printf("--- FAIL: CASE %d (%dms)\n[EXPECT]:\n%v[ANSWER]:\n%v", i+1, cost, expect, answer)
        }
        buf.Reset()
    }
    if pass {
        fmt.Printf("\nPASS\n")
    } else {
        fmt.Printf("\nFAIL\n")
    }
}

type fastIO struct {
    reader io.Reader
    writer io.Writer
    out    *bufio.Writer
    buf    []byte // 4KB
    i, n   int
}

func newFastIO(reader io.Reader, writer io.Writer) *fastIO {
    return &fastIO{reader: reader, writer: writer, out: bufio.NewWriter(writer), buf: make([]byte, 1<<12)}
}

// 读取整数
func (f *fastIO) r1i() int             { return fioR1(f.ri) }
func (f *fastIO) r2i() (int, int)      { return fioR2(f.r1i) }
func (f *fastIO) r3i() (int, int, int) { return fioR3(f.r1i) }
func (f *fastIO) rni(n int) []int      { return fioRn(n, f.r1i) }
func (f *fastIO) rxi() (nums []int)    { return fioRx(f.ri) }

func (f *fastIO) rnimms(n int) (min, max int, sum uint64)   { return fioRnMMS(n, f.r1i) }
func (f *fastIO) rximms() (n int, min, max int, sum uint64) { return fioRxMMS(f.ri) }

func (f *fastIO) r1i64() int64                 { return fioR1(f.ri64) }
func (f *fastIO) r2i64() (int64, int64)        { return fioR2(f.r1i64) }
func (f *fastIO) r3i64() (int64, int64, int64) { return fioR3(f.r1i64) }
func (f *fastIO) rni64(n int) []int64          { return fioRn(n, f.r1i64) }
func (f *fastIO) rxi64() (nums []int64)        { return fioRx(f.ri64) }

func (f *fastIO) rni64mms(n int) (min, max int64, sum uint64)   { return fioRnMMS(n, f.r1i64) }
func (f *fastIO) rxi64mms() (n int, min, max int64, sum uint64) { return fioRxMMS(f.ri64) }

// 读取字符串
func (f *fastIO) r1s() []byte                   { return fioR1(f.rs) }
func (f *fastIO) r2s() ([]byte, []byte)         { return fioR2(f.r1s) }
func (f *fastIO) r3s() ([]byte, []byte, []byte) { return fioR3(f.r1s) }
func (f *fastIO) rns(n int) [][]byte            { return fioRn(n, f.r1s) }
func (f *fastIO) rxs() (strs [][]byte)          { return fioRx(f.rs) }

// 输出
func (f *fastIO) w(a ...any)                 { f.panic(fmt.Fprint(f.out, a...)) }
func (f *fastIO) wf(format string, a ...any) { f.panic(fmt.Fprintf(f.out, format, a...)) }
func (f *fastIO) wln(a ...any)               { f.panic(fmt.Fprintln(f.out, a...)) }
func (f *fastIO) flush()                     { f.panic(f.out.Flush()) }

// 尝试读取一个字符
func (f *fastIO) rc() (b byte, err error) {
    if f.i == f.n {
        f.i = 0
        if f.n, _ = f.reader.Read(f.buf); f.n == 0 {
            return 0, io.EOF
        }
    }
    b = f.buf[f.i]
    f.i++
    return
}

// 尝试读取一个整数（包括负数）
func (f *fastIO) ri() (x int, err error)     { return fioRi[int](f.rc) }
func (f *fastIO) ri64() (x int64, err error) { return fioRi[int64](f.rc) }

func fioRi[T _integer_](f func() (byte, error)) (x T, err error) {
    var b byte
    negative := false
    for b, err = f(); err == nil && !isDigit(b); b, err = f() {
        if b == '-' {
            negative = true
        }
    }
    if err != nil {
        return 0, err
    } else {
        x = T(b & 15)
        for b, _ = f(); isDigit(b); b, _ = f() {
            x = x*10 + T(b&15)
        }
        if negative {
            x = -x
        }
        return
    }
}

// 空白字符
var _ioWs = map[byte]bool{' ': true, '\n': true, '\r': true, '\t': true, '\v': true, '\f': true}

// 尝试读取一个被空白字符分隔的字符串
func (f *fastIO) rs() ([]byte, error) {
    b, err := f.rc()
    for ; err == nil && _ioWs[b]; b, err = f.rc() {
    }
    if err != nil {
        return nil, err
    } else {
        chars := []byte{b}
        for b, err = f.rc(); err == nil && !_ioWs[b]; b, err = f.rc() {
            chars = append(chars, b)
        }
        return chars, nil
    }
}

func isDigit(b byte) bool    { return '0' <= b && b <= '9' }
func isUpper(b byte) bool    { return 'A' <= b && b <= 'Z' }
func isLower(b byte) bool    { return 'a' <= b && b <= 'z' }
func isAlphabet(b byte) bool { return isLower(b) || isUpper(b) }

func fioPanic[T _number_ | []byte](x T, err any) T {
    if err != nil {
        panic(err)
    }
    return x
}

func fioR1[T _number_ | []byte](f func() (T, error)) T { return fioPanic(f()) }
func fioR2[T _number_ | []byte](f func() T) (T, T)     { return f(), f() }
func fioR3[T _number_ | []byte](f func() T) (T, T, T)  { return f(), f(), f() }
func fioRn[T _number_ | []byte](n int, f func() T) []T {
    arr := make([]T, n)
    for i := range arr {
        arr[i] = f()
    }
    return arr
}
func fioRx[T _number_ | []byte](f func() (T, error)) (arr []T) {
    for t, err := f(); err == nil; t, err = f() {
        arr = append(arr, t)
    }
    return
}
func fioRnMMS[T _integer_](n int, f func() T) (min, max T, sum uint64) {
    min = f()
    max, sum = min, uint64(min)
    for i := 1; i < n; i++ {
        t := f()
        sum += uint64(t)
        min, max = fioMinMax(min, max, t)
    }
    return
}
func fioRxMMS[T _integer_](f func() (T, error)) (n int, min, max T, sum uint64) {
    if t, err := f(); err == nil {
        n, min, max, sum = 0, t, t, uint64(t)
        for t, err = f(); err == nil; t, err = f() {
            n++
            sum += uint64(t)
            min, max = fioMinMax(min, max, t)
        }
    }
    return
}
func fioMinMax[T _number_](min, max, t T) (T, T) {
    if min > t {
        min = t
    } else if max < t {
        max = t
    }
    return min, max
}

func (fastIO) panic(a ...any) {
    n := len(a)
    if err := a[n-1]; err != nil {
        panic(err)
    }
}

package main

import (
    "bufio"
    "bytes"
    "fmt"
    "io"
    "math"
    "os"
    "path"
    "runtime"
    "sort"
    "strings"
    "time"
)

/**
https://codeforces.com/contest/1582/problem/e

输入 t(t≤100) 表示 t 组数据。
每组数据输入 n(1≤n≤1e5) 和长为 n 的整数数组 a (1≤a[i]≤1e9)，所有数据的 n 之和不超过 1e5。

从 a 中选尽可能多的互不相交的子数组，设有 k 个子数组，需满足：
1. 从左到右第一个子数组的长度恰好是 k，第二个的长度恰好是 k-1，……，最后一个的长度恰好是 1；
2. 从左到右第 i 个子数组的元素和严格小于第 i+1 个子数组的元素和。
输出 k 的最大值。

注：子数组是连续的。
*/

func main() {
    StdIO(func(fio *fastIO) { cf1582e(fio) })
    // CaseIO(func(fio *fastIO) { cf1582e(fio) })
}

func cf1582e(fio *fastIO) {
    T := fio.r1i()
    for I := 0; I < T; I++ {
        n := fio.r1i()
        a := make([]int, n)
        s := make([]int64, n+1)
        for i := n - 1; i >= 0; i-- {
            a[i] = fio.r1i() // 将数组a逆序，方便处理
        }
        for i := 0; i < n; i++ {
            s[i+1] = s[i] + int64(a[i])
        }
        mak := int(math.Sqrt(float64(n << 1)))
        if mak*(mak+1) > n<<1 {
            mak--
        }
        if mak == 1 {
            fio.wln(1)
        } else {
            // dp[k][i]表示前i个元素选出k个子数组，第k个子数组的元素和的最大值
            // 根据是否选择第i个元素作为第k个子数组的末尾元素进行状态转移
            // 如果不选择，则最大值dp[k][i-1]；如果选择，且满足s[j]-s[j-i] < dp[k-1]，则最大值为s[j]-s[j-i]
            // 空间优化：使用滚动数组优化掉第一个维度
            dp := make([]int64, n+1)
            prev := make([]int64, n+1)
            for i := 1; i <= n; i++ {
                prev[i] = Max(prev[i-1], int64(a[i-1]))
            }
            k := 2
            for ; k <= mak; k++ {
                start := (k * (k + 1)) >> 1
                dp[start-1] = 0
                for i := start; i <= n; i++ {
                    if v := s[i] - s[i-k]; v < prev[i-k] {
                        dp[i] = Max(dp[i-1], v)
                    } else {
                        dp[i] = dp[i-1]
                    }
                }
                if dp[n] == 0 {
                    break
                }
                prev, dp = dp, prev
            }
            fio.wln(k - 1)
        }
    }
}

// ================== utils ==================

type _integer_ interface {
    ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int8 | ~int16 | ~int32 | ~int64 | ~int | ~uint
}

type _float_ interface {
    ~float32 | ~float64
}

type _number_ interface {
    _integer_ | _float_
}

type _ordered_ interface {
    _number_ | ~string
}

func _select_[T _ordered_](f func(x, t T) bool, ts ...T) T {
    n := len(ts)
    if n == 0 {
        panic("At Least One Argument")
    } else {
        x := ts[0]
        for i := 1; i < n; i++ {
            if f(x, ts[i]) {
                x = ts[i]
            }
        }
        return x
    }
}

func Max[T _ordered_](ts ...T) T {
    return _select_(func(x, t T) bool { return x < t }, ts...)
}
func Min[T _ordered_](ts ...T) T {
    return _select_(func(x, t T) bool { return x > t }, ts...)
}
func SumI[T _integer_](ts []T) (sum uint64) {
    for _, t := range ts {
        sum += uint64(t)
    }
    return
}
func SumF[T _float_](ts []T) (sum float64) {
    for _, t := range ts {
        sum += float64(t)
    }
    return
}
func SortASC[T _ordered_](ts []T) {
    sort.Slice(ts, func(i, j int) bool { return ts[i] < ts[j] })
}
func SortDESC[T _ordered_](ts []T) {
    sort.Slice(ts, func(i, j int) bool { return ts[i] > ts[j] })
}

func InitSlice[T _ordered_ | bool](n int, v T) []T {
    arr := make([]T, n)
    for i := range arr {
        arr[i] = v
    }
    return arr
}

// InitSlice2 M * N
func InitSlice2[T _ordered_ | bool](m, n int, v T) [][]T {
    arr := make([][]T, m)
    for i := range arr {
        arr[i] = InitSlice(n, v)
    }
    return arr
}

func MakeSlice2[T any](m, n int) [][]T {
    arr := make([][]T, m)
    for i := range arr {
        arr[i] = make([]T, n)
    }
    return arr
}

// InitSlice3 L * M * N
func InitSlice3[T _ordered_ | bool](l, m, n int, v T) [][][]T {
    arr := make([][][]T, l)
    for i := range arr {
        arr[i] = InitSlice2(m, n, v)
    }
    return arr
}

func MakeSlice3[T any](l, m, n int) [][][]T {
    arr := make([][][]T, l)
    for i := range arr {
        arr[i] = MakeSlice2[T](m, n)
    }
    return arr
}

func b2i[T _integer_](b bool) T {
    if b {
        return 1
    } else {
        return 0
    }
}

// ================== fastIO ==================

// StdIO 标准输入输出，用于提交
func StdIO(f func(fio *fastIO)) {
    fio := newFastIO(os.Stdin, os.Stdout)
    f(fio)
    fio.flush()
}

// CaseIO 测试用例文件输入输出，用于测试，不支持多种答案的情况
// 读入`main`函数文件同目录的`inputs.txt`文件中的测试用例进行测试，文件格式参考`datafiles/inputs.txt`
func CaseIO(f func(fio *fastIO)) {
    _, file, _, _ := runtime.Caller(0)
    inputs, _ := os.Open(path.Dir(file) + "/inputs.txt")
    all, _ := io.ReadAll(inputs)
    buf := new(bytes.Buffer)
    pass := true
    for i, testcase := range strings.Split(string(all), "input\n")[1:] {
        items := strings.Split(testcase, "\noutput\n")
        input, expect := items[0], items[1]
        if expect[len(expect)-1] != '\n' {
            expect += "\n"
        }
        fmt.Printf("=== RUN   CASE %d\n", i+1)
        start := time.Now().UnixMilli()
        fio := newFastIO(strings.NewReader(input), buf)
        f(fio)
        fio.flush()
        cost := time.Now().UnixMilli() - start
        answer := buf.String()
        if expect == answer {
            fmt.Printf("--- PASS: CASE %d (%dms)\n", i+1, cost)
        } else {
            pass = false
            fmt.Printf("--- FAIL: CASE %d (%dms)\n[EXPECT]:\n%v[ANSWER]:\n%v", i+1, cost, expect, answer)
        }
        buf.Reset()
    }
    if pass {
        fmt.Printf("\nPASS\n")
    } else {
        fmt.Printf("\nFAIL\n")
    }
}

type fastIO struct {
    reader io.Reader
    writer io.Writer
    out    *bufio.Writer
    buf    []byte // 4KB
    i, n   int
}

func newFastIO(reader io.Reader, writer io.Writer) *fastIO {
    return &fastIO{reader: reader, writer: writer, out: bufio.NewWriter(writer), buf: make([]byte, 1<<12)}
}

// 读取整数
func (f *fastIO) r1i() int             { return fioR1(f.ri) }
func (f *fastIO) r2i() (int, int)      { return fioR2(f.r1i) }
func (f *fastIO) r3i() (int, int, int) { return fioR3(f.r1i) }
func (f *fastIO) rni(n int) []int      { return fioRn(n, f.r1i) }
func (f *fastIO) rxi() (nums []int)    { return fioRx(f.ri) }

func (f *fastIO) rnimms(n int) (min, max int, sum uint64)   { return fioRnMMS(n, f.r1i) }
func (f *fastIO) rximms() (n int, min, max int, sum uint64) { return fioRxMMS(f.ri) }

func (f *fastIO) r1i64() int64                 { return fioR1(f.ri64) }
func (f *fastIO) r2i64() (int64, int64)        { return fioR2(f.r1i64) }
func (f *fastIO) r3i64() (int64, int64, int64) { return fioR3(f.r1i64) }
func (f *fastIO) rni64(n int) []int64          { return fioRn(n, f.r1i64) }
func (f *fastIO) rxi64() (nums []int64)        { return fioRx(f.ri64) }

func (f *fastIO) rni64mms(n int) (min, max int64, sum uint64)   { return fioRnMMS(n, f.r1i64) }
func (f *fastIO) rxi64mms() (n int, min, max int64, sum uint64) { return fioRxMMS(f.ri64) }

// 读取字符串
func (f *fastIO) r1s() []byte                   { return fioR1(f.rs) }
func (f *fastIO) r2s() ([]byte, []byte)         { return fioR2(f.r1s) }
func (f *fastIO) r3s() ([]byte, []byte, []byte) { return fioR3(f.r1s) }
func (f *fastIO) rns(n int) [][]byte            { return fioRn(n, f.r1s) }
func (f *fastIO) rxs() (strs [][]byte)          { return fioRx(f.rs) }

// 输出
func (f *fastIO) w(a ...any)                 { f.panic(fmt.Fprint(f.out, a...)) }
func (f *fastIO) wf(format string, a ...any) { f.panic(fmt.Fprintf(f.out, format, a...)) }
func (f *fastIO) wln(a ...any)               { f.panic(fmt.Fprintln(f.out, a...)) }
func (f *fastIO) flush()                     { f.panic(f.out.Flush()) }

// 尝试读取一个字符
func (f *fastIO) rc() (b byte, err error) {
    if f.i == f.n {
        f.i = 0
        if f.n, _ = f.reader.Read(f.buf); f.n == 0 {
            return 0, io.EOF
        }
    }
    b = f.buf[f.i]
    f.i++
    return
}

// 尝试读取一个整数（包括负数）
func (f *fastIO) ri() (x int, err error)     { return fioRi[int](f.rc) }
func (f *fastIO) ri64() (x int64, err error) { return fioRi[int64](f.rc) }

func fioRi[T _integer_](f func() (byte, error)) (x T, err error) {
    var b byte
    negative := false
    for b, err = f(); err == nil && !isDigit(b); b, err = f() {
        if b == '-' {
            negative = true
        }
    }
    if err != nil {
        return 0, err
    } else {
        x = T(b & 15)
        for b, _ = f(); isDigit(b); b, _ = f() {
            x = x*10 + T(b&15)
        }
        if negative {
            x = -x
        }
        return
    }
}

// 空白字符
var _ioWs = map[byte]bool{' ': true, '\n': true, '\r': true, '\t': true, '\v': true, '\f': true}

// 尝试读取一个被空白字符分隔的字符串
func (f *fastIO) rs() ([]byte, error) {
    b, err := f.rc()
    for ; err == nil && _ioWs[b]; b, err = f.rc() {
    }
    if err != nil {
        return nil, err
    } else {
        chars := []byte{b}
        for b, err = f.rc(); err == nil && !_ioWs[b]; b, err = f.rc() {
            chars = append(chars, b)
        }
        return chars, nil
    }
}

func isDigit(b byte) bool    { return '0' <= b && b <= '9' }
func isUpper(b byte) bool    { return 'A' <= b && b <= 'Z' }
func isLower(b byte) bool    { return 'a' <= b && b <= 'z' }
func isAlphabet(b byte) bool { return isLower(b) || isUpper(b) }

func fioPanic[T _number_ | []byte](x T, err any) T {
    if err != nil {
        panic(err)
    }
    return x
}

func fioR1[T _number_ | []byte](f func() (T, error)) T { return fioPanic(f()) }
func fioR2[T _number_ | []byte](f func() T) (T, T)     { return f(), f() }
func fioR3[T _number_ | []byte](f func() T) (T, T, T)  { return f(), f(), f() }
func fioRn[T _number_ | []byte](n int, f func() T) []T {
    arr := make([]T, n)
    for i := range arr {
        arr[i] = f()
    }
    return arr
}
func fioRx[T _number_ | []byte](f func() (T, error)) (arr []T) {
    for t, err := f(); err == nil; t, err = f() {
        arr = append(arr, t)
    }
    return
}
func fioRnMMS[T _integer_](n int, f func() T) (min, max T, sum uint64) {
    min = f()
    max, sum = min, uint64(min)
    for i := 1; i < n; i++ {
        t := f()
        sum += uint64(t)
        min, max = fioMinMax(min, max, t)
    }
    return
}
func fioRxMMS[T _integer_](f func() (T, error)) (n int, min, max T, sum uint64) {
    if t, err := f(); err == nil {
        n, min, max, sum = 0, t, t, uint64(t)
        for t, err = f(); err == nil; t, err = f() {
            n++
            sum += uint64(t)
            min, max = fioMinMax(min, max, t)
        }
    }
    return
}
func fioMinMax[T _number_](min, max, t T) (T, T) {
    if min > t {
        min = t
    } else if max < t {
        max = t
    }
    return min, max
}

func (fastIO) panic(a ...any) {
    n := len(a)
    if err := a[n-1]; err != nil {
        panic(err)
    }
}

package main

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

/*
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    a = a[::-1]
    pre = [0] + list(accumulate(a))
    k = int((n * 2) ** 0.5) + 1
    f = [[0] * (k + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        f[i][1] = max(f[i - 1][1], a[i - 1])

    res = 1
    for i in range(2, n + 1):
        for j in range(2, k + 1):
            f[i][j] = f[i - 1][j]
            if i < j * (j + 1) // 2: break
            v = pre[i] - pre[i - j]
            if f[i - j][j - 1] > v:
                res = max(res, j)
                f[i][j] = max(f[i][j], v)
    print(res)
*/

// https://codeforces.com/contest/1582/submission/167714541
func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int
	Fscan(in, &t)

	for ; t > 0; t-- {
		Fscan(in, &n)

		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[n-i+1])
		}

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

		var ans int64 = 1
		dp := make([][]int64, n+1)

		k := int(math.Sqrt(float64(2* n)) + 1)
		for i := 0; i <= n; i++ {
			dp[i] = make([]int64, k+1)
			if i == 0 { continue }
			dp[i][1] = max(dp[i-1][1],a[i])
		}

		for i := 2; i <= n; i++ {
			for j := 2; j <= k; j++ {
				dp[i][j] = dp[i-1][j]
				if i < j*(j+1)/2 {
					break
				}
				v := pre[i] - pre[i-j]
				if dp[i-j][j-1] > v {
					ans = max(ans, int64(j))
					dp[i][j] = max(dp[i][j], v)
				}
			}
		}
		Fprintln(out, ans)
	}
}

func max(x, y int64) int64 { if x > y { return x } else { return y }}
func main() { Solve(os.Stdin, os.Stdout) }

package main

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

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

func CF1582E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &n)
		a := make([]int64, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		suf := make([]int64, n+1)
		for i := n - 1; i >= 0; i-- {
			suf[i] = max(suf[i+1], a[i])
			a[i] += a[i+1]
		}
		suf2 := make([]int64, n)
		k := 2
		for l := n - 1; l >= k; l -= k - 1 {
			suf2[l-k+1] = 0
			for i := l - k; i >= 0; i-- {
				s := a[i] - a[i+k]
				if suf2[i+1] < s && s < suf[i+k] {
					suf2[i] = s
				} else {
					suf2[i] = suf2[i+1]
				}
			}
			if suf2[0] == 0 {
				break
			}
			suf, suf2 = suf2, suf
			k++
		}
		fmt.Fprintln(out, k-1)
	}
}

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

package main

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

const MAXK = 350

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || (dp[i-j][j-1] > 0 && presum[i]-presum[i-j] < dp[i-j][j-1])) && (presum[i]-presum[i-j] > dp[i-1][j]) {
					dp[i][j] = presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

const MAXK = 230

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || (dp[i-j][j-1] > 0 && presum[i]-presum[i-j] < dp[i-j][j-1])) && (presum[i]-presum[i-j] > dp[i-1][j]) {
					dp[i][j] = presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

const MAXK = 230

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || (dp[i-j][j-1] > 0 && presum[i]-presum[i-j] < dp[i-j][j-1])) && (presum[i]-presum[i-j] > dp[i-1][j]) {
					dp[i][j] = presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	in, _ := os.Open("input.txt")
	// in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

const MAXK = 230

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || dp[i-j][j-1] > 0) && (j == 1 || presum[i]-presum[i-j] < dp[i-j][j-1]) {
					dp[i][j] = presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

const MAXK = 230

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || dp[i-j][j-1] > 0) && dp[i-j][j-1]+presum[i]-presum[i-j] > dp[i][j] && (j == 1 || presum[i]-presum[i-j] < dp[i-j][j-1]) {
					dp[i][j] = presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

const MAXK = 230

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int64, n+1)
		dp[0] = make([]int64, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int64, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || dp[i-j][j-1] > 0) && dp[i-j][j-1]+presum[i]-presum[i-j] > dp[i][j] && (j == 1 || presum[i]-presum[i-j] < dp[i-j][j-1]) {
					dp[i][j] = dp[i-j][j-1] + presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

const MAXK = 230

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

func CF1582E(read io.Reader, write io.Writer) {
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[n-i-1])
		}
		presum := make([]int, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + nums[i-1]
		}

		dp := make([][]int, n+1)
		dp[0] = make([]int, MAXK)
		maxk := 0
		for i := 1; i <= n; i++ {
			dp[i] = make([]int, MAXK)
			for j := 1; j <= MAXK-1; j++ {
				dp[i][j] = dp[i-1][j]
				if i >= j && (j == 1 || dp[i-j][j-1] > 0) && dp[i-j][j-1]+presum[i]-presum[i-j] > dp[i][j] && (j == 1 || presum[i]-presum[i-j] < dp[i-j][j-1]) {
					dp[i][j] = dp[i-j][j-1] + presum[i] - presum[i-j]
				}
				if dp[i][j] > 0 {
					maxk = max(maxk, j)
				}
			}
		}
		fmt.Fprintln(out, maxk)
	}
}

func main() {
	// in, _ := os.Open("input.txt")
	in := os.Stdin
	CF1582E(in, os.Stdout)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1582E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		suf := make([]int64, n+1)
		for i := n - 1; i >= 0; i-- {
			suf[i] = max(suf[i+1], a[i])
			a[i] += a[i+1]
		}
		suf2 := make([]int64, n)
		k := 2
		for l := n - 1; l >= k; l -= k {
			suf2[l-k+1] = 0
			for i := l - k; i >= 0; i-- {
				s := a[i] - a[i+k]
				if suf2[i+1] < s && s < suf[i+k] {
					suf2[i] = s
				} else {
					suf2[i] = suf2[i+1]
				}
			}
			if suf2[0] == 0 {
				break
			}
			suf, suf2 = suf2, suf
			k++
		}
		Fprintln(out, k-1)
	}
}

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

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

package main

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

/*
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    a = a[::-1]
    pre = [0] + list(accumulate(a))
    k = int((n * 2) ** 0.5) + 1
    f = [[0] * (k + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        f[i][1] = max(f[i - 1][1], a[i - 1])

    res = 1
    for i in range(2, n + 1):
        for j in range(2, k + 1):
            f[i][j] = f[i - 1][j]
            if i < j * (j + 1) // 2: break
            v = pre[i] - pre[i - j]
            if f[i - j][j - 1] > v:
                res = max(res, j)
                f[i][j] = max(f[i][j], v)
    print(res)
*/

// https://codeforces.com/contest/1582/submission/167714541
func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()

	var t, n int
	Fscan(in, &t)

	for ; t > 0; t-- {
		Fscan(in, &n)

		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[n-i+1])
		}

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

		var ans int64 = 1
		dp := make([][]int64, n+1)

		k := int(math.Sqrt(float64(2* n)) + 1)
		for i := 0; i <= n; i++ {
			dp[i] = make([]int64, k+1)
			if i == 0 { continue }
			dp[i][1] = max(dp[i-1][1],a[i])
		}

		for i := 2; i <= n; i++ {
			for j := 2; j <= k; j++ {
				dp[i][j] = dp[i-1][j]
				if i < j*(j+1)/2 {
					break
				}
				v := pre[i] - pre[i-j]
				if dp[i-j][j-1] > v {
					ans = max(ans, int64(j))
					dp[i][j] = max(dp[i][j], v)
				}
			}
		}
		Fprint(out, ans)
	}
}

func max(x, y int64) int64 { if x > y { return x } else { return y }}
func main() { Solve(os.Stdin, os.Stdout) }


— Hey folks, how do you like this problem?— That'll do it. BThero is a powerful magician. He has got $$$n$$$ piles of candies, the $$$i$$$-th pile initially contains $$$a_i$$$ candies. BThero can cast a copy-paste spell as follows:   He chooses two piles $$$(i, j)$$$ such that $$$1 \le i, j \le n$$$ and $$$i \ne j$$$.  All candies from pile $$$i$$$ are copied into pile $$$j$$$. Formally, the operation $$$a_j := a_j + a_i$$$ is performed. BThero can cast this spell any number of times he wants to — but unfortunately, if some pile contains strictly more than $$$k$$$ candies, he loses his magic power. What is the maximum number of times BThero can cast the spell without losing his power?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 500$$$) — the number of test cases. Each test case consists of two lines:    the first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 1000$$$, $$$2 \le k \le 10^4$$$);  the second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le k$$$).  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$, and the sum of $$$k$$$ over all test cases does not exceed $$$10^4$$$.

For each test case, print one integer — the maximum number of times BThero can cast the spell without losing his magic power.

NoteIn the first test case we get either $$$a = [1, 2]$$$ or $$$a = [2, 1]$$$ after casting the spell for the first time, and it is impossible to cast it again.

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)

		A := readNNums(reader, n)

		res := solve(n, k, A)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func solve(n int, k int, A []int) int {
	var first = 0
	for i := 1; i < n; i++ {
		if A[i] < A[first] {
			first = i
		}
	}

	var res int

	for i := 0; i < n; i++ {
		if i == first {
			continue
		}
		if k > A[i] {
			res += (k - A[i]) / A[first]
		}
	}

	return res
}

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

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

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

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

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

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

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

	return i
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n, k := in(), in()

		a := make([]int, n)

		for i := range a {
			a[i] = in()
		}

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

		sum := 0

		for i := n - 1; i >= 1; i-- {
			sum += (k - a[i]) / a[0]
		}

		fmt.Println(sum)
	}
}

package main
import."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T, n, k int
	for Scan(&T); T > 0; T-- {
		Scan(&n, &k)
		mi := 0
		a := make([]int, n)
		for i := range a {
			Scan(&a[i])
			if a[i] < a[mi] {
				mi = i
			}
		}
		ans := 0
		for i, v := range a {
			if i != mi {
				ans += (k - v) / a[mi]
			}
		}
		Println(ans)
	}
}

package main

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

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

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

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

		ans := 0
		for i := 1; i < n; i++ {
			ans += (arr[i] - k) / arr[0]
		}

		fmt.Println(ans * -1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"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 t, k, n int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		scanf("%d %d\n", &n, &k)
		min := 0
		a := make([]int, n)
		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
			if a[i] < a[min] {
				min = i
			}
		}
		scanf("\n")
		s := 0
		for i := 0; i < n; i++ {
			if min == i {
				continue
			}
			s += int(math.Floor(float64((k - a[i]) / a[min])))
		}
		printf("%d\n", s)
	}
}


Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.Write a program that, given sequence ai, will print the minimum number of folders.

The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.

Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them.

NoteHere goes a way to sort the reports from the first sample into three folders:  1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.

package main

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

func main(){
	var n int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	a := make([]int, 105)
	c, t, x := 0, 0, 0
	a[t] = 0
	for n > 0 {
		r.Scan()
		x, _ = strconv.Atoi(r.Text())
		if x < 0 {
			if c == 2 {
				t += 1
				c = 1
				a[t] = 1
			} else {
				c += 1
				a[t] += 1
			}
		} else {
			a[t] += 1
		}
		n -= 1
	}
	w.WriteString(strconv.Itoa(t+1)+"\n")
	for i:=0; i<=t; i++ {
		w.WriteString(strconv.Itoa(a[i])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

// 250A
package main

import (
	"fmt"
)

func main() {
	var a [110]int
	var n, t int
	fmt.Scan(&n)
	x, m := 0, 1
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		if t < 0 {
			x++
		}
		if x == 3 {
			a[m] = i
			m++
			x = 1
		}
	}
	a[m] = n
	fmt.Println(m)
	for i := 1; i <= m; i++ {
		fmt.Print(a[i]-a[i-1], " ")
	}
}

// 250A
package main

import (
	"fmt"
)

func main() {
	var a [110]int
	var n, t int
	fmt.Scan(&n)
	x, m := 0, 1
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		if t < 0 {
			x++
		}
		if x == 3 {
			a[m] = i
			m++
			x = 1
		}
	}
	a[m] = n
	fmt.Println(m)
	for i := 1; i <= m; i++ {
		fmt.Print(a[i] - a[i-1], " ")
	}
}

package main

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

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A := make([]int, 0)
	for i := 0; i < N; i++ {
		A = append(A, fsc.NextInt())
	}
	res := make([]int, 0)

	cnt := 0
	for i := 0; i < N; i++ {
		if A[i] < 0 {
			cnt++
		}
		if cnt >= 3 {
			cnt = 1
			res = append(res, i)
		}
	}

	ans := make([]int, 0)
	pre := 0
	for i := 0; i < len(res); i++ {
		ans = append(ans, res[i]-pre)
		pre = res[i]
	}

	ans = append(ans, N-pre)
	fmt.Println(len(ans))
	for _, v := range ans {
		fmt.Print(v, " ")

	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

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

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

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

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

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


You are given a string $$$s$$$. You have to determine whether it is possible to build the string $$$s$$$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order.For example:  aaaabbb can be built as aa $$$+$$$ aa $$$+$$$ bbb;  bbaaaaabbb can be built as bb $$$+$$$ aaa $$$+$$$ aa $$$+$$$ bbb;  aaaaaa can be built as aa $$$+$$$ aa $$$+$$$ aa;  abab cannot be built from aa, aaa, bb and/or bbb.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of one line containing the string $$$s$$$ ($$$1 \le |s| \le 50$$$), consisting of characters a and/or b.

For each test case, print YES if it is possible to build the string $$$s$$$. Otherwise, print NO. You may print each letter in any case (for example, YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

8

aaaabbb

bbaaaaabbb

aaaaaa

abab

a

b

aaaab

bbaaa

NoteThe first four test cases of the example are described in the statement.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1671A
Date: 26/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1671/A
Problem: CF1671A
**/
func (in *CF1671A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		letter := uint8(0)
		count := 0
		ans := true
		for i := 0; i < len(str); i++ {
			if letter == str[i] {
				count++
			} else {
				if count != 0 && count < 2 {
					ans = false
					break
				}
				letter = str[i]
				count = 1
			}
		}
		if count != 0 && count < 2 {
			ans = false
		}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1671A
Date: 26/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1671/A
Problem: CF1671A
**/
func (in *CF1671A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		letter := uint8(0)
		count := 0
		ans := true
		for i := 0; i < len(str); i++ {
			if letter == str[i] {
				count++
			} else {
				if count > 0 {
					if count >= 2 {

					} else {
						ans = false
						break
					}
				}
				letter = str[i]
				count = 1
			}
		}
		if count > 0 {
			if count >= 2 {

			} else {
				ans = false
			}
		}

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

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

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

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    count, _ := strconv.Atoi(scanner.Text())

out:
    for i := 0; i < count; i++ {
        scanner.Scan()
        text := scanner.Text()

        var cos int
        var prev rune
        for ii, r := range text {
            if ii == 0 || r == prev {
                prev = r
                cos++
                continue
            }

            if r != prev {
                if cos == 1 {
                    fmt.Println("NO")
                    continue out
                }

                cos = 1
                prev = r
            }
        }

        if cos == 1 {
            fmt.Println("NO")
        } else {
            fmt.Println("YES")
        }
    }
}

package main

import "fmt"

func acceptable(input string) string {
	if len(input) == 1 {
		return "NO"
	} else {
		return "YES"
	}
}

func affinity(input string) []string {
	var sofar string
	var ret []string
	for i := 0; i < len(input); i++ {
		if sofar == "" {
			sofar += string(input[i])
			continue
		}

		if input[i] == input[i-1] {
			sofar += string(input[i])
		} else {
			ret = append(ret, sofar)
			sofar = string(input[i])
		}
	}

	if sofar != "" {
		ret = append(ret, sofar)
	}
	return ret
}

func solve(input []string) string {
	for _, it := range input {
		if acceptable(it) == "NO" {
			return "NO"
		}
	}
	return "YES"
}
func main() {
	var testcases int
	fmt.Scanf("%d\n", &testcases)

	for testcases > 0 {
		testcases--
		var input string
		fmt.Scanf("%s\n", &input)
		fmt.Println(solve(affinity(input)))

	}
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		str := ""
		fmt.Fscan(in, &str)
		left, right := 0, 0
		for right < len(str) {
			cnt := 0
			for right < len(str) && str[left] == str[right] {
				cnt++
				right++
			}
			if right-left == 1 {
				fmt.Fprintln(out, "NO")
				goto h1
			}
			left = right
		}
		fmt.Fprintln(out, "YES")
	h1:
	}
}

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

		f := true
		var a, b int
		for _, ch := range s {
			if ch == 'a' {
				a++
				if b == 1 {
					f = false
					break
				}
				b = 0
			} else {
				b++
				if a == 1 {
					f = false
					break
				}
				a = 0
			}
		}

		if a == 1 || b == 1 {
			f = false
		}

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

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var s string
		fmt.Fscan(in,&s)
		var fail bool
		var count int = 1
		for j:=0;j<len(s)-1;j++{
			if string(s[j]) == string(s[j+1]) {
				count = 0
			} else {
				count++
			}
			if count > 1 {
				fail = true
				break
			}
		}
		if fail == true || count == 1 {
			fmt.Fprintln(out,"NO")
		} else {
			fmt.Fprintln(out,"YES")
		}
	}
}

package main

import (
	"fmt"
)

var st [55]bool

func init() {
	for i := 0; i <= 50; i += 2 {
		for j := 0; j+i <= 50; j += 3 {
			st[i+j] = true
		}
	}
}

func solve() {
	// in := bufio.NewReader(os.Stdin)
	// s, _ := in.ReadString('\n')
	var s string
	fmt.Scan(&s)
	cnt := 0
	for i := range s {
		if i == 0 || s[i] == s[i-1] {
			cnt++
		} else if !st[cnt] {
			fmt.Println("NO")
			return
		} else {
			cnt = 1
		}
	}
	//fmt.Printf("cnt: %v\n", cnt)
	if !st[cnt] {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
}
func main() {
	t := 0
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		//	fmt.Printf("i: %v\n", i)
		solve()
	}
}

package main

import (
	"fmt"
)

var st [55]bool

func init() {
	for i := 0; i <= 50; i += 2 {
		for j := 0; j+i <= 50; j += 3 {
			st[i+j] = true
		}
	}
}

func solve() {
	// in := bufio.NewReader(os.Stdin)
	// s, _ := in.ReadString('\n')
	var s string
	fmt.Scanf("%s\n", &s)
	cnt := 0
	for i := range s {
		if i == 0 || s[i] == s[i-1] {
			cnt++
		} else if !st[cnt] {
			fmt.Println("NO")
			return
		} else {
			cnt = 1
		}
	}
	//fmt.Printf("cnt: %v\n", cnt)
	if !st[cnt] {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
}
func main() {
	t := 0
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		//	fmt.Printf("i: %v\n", i)
		solve()
	}
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"strings"
)

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	in := bufio.NewReader(os.Stdin)
	testCases := readInt(in)

	for i := 0; i < testCases; i++ {
		aCount := 0
		bCount := 0

		found := false
		s := readStr(in)
		if len(s) == 1 {
			fmt.Println("NO")
			continue
		}
		for _, r := range s {
			if r == 'a' {
				aCount++
				if bCount != 0 {
					if !compose(bCount) {
						fmt.Println("NO")
						found = true
						break
					} else {
						bCount = 0
					}
				}
			} else {
				bCount++
				if aCount != 0 {
					if !compose(aCount) {
						fmt.Println("NO")
						found = true
						break
					} else {
						aCount = 0
					}
				}
			}

		}

		if !found {
			if compose(aCount) && compose(bCount) {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

func compose(i int) bool {
	return i != 1

}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readInts(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readInt64s(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t, "\n")
	for ; t > 0; t-- {
		var str string
		fmt.Fscan(in, &str, "\n")

		i := 0
		slen := len(str)
		flag := true
		for ; i < slen; i++ {
			cnt := 0
			if str[i] == 'a' {
				for ; i < slen; i++ {
					if str[i] != 'a' {
						break
					}
					cnt++
				}
				i--
				if cnt < 2 {
					flag = false
				}
			} else {
				for ; i < slen; i++ {
					if str[i] != 'b' {
						break
					}
					cnt++
				}
				i--
				if cnt < 2 {
					flag = false
				}
			}
		}
		if flag {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

// This section should be changed every time you solve a problem.
var (
	tmp string
)

//var read, _ = os.Open("input.txt")
//var in = bufio.NewReader(read)

//var out, _ = os.Create("output.txt")

var in = bufio.NewReader(os.Stdin)

// This section should be changed every time you solve a problem.
func setting() {

}

func main() {
	setting()
	//defer out.Close()

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

	for k := 0; k < T; k++ {
		fmt.Fscan(in, &tmp)
		length := len(tmp)
		a, b := 0, 0
		test := true
		for i := 0; i < length; i++ {
			if length == 1 {
				test = false
				break
			}
			if i == 0 {
				if tmp[0] == 'a' {
					a++
				} else {
					b++
				}
				continue
			}
			if tmp[i] == 'a' {
				if tmp[i-1] == 'b' {
					if b < 2 {
						test = false
						break
					}
					b = 0
				}
				a++
			} else if tmp[i] == 'b' {
				if tmp[i-1] == 'a' {
					if a < 2 {
						test = false
						break
					}
					a = 0
				}
				b++
			}
			if i == length-1 {
				if a < 2 && b < 2 {
					test = false
				}
			}
		}
		if test == true {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

package main

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

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

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

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

		ans := true
		if len(s) == 1 {
			ans = false
		}
		for i := 1; i < len(s)-1; i++ {
			if s[i] != s[i-1] && s[i+1] != s[i] {
				ans = false
				break
			}
		}

		if len(s) >= 2 {
			if s[len(s)-1] != s[len(s)-2] || s[0] != s[1] {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

package main

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

func valid(s string) bool {
	if len(s) == 0 {
		return true
	}

	if strings.HasPrefix(s, "aaa") || strings.HasPrefix(s, "bbb") {
		return valid(s[2:]) || valid(s[3:])
	} else if strings.HasPrefix(s, "aa") || strings.HasPrefix(s, "bb") {
		return valid(s[2:])
	}
	return false
}

func main() {
	var count int
	fmt.Fscan(os.Stdin, &count)

	for i := 0; i < count; i++ {
		var s string
		fmt.Fscan(os.Stdin, &s)
		if valid(s) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

package main

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

/*
1
bbaaaaabbb
*/

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

	aCnt := 0
	bCnt := 0

	prev := rune(s[0])

	switch prev {
	case 'a':
		aCnt++
	case 'b':
		bCnt++
	default:
		fmt.Fprintln(writer, "NO")
		return
	}

	for _, r := range s[1:] {
		if r == prev {
			switch r {
			case 'a':
				aCnt++
			case 'b':
				bCnt++
			default:
				fmt.Fprintln(writer, "NO")
				return
			}
		} else {
			switch r {
			case 'a':
				if !isGoodCnt(bCnt) {
					fmt.Fprintln(writer, "NO")
					return
				}

				aCnt++
				bCnt = 0
			case 'b':
				if !isGoodCnt(aCnt) {
					fmt.Fprintln(writer, "NO")
					return
				}

				aCnt = 0
				bCnt++
			default:
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		prev = r
	}

	if !isGoodCnt(bCnt) {
		fmt.Fprintln(writer, "NO")
		return
	}

	if !isGoodCnt(aCnt) {
		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

func isGoodCnt(cnt int) bool {
	return cnt != 1
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

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

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

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

	return factors
}

package main

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

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

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var s string
		Fscan(in, &s)

		cntA := 0
		cntB := 0
		ans := "YES"
		for _, ch := range s {
			if ch == 'a' {
				if cntB == 1 {
					ans = "NO"
					break
				} else {
					cntB = 0
					cntA++
				}
			} else {
				if cntA == 1 {
					ans = "NO"
					break
				} else {
					cntA = 0
					cntB++
				}
			}
		}
		if cntA == 1 || cntB == 1 {
			ans = "NO"
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

const MOD int64 = 1000000007

var s string

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &s)

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

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

func solve()  {
	if len(s) == 1 {
		fmt.Println("NO")
		return
	}

	prev := s[0]
	cnt := 1
	for i := 1; i < len(s); i++ {
		if s[i] == prev {
			cnt++
			continue
		}
		if cnt <= 1 {
			fmt.Println("NO")
			return
		}
		cnt = 1
		prev = s[i]
	}
	if cnt <= 1 {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
}

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

package main

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

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

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

	var T int
	var x string

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

		Fscan(in, &x)
		r := []byte(x)
		//Fprintln(out, string(r))

		if len(r) == 1 {
			Fprintln(out, "NO")
			continue
		}

		t := 1
		for i := 1; i < len(r); i++ {
			if r[i] == r[i-1] {
				t++
			} else {
				if t == 1 {
					Fprintln(out, "NO")
					continue loop
				}
				t = 1
			}
		}
		if t == 1 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var s string
		fmt.Fscan(in, &s)
		var lc rune
		var cnt int
		ok := true
		for _, c := range s {
			if c == lc {
				cnt++
			} else {
				if cnt == 1 {
					ok = false
					break
				}
				lc = c
				cnt = 1
			}
		}
		if !ok || cnt == 1 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

func slove() {
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	last := 0
	i := 1
	for i=1;i<len(s);i++ {
		if s[i] != s[last] {
			l := i - last
			if l == 1 {
				fmt.Fprintln(w, "No")
				return
			}
			last = i
		}
	}
	l := i - last
	if l == 1 {
		fmt.Fprintln(w, "No")
		return
	}
	fmt.Fprintln(w, "Yes")
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1671A
Date: 26/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1671/A
Problem: CF1671A
**/
func (in *CF1671A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		letter := uint8(0)
		count := 0
		ans := true
		for i := 0; i < len(str); i++ {
			if letter == str[i] {
				count++
			} else {
				if count > 0 {
					if (count%2 == 0 || count%3 == 0 || count%5 == 0 || count%7 == 0) && count >= 2 {

					} else {
						ans = false
						break
					}
				}
				letter = str[i]
				count = 1
			}
		}
		if count > 0 {
			if (count%2 == 0 || count%3 == 0 || count%5 == 0 || count%7 == 0) && count >= 2 {

			} else {
				ans = false
			}
		}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1671A
Date: 26/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1671/A
Problem: CF1671A
**/
func (in *CF1671A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		letter := uint8(0)
		count := 0
		ans := true
		for i := 0; i < len(str); i++ {
			if letter == str[i] {
				count++
			} else {
				if count > 0 {
					if (count%2 == 0 || count%3 == 0 || count%5 == 0) && count > 1 {

					} else {
						ans = false
						break
					}
				}
				letter = str[i]
				count = 1
			}
		}
		if count > 0 {
			if (count%2 == 0 || count%3 == 0 || count%5 == 0) && count > 1 {

			} else {
				ans = false
			}
		}

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

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

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

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    count, _ := strconv.Atoi(scanner.Text())

out:
    for i := 0; i < count; i++ {
        scanner.Scan()
        text := scanner.Text()

        var prev rune
        cos := 1
        for ii, r := range text {
            if ii == 0 {
                prev = r
                continue
            }

            if r == prev {
                cos++
                continue
            }

            if r != prev {
                if jj := cos % 3; jj == 0 || jj%2 == 0 {
                } else if jj := cos % 2; jj == 0 || jj%3 == 0 {
                } else if jj := cos % 5; jj == 0 || jj%3 == 0 || jj%2 == 0 {
                } else {
                    fmt.Println("NO")
                    continue out
                }

                cos = 1
                prev = r
            }
        }

        if j := cos % 3; j == 0 || j%2 == 0 {
            fmt.Println("YES")
        } else if j := cos % 2; j == 0 || j%3 == 0 {
            fmt.Println("YES")
        } else if jj := cos % 5; jj == 0 || jj%3 == 0 || jj%2 == 0 {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    count, _ := strconv.Atoi(scanner.Text())

out:
    for i := 0; i < count; i++ {
        scanner.Scan()
        text := scanner.Text()

        var prev rune
        cos := 1
        for ii, r := range text {
            if ii == 0 {
                prev = r
                continue
            }

            if r == prev {
                cos++
                continue
            }

            if r != prev {
                if j := cos % 3; j == 0 || j%2 == 0 {
                } else if j := cos % 2; j == 0 || j%3 == 0 {
                } else {
                    fmt.Println("NO")
                    continue out
                }

                cos = 1
                prev = r
            }
        }

        if j := cos % 3; j == 0 || j%2 == 0 {
            fmt.Println("YES")
        } else if j := cos % 2; j == 0 || j%3 == 0 {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    count, _ := strconv.Atoi(scanner.Text())

out:
    for i := 0; i < count; i++ {
        scanner.Scan()
        text := scanner.Text()

        var prev rune
        cos := 1
        for ii, r := range text {
            if ii == 0 {
                prev = r
                continue
            }

            if r == prev {
                cos++
                continue
            }

            if r != prev {
                if j := cos % 3; j == 0 || j%2 == 0 {
                } else if cos%2 == 0 {
                } else {
                    fmt.Println("NO")
                    continue out
                }

                cos = 1
                prev = r
            }
        }

        if j := cos % 3; j == 0 || j%2 == 0 {
            fmt.Println("YES")
        } else if cos%2 == 0 {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    count, _ := strconv.Atoi(scanner.Text())

out:
    for i := 0; i < count; i++ {
        scanner.Scan()
        text := scanner.Text()

        var prev rune
        cos := 0
        for ii, r := range text {
            if ii == 0 {
                prev = r
                continue
            }

            if r == prev {
                cos++
                continue
            }

            if r != prev {
                if j := cos % 3; j == 0 || j%2 == 0 {
                } else if cos%2 == 0 {
                } else {
                    fmt.Println("NO")
                    continue out
                }

                cos = 0
                prev = r
            }
        }
        fmt.Println("YES")
    }
}

package main

import "fmt"

func acceptable(input string) string {
	if len(input)%2 == 0 || len(input)%3 == 0 || len(input)%5 == 0 {
		return "YES"
	}
	return "NO"
}

func affinity(input string) []string {
	var sofar string
	var ret []string
	for i := 0; i < len(input); i++ {
		if sofar == "" {
			sofar += string(input[i])
			continue
		}

		if input[i] == input[i-1] {
			sofar += string(input[i])
		} else {
			ret = append(ret, sofar)
			sofar = string(input[i])
		}
	}

	if sofar != "" {
		ret = append(ret, sofar)
	}
	return ret
}

func solve(input []string) string {
	for _, it := range input {
		if acceptable(it) == "NO" {
			return "NO"
		}
	}
	return "YES"
}
func main() {
	var testcases int
	fmt.Scanf("%d\n", &testcases)

	for testcases > 0 {
		testcases--
		var input string
		fmt.Scanf("%s\n", &input)
		fmt.Println(solve(affinity(input)))

	}
}

package main

import "fmt"

func acceptable(input string) string {
	// fmt.Println(len(input), input)
	if len(input)%2 == 0 || len(input)%3 == 0 {
		return "YES"
	}
	return "NO"
}

func affinity(input string) []string {
	var sofar string
	var ret []string
	for i := 0; i < len(input); i++ {
		if sofar == "" {
			sofar += string(input[i])
			continue
		}

		if input[i] == input[i-1] {
			sofar += string(input[i])
		} else {
			ret = append(ret, sofar)
			sofar = string(input[i])
		}
	}

	if sofar != "" {
		ret = append(ret, sofar)
	}
	return ret
}

func solve(input []string) string {
	for _, it := range input {
		if acceptable(it) == "NO" {
			return "NO"
		}
	}
	return "YES"
}
func main() {
	var testcases int
	fmt.Scanf("%d\n", &testcases)

	for testcases > 0 {
		testcases--
		var input string
		fmt.Scanf("%s\n", &input)
		fmt.Println(solve(affinity(input)))

	}
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		str := ""
		fmt.Fscan(in, &str)
		left, right := 0, 0
		for right < len(str) {
			cnt := 0
			for right < len(str) && str[left] == str[right] {
				cnt++
				right++
			}
			if (right-left)%2 != 0 && (right-left)%3 != 0 && (right-left)%5 != 0 && (right-left) % 7 != 0{
				fmt.Fprintln(out, "NO")
				goto h1
			}
			left = right
		}
		fmt.Fprintln(out, "YES")
	h1:
	}
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		str := ""
		fmt.Fscan(in, &str)
		left, right := 0, 0
		for right < len(str) {
			cnt := 0
			for right < len(str) && str[left] == str[right] {
				cnt++
				right++
			}
			if (right-left)%2 != 0 && (right-left)%3 != 0 && (right-left)%5 != 0 {
				fmt.Fprintln(out, "NO")
				goto h1
			}
			left = right
		}
		fmt.Fprintln(out, "YES")
	h1:
	}
}

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

		f := true
		var a, b int
		for _, ch := range s {
			if ch == 'b' && a > 0 {
				if a%2 != 0 && a%3 != 0 && a%5 != 0 {
					f = false
					break
				}
				b++
				a = 0
			} else if ch == 'a' && b > 0 {
				if b%2 != 0 && b%3 != 0 && b%5 != 0 {
					f = false
					break
				}
				a++
				b = 0
			} else if ch == 'a' {
				a++
			} else if ch == 'b' {
				b++
			}
		}

		if a > 0 && a%2 != 0 && a%3 != 0 && a%5 != 0 {
			f = false
		}

		if b > 0 && b%2 != 0 && b%3 != 0 && b%5 != 0 {
			f = false
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

		f := true
		var a, b int
		for _, ch := range s {
			if ch == 'b' && a > 0 {
				if a%2 != 0 && a%3 != 0 && a%5 != 0 {
					f = false
					break
				}
				b++
				a = 0
			} else if ch == 'a' && b > 0 {
				if b%2 != 0 && b%3 != 0 && b%5 != 0 {
					fmt.Println("here")
					f = false
					break
				}
				a++
				b = 0
			} else if ch == 'a' {
				a++
			} else if ch == 'b' {
				b++
			}
		}

		if a > 0 && a%2 != 0 && a%3 != 0 && a%5 != 0 {
			f = false
		}

		if b > 0 && b%2 != 0 && b%3 != 0 && b%5 != 0 {
			f = false
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var s string
		fmt.Fscan(in,&s)
		var a,b int
		for j:=0;j<len(s);j++{
			if string(s[j]) == "a" {
				a++
			} else {
				b++
			}
		}
		if a == 1 || b == 1 {
			fmt.Fprintln(out,"NO")
			continue
		}
		if len(s) == 2 {
			fmt.Fprintln(out,"YES")
			continue
		}
		for j:=3;j<=len(s);j+=3{
			if string(s[j-3:j]) == "bab" || string(s[j-3:j]) == "aba" {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"strings"
)

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	in := bufio.NewReader(os.Stdin)
	testCases := readInt(in)

	for i := 0; i < testCases; i++ {
		aCount := 0
		bCount := 0

		found := false
		s := readStr(in)
		if len(s) == 1 {
			fmt.Println("NO")
			continue
		}
		for _, r := range s {
			if r == 'a' {
				aCount++
				if bCount != 0 {
					if bCount%2 != 0 && bCount%3 != 0 && bCount%5 != 0 {
						fmt.Println("NO")
						found = true
						break
					} else {
						bCount = 0
					}
				}
			} else {
				bCount++
				if aCount != 0 {
					if aCount%2 != 0 && aCount%3 != 0 && aCount%5 != 0 {
						fmt.Println("NO")
						found = true
						break
					} else {
						aCount = 0
					}
				}
			}

		}

		if !found {
			if (aCount%2 == 0 || aCount%3 == 0 || aCount%5 == 0) && (bCount%2 == 0 || bCount%3 == 0 || bCount%5 == 0) {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}

}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readInts(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readInt64s(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}


The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text.Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that it points to only one of the characters (and not between a pair of characters). Thus, it points to an index character. The user can move the cursor left or right one position. If the cursor is already at the first (leftmost) position, then it does not move left.Initially, the cursor is in the first (leftmost) character.Also, the user can write a letter or brackets (either (, or )) to the position that the cursor is currently pointing at. A new character always overwrites the old value at that position.Your editor must check, whether the current line is the correct text. Text is correct if the brackets in them form the correct bracket sequence.Formally, correct text (CT) must satisfy the following rules:   any line without brackets is CT (the line can contain whitespaces);  If the first character of the string — is (, the last — is ), and all the rest form a CT, then the whole line is a CT;  two consecutively written CT is also CT. Examples of correct texts: hello(codeforces), round, ((i)(write))edi(tor)s, ( me). Examples of incorrect texts: hello)oops(, round), ((me).The user uses special commands to work with your editor. Each command has its symbol, which must be written to execute this command.The correspondence of commands and characters is as follows:   L — move the cursor one character to the left (remains in place if it already points to the first character);  R — move the cursor one character to the right;  any lowercase Latin letter or bracket (( or )) — write the entered character to the position where the cursor is now. For a complete understanding, take a look at the first example and its illustrations in the note below.You are given a string containing the characters that the user entered. For the brackets coloring module's work, after each command you need to:  check if the current text in the editor is a correct text;  if it is, print the least number of colors that required, to color all brackets. If two pairs of brackets are nested (the first in the second or vice versa), then these pairs of brackets should be painted in different colors. If two pairs of brackets are not nested, then they can be painted in different or the same colors. For example, for the bracket sequence ()(())()() the least number of colors is $$$2$$$, and for the bracket sequence (()(()())())(()) — is $$$3$$$.Write a program that prints the minimal number of colors after processing each command.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the number of commands.  The second line contains $$$s$$$ — a sequence of commands. The string $$$s$$$ consists of $$$n$$$ characters. It is guaranteed that all characters in a string are valid commands.

In a single line print $$$n$$$ integers, where the $$$i$$$-th number is:   $$$-1$$$ if the line received after processing the first $$$i$$$ commands is not valid text,  the minimal number of colors in the case of the correct text.

NoteIn the first example, the text in the editor will take the following form:  (^  ( ^  (a ^  (a  ^  (ab  ^  (ab   ^  (ab)   ^  (ab)  ^  (a))  ^  (a)) ^  (()) ^

package main

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

type Stack []int

func (s *Stack) Push(x int) {
	*s = append(*s, x)
}
func (s *Stack) Pop() {
	if len(*s) == 0 {
		return
	}

	*s = (*s)[:len(*s)-1]
}
func (s *Stack) Top() int {
	if len(*s) == 0 {
		return 0
	}

	return (*s)[len(*s)-1]
}

type MyStack struct {
	cnt      int
	s        Stack
	minValue Stack
	maxValue Stack
}

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

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

func (ms *MyStack) Cnt() int {
	return ms.cnt
}

func (ms *MyStack) Push(x int) {
	ms.s.Push(x)
	ms.cnt += x

	if len(ms.minValue) > 0 {
		ms.minValue.Push(min(ms.minValue.Top(), ms.cnt))
	} else {
		ms.minValue.Push(ms.cnt)
	}

	if len(ms.maxValue) > 0 {
		ms.maxValue.Push(max(ms.maxValue.Top(), ms.cnt))
	} else {
		ms.maxValue.Push(ms.cnt)
	}
}

func (ms *MyStack) Pop() {
	if len(ms.s) == 0 {
		return
	}
	ms.cnt -= ms.s.Top()
	ms.s.Pop()
	ms.minValue.Pop()
	ms.maxValue.Pop()
}

func (ms *MyStack) Top() int {
	return ms.s.Top()
}

func (ms *MyStack) IsCorrect() bool {
	return len(ms.minValue) == 0 || ms.minValue.Top() >= 0
}

func (ms *MyStack) Depth() int {
	if len(ms.maxValue) > 0 {
		return ms.maxValue.Top()
	}

	return 0
}

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

	var symbols int
	fmt.Fscanln(in, &symbols)

	left := MyStack{}
	right := MyStack{}

	pos := 0

	for i := 0; i < symbols; i++ {
		b, _ := in.ReadByte()

		switch b {
		case 'R':
			pos++
			left.Push(-right.Top())
			right.Pop()
		case 'L':
			if pos > 0 {
				pos--
				right.Push(-left.Top())
				left.Pop()
			}
		case '(':
			left.Pop()
			left.Push(1)
		case ')':
			left.Pop()
			left.Push(-1)
		default:
			left.Pop()
			left.Push(0)
		}

		if left.IsCorrect() && right.IsCorrect() && left.Cnt() == right.Cnt() {
			m := max(left.Depth(), right.Depth())
			m = max(m, left.Cnt())

			fmt.Fprint(out, strconv.Itoa(m))
			fmt.Fprint(out, " ")
		} else {
			fmt.Fprint(out, "-1 ")
		}
	}

	out.Flush()
}

package main

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

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

	fmt.Fscanln(in, &symbols)

	r := make([]byte, 1000000)
	cur := 0
	max := 0

	o := make([]int, 0, 1000)
	c := make([]int, 0, 1000)
	for i := 0; i < symbols; i++ {
		b, _ := in.ReadByte()

		if b == 'R' {
			cur += 1
			if cur > max {
				max = cur
			}
			goto printPoint
		}

		if b == 'L' {
			cur -= 1
			if cur < 0 {
				cur = 0
			}
			goto printPoint
		}

		if r[cur] == b {
			goto printPoint
		}

		r[cur] = b

		if b == '(' {
			o = append(o, cur)
			for j := 0; j < len(o)-1; j++ {
				if cur < o[j] {
					copy(o[j+1:], o[j:])
					o[j] = cur
				}
			}
			goto printPoint
		}

		if b == ')' {
			c = append(c, cur)
			for j := 0; j < len(c)-1; j++ {
				if cur < c[j] {
					copy(c[j+1:], c[j:])
					c[j] = cur
				}
			}
			goto printPoint
		}

	printPoint:
		//fmt.Println(b, string(b), string(r[:max+1]), o, c, check(o, c))
		fmt.Fprint(os.Stdout, check(o, c))
	}

}

func check(o, c []int) string {
	if len(o) != len(c) {
		return "-1 "
	}

	if len(o) == 0 {
		return "0 "
	}

	if c[0] < o[0] {
		return "-1 "
	}

	max := 0

	oi := 0
	ci := 0

	cur := 0
	for {
		if oi < len(o) {
			if ci < len(c) {
				if o[oi] < c[ci] {
					cur++
					if cur > max {
						max = cur
					}
					oi++
				} else {
					cur--
					ci++
				}
			} else {
				return "-1 "
			}
		} else {
			if ci < len(c) {
				if len(c)-ci != cur {
					return "-1 "
				} else {
					break
				}
			} else {
				break
			}
		}
	}

	return strconv.Itoa(max) + " "
}