There are $$$n$$$ models in the shop numbered from $$$1$$$ to $$$n$$$, with sizes $$$s_1, s_2, \ldots, s_n$$$.Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices $$$i_j$$$ and $$$i_{j+1}$$$ (note that $$$i_j < i_{j+1}$$$, because Orac arranged them properly), $$$i_{j+1}$$$ is divisible by $$$i_j$$$ and $$$s_{i_j} < s_{i_{j+1}}$$$.For example, for $$$6$$$ models with sizes $$$\{3, 6, 7, 7, 7, 7\}$$$, he can buy models with indices $$$1$$$, $$$2$$$, and $$$6$$$, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.

The first line contains one integer $$$t\ (1 \le t\le 100)$$$: the number of queries. Each query contains two lines. The first line contains one integer $$$n\ (1\le n\le 100\,000)$$$: the number of models in the shop, and the second line contains $$$n$$$ integers $$$s_1,\dots,s_n\ (1\le s_i\le 10^9)$$$: the sizes of models. It is guaranteed that the total sum of $$$n$$$ is at most $$$100\,000$$$.

Print $$$t$$$ lines, the $$$i$$$-th of them should contain the maximum number of models that Orac can buy for the $$$i$$$-th query.

NoteIn the first query, for example, Orac can buy models with indices $$$2$$$ and $$$4$$$, the arrangement will be beautiful because $$$4$$$ is divisible by $$$2$$$ and $$$6$$$ is more than $$$3$$$. By enumerating, we can easily find that there are no beautiful arrangements with more than two models. In the second query, Orac can buy models with indices $$$1$$$, $$$3$$$, and $$$6$$$. By enumerating, we can easily find that there are no beautiful arrangements with more than three models. In the third query, there are no beautiful arrangements with more than one model.

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		var n int

		fmt.Scan(&n)

		arr := make([]int, n)
		count := make([]int, n)

		for i := range arr {
			fmt.Scan(&arr[i])
			count[i]++
		}

		for i := 0; i <= n/2; i++ {
			for j := 2*i + 1; j < n; j += i + 1 {
				if (j+1)%(i+1) == 0 {
					if arr[j] > arr[i] {
						if count[i]+1 > count[j] {
							count[j] = count[i] + 1
						}
					}
				}
			}
		}

		max := 1

		for _, i := range count {
			if i > max {
				max = i
			}
		}
		fmt.Println(max)

	}
}

/*
URL:
https://codeforces.com/contest/1350/problem/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int
	n int
	S []int
)

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

func solve(n int, tmp []int) {
	S := []int{-1}
	S = append(S, tmp...)

	G := make([][]int, n+1)
	for i := 1; i <= n; i++ {
		cid := i

		for j := 2; i*j <= n; j++ {
			nid := i * j

			if S[cid] < S[nid] {
				G[cid] = append(G[cid], nid)
			}
		}
	}

	_, sorted := tsort(n+1, G)
	ans := longestPath(sorted, G) + 1
	fmt.Println(ans)
}

// O(|E| + |V|)
// ノードIDは0-based
// ok, ans := tsort(v, edges[:])
// https://onlinejudge.u-aizu.ac.jp/problems/GRL_4_B
func tsort(nn int, edges [][]int) (bool, []int) {
	res := []int{}

	degin := make([]int, nn)
	for s := 0; s < nn; s++ {
		for _, t := range edges[s] {
			degin[t]++
		}
	}

	st := []int{}
	for nid := 0; nid < nn; nid++ {
		if degin[nid] == 0 {
			st = append(st, nid)
		}
	}

	for len(st) > 0 {
		cid := st[len(st)-1]
		res = append(res, cid)
		st = st[:len(st)-1]

		for _, nid := range edges[cid] {
			degin[nid]--
			if degin[nid] == 0 {
				st = append(st, nid)
			}
		}
	}

	if len(res) != nn {
		return false, nil
	}

	return true, res
}

// トポロジカルソート済みリストから最長経路の長さを計算する
// l := longestPath(res, edges[:])
// https://atcoder.jp/contests/abc139/tasks/abc139_e
func longestPath(tsortedNodes []int, edges [][]int) int {
	dp := make([]int, len(tsortedNodes)+1)

	for i := 0; i < len(tsortedNodes); i++ {
		cid := tsortedNodes[i]
		for _, nid := range edges[cid] {
			ChMax(&dp[nid], dp[cid]+1)
		}
	}

	res := 0
	for i := 0; i < len(tsortedNodes); i++ {
		ChMax(&res, dp[i])
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1350B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	const mx int = 1e5
	ds := [mx + 1][]int{}
	for i := 1; i <= mx; i++ {
		for j := 2 * i; j <= mx; j += i {
			ds[j] = append(ds[j], i)
		}
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		dp := make([]int, n)
		ans := 0
		for i := range a {
			Fscan(in, &a[i])
			dp[i] = 1
			for _, d := range ds[i+1] {
				if a[d-1] < a[i] {
					dp[i] = max(dp[i], dp[d-1]+1)
				}
			}
			ans = max(ans, dp[i])
		}
		Fprintln(out, ans)
	}
}

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

package main

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

var dp = make([]int, 100004)

func main() {
	for t := ScanInt(); t > 0; t-- {
		for i := 0; i < 100004; i++ {
			dp[i] = 1
		}
		n := ScanInt()
		s := ScanIntSlice(n)
		s = append([]int{0}, s...)

		maxL := 1
		for i := 1; i <= n; i++ {
			if dp[i] > 1 {
				maxL = max(maxL, dp[i])
			} else {
				maxL = max(maxL, 1+f(i, n, s))
				dp[i] = maxL
			}
		}

		P(maxL)
	}

	close(O)
	oWg.Wait()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func f(ind, n int, s []int) int {

	if ind > n {
		return 0
	}
	count := 0
	for i := ind; i <= n; i += ind {
		if s[i] > s[ind] {
			count = max(count, 1+f(i, n, s))
			dp[ind] = count
		}
	}

	return count
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		s := make([]int, n+1)
		dp := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&s[i])
			dp[i] = 1
		}

		max := 0
		for i := 1; i <= n; i++ {
			for j := i * 2; j <= n; j += i {
				if s[j] > s[i] && dp[j] < dp[i]+1 {
					dp[j] = dp[i] + 1
				}
			}
			if max < dp[i] {
				max = dp[i]
			}
		}
		fmt.Println(max)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

func gcd(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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

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

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

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

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

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

func sol(ss []int64) int64 {
	dp := make([]int64, len(ss))
	dp[0] = 1
	maxSoFar := int64(1)
	for i := int64(0); i < int64(len(dp)); i++ {
		for j := int64(2); j < int64(len(dp)); j++ {
			nxtIdx := (i+1)*j-1
			if nxtIdx >= int64(len(dp)) {
				break
			}
			if (nxtIdx + 1) % (i + 1) == 0 && ss[nxtIdx] > ss[i] {
				dp[nxtIdx] = max(dp[nxtIdx], dp[i]+1)
				maxSoFar = max(maxSoFar, dp[nxtIdx])
			} else {
				dp[nxtIdx] = max(dp[nxtIdx], 1)
			}
		}
	}
	return maxSoFar
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a[i])
	}

	dp := make([]float64, n+1)
	for i := 1; i <= n; i++ {
		dp[i] = 1
	}

	for i := 1; i <= n; i++ {
		for j := i + i; j <= n; j += i {
			if a[i] < a[j] {
				dp[j] = math.Max(dp[j], dp[i]+1)
			}
		}
	}
	ans := 0.0
	for i := 1; i <= n; i++ {
		ans = math.Max(ans, dp[i])
	}
	fmt.Println(ans)
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1

	}

	ans := 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
				ans = max(ans,dp[k])
			}
		}
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
	}

	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
	}

	ans := 1
	for i := 1; i <= n; i++ {
		ans = max(ans,dp[i])
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
		}
	}

	if n == 1 {
		return 1
	}

	ans := 1
	for i := 1; i < n; i++ {
		for k := 2; k <= sqr(i) + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

func sqr(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
			ans = 2
		}
	}

	if n == 1 {
		return 1
	}

	for i := 1; i < n; i++ {
		for k := 2; k*k <= i; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++

		}
	}

	if n == 1 {
		return 1
	}
	ans := 2

	for i := 1; i < n; i++ {
		for k := 2; k*k <= i; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])

	}
	dp[0] = 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
	}

	ans := 1
	for i := 1; i <= n; i++ {
		ans = max(ans,dp[i])
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
			ans = 2

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

	for z := 2; z <= n; z++ {
		for k := 2; k*k <= z; k++ {
			if z % k == 0 && s[z - 1] > s[z / k - 1] {
				dp[z - 1] = max(dp[z - 1], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[z - 1])
	}

	return ans
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
	}

	dp[1] = 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
	}

	ans := 1
	for i := 1; i <= n; i++ {
		ans = max(ans,dp[i])
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[1] = 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}
	dp := make([]int, n)
	ans := 1
	dp[0] = 1
	for z := 2; z <= n; z++ {
		for k := 2; z / k > 0; k++ {
			if z % k == 0 && s[z - 1] > s[z / k - 1] {
				dp[z - 1] = max(dp[z - 1], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[z - 1])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
	}

	if n == 1 {
		return 1
	}

	ans := 1
	for i := 1; i < n; i++ {
		for k := 2; k*k <= i + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
			if s[z - 1] > s[0] {
				dp[i]++
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[0] = 1
	for i := 1; i < n; i++ {
		dp[i] = 1
		if s[i] > s[0] {
			dp[i]++
		}
		z := i + 1
		//println("check z", z)
		for k := 2; k <= sqrt(z) + 1; k++ {
		//	println("iter", k, s[i] > s[z / k - 1], i , z / k - 1)
			if z % k == 0 && s[i] > s[z / k - 1] {
				dp[i] = max(dp[i], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	//fmt.Println(dp)
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[0] = 1
	for i := 1; i < n; i++ {
		dp[i] = 1
		if s[i] > s[0] {
			dp[i]++
		}
		z := i + 1
		//println("check z", z)
		for k := 2; k <= sqrt(z); k++ {
		//	println("iter", k, s[i] > s[z / k - 1], i , z / k - 1)
			if z % k == 0 && s[i] > s[z / k - 1] {
				dp[i] = max(dp[i], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	//fmt.Println(dp)
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		var n int

		fmt.Scan(&n)

		arr := make([]int, n)
		count := make([]int, n)

		for i := range arr {
			fmt.Scan(&arr[i])
			count[i]++
		}

		for i := 0; i <= n/2; i++ {
			for j := 2*i + 1; j < n; j += i + 1 {
				if (j+1)%(i+1) == 0 {
					if arr[j] > arr[i] {
						if count[i]+1 > count[j] {
							count[j] = count[i] + 1
						}
					}
				}
			}
		}

		max := 1

		for _, i := range count {
			if i > max {
				max = i
			}
		}

		fmt.Println(count)

		fmt.Println(max)

	}
}

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		var n int

		fmt.Scan(&n)

		arr := make([]int, n)
		count := make([]int, n)

		for i := range arr {
			fmt.Scan(&arr[i])
			count[i]++
		}

		for i := 0; i <= n/2; i++ {
			for j := 2*i + 1; j < n; j += i + 1 {
				if (j+1)%(i+1) == 0 {
					if arr[j] > arr[i] {
						count[j]++
					}
				}
			}
		}

		max := 1

		for _, i := range count {
			if i > max {
				max = i
			}
		}
		fmt.Println(max)

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		s := make([]int, n+1)
		dp := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&s[i])
		}

		max := 0
		for i := 1; i <= n; i++ {
			if s[i] > s[i/2] {
				dp[i] = dp[i/2] + 1
			} else {
				dp[i] = 1
			}

			if max < dp[i] {
				max = dp[i]
			}
		}
		fmt.Println(max)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

func gcd(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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

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

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

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

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

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

func sol(ss []int64) int64 {
	dp := make([]int64, len(ss))
	dp[0] = 1
	maxSoFar := int64(1)
	for i := 1; i < len(dp); i++ {
		for j := i-1; j >= 0; j-- {
			if (i+1) % (j+1) == 0 && ss[i] > ss[j] {
				dp[i] = max(dp[i], dp[j] + 1)
				maxSoFar = max(maxSoFar, dp[i])
			}
		}
	}
	return maxSoFar
}

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[0] = 1
	for i := 1; i < n; i++ {
		z := i + 1
		dp[i] = 1
		if s[i] > s[0] {
			dp[i]++
		}

		for k := 2; k*k <= z; k++ {
			//println("iter", k, s[i] > s[z / k - 1], i , z / k - 1)
			if z % k == 0 && s[i] > s[z / k - 1] {
				dp[i] = max(dp[i], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	//fmt.Println(dp)
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
		}
	}

	if n == 1 {
		return 1
	}

	ans := 1
	for i := 1; i < n; i++ {
		for k := 2; k*k <= i + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

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

	ans := 1
	for i := 2; 2*i <= n; i++ {
		tmp := 1
		for k := 2; k * i <= n; k++ {
			if s[k*i - i - 2] < s[k*i - 1] {
				tmp++
			}
		}
		ans = max(ans, tmp)
	}

	fmt.Println(ans)
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
			ans = 2

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

	for i := 1; i < n; i++ {
		for k := 2; k*k <= i + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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


Gildong is playing a video game called Block Adventure. In Block Adventure, there are $$$n$$$ columns of blocks in a row, and the columns are numbered from $$$1$$$ to $$$n$$$. All blocks have equal heights. The height of the $$$i$$$-th column is represented as $$$h_i$$$, which is the number of blocks stacked in the $$$i$$$-th column.Gildong plays the game as a character that can stand only on the top of the columns. At the beginning, the character is standing on the top of the $$$1$$$-st column. The goal of the game is to move the character to the top of the $$$n$$$-th column.The character also has a bag that can hold infinitely many blocks. When the character is on the top of the $$$i$$$-th column, Gildong can take one of the following three actions as many times as he wants:   if there is at least one block on the column, remove one block from the top of the $$$i$$$-th column and put it in the bag;  if there is at least one block in the bag, take one block out of the bag and place it on the top of the $$$i$$$-th column;  if $$$i < n$$$ and $$$|h_i - h_{i+1}| \le k$$$, move the character to the top of the $$$i+1$$$-st column. $$$k$$$ is a non-negative integer given at the beginning of the game. Note that it is only possible to move to the next column. In actions of the first two types the character remains in the $$$i$$$-th column, and the value $$$h_i$$$ changes.The character initially has $$$m$$$ blocks in the bag. Gildong wants to know if it is possible to win the game. Help Gildong find the answer to his question.

Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n \le 100$$$, $$$0 \le m \le 10^6$$$, $$$0 \le k \le 10^6$$$) — the number of columns in the game, the number of blocks in the character's bag at the beginning, and the non-negative integer $$$k$$$ described in the statement. The second line of each test case contains $$$n$$$ integers. The $$$i$$$-th integer is $$$h_i$$$ ($$$0 \le h_i \le 10^6$$$), the initial height of the $$$i$$$-th column.

For each test case, print "YES" if it is possible to win the game. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first case, Gildong can take one block from the $$$1$$$-st column, move to the $$$2$$$-nd column, put the block on the $$$2$$$-nd column, then move to the $$$3$$$-rd column.In the second case, Gildong has to put the block in his bag on the $$$1$$$-st column to get to the $$$2$$$-nd column. But it is impossible to get to the $$$3$$$-rd column because $$$|h_2 - h_3| = 3 > k$$$ and there is no way to decrease the gap.In the fifth case, the character is already on the $$$n$$$-th column from the start so the game is won instantly.

package main

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

/* solution */

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		if solveOne() {
			print("YES")
		} else {
			print("NO")
		}
	}
}

func solveOne() bool {
	n, m, k := readInt(), readInt(), readInt()
	cur := readInt()
	for i := 1; i < n; i++ {
		next := readInt()
		enough := next - k
		if enough < 0 {
			enough = 0
		}
		if cur > enough {
			m += cur - enough
		} else {
			m -= enough - cur
		}
		if m < 0 {
			for j := i + 1; j < n; j++ {
				readInt()
			}
			return false
		}
		cur = next
	}
	return true
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] >= heights[i] {
				// 0o
				m += heights[i-1] - heights[i]
				if k > heights[i] {
					m += heights[i]
				} else {
					m += k
				}

			} else {
				// o0
				if heights[i]-heights[i-1] <= k {
					if k > heights[i]{
						m += heights[i-1]
					} else {
						m += k - (heights[i] - heights[i-1])
					}
				} else {
					if absInt(heights[i]-heights[i-1], k) <= m {
						m -= absInt(heights[i]-heights[i-1], k)
						if m < 0 {
							win = false
							break
						}
					} else {
						win = false
						break
					}
				}
			}
		}

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

package main

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

// 1200
// 27.05.2020
// https://codeforces.com/problemset/problem/1200/B

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

	r := bufio.NewReader(os.Stdin)
LOOP:
	for tt := 0; tt < t; tt++ {
		var n, m, k int
		fmt.Fscanln(r, &n, &m, &k)
		b, _, err := r.ReadLine()
		if err != nil {
			panic(err)
		}
		str := string(b)

		strs := strings.SplitN(str, " ", n)

		next, cur := -1, -1
		for i := 0; i < n; i++ {
			cur = next
			var err error
			next, err = strconv.Atoi(strs[i])
			if err != nil {
				panic(err)
			}

			if cur == -1 {
				continue
			}
			u := next - k
			if u < 0 {
				u = 0
			}
			m += cur - u
			if m < 0 {
				fmt.Println("NO")
				continue LOOP
			}
		}
		fmt.Println("YES")
	}
}

package main

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readi()
		m := readll()
		k := readll()
		_, h := readIntsll(n)
		if solve(n, m, k, h) {
			println("YES")
		} else {
			println("NO")
		}
	}
}

func solve(n int, m, k int64, h []int64) bool {
	for i := 0; i+1 < n; i++ {
		b := maxll(0, h[i+1]-k)
		m += h[i] - b
		if m < 0 {
			return false
		}
	}
	return true
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n, m, k int
		_, err := fmt.Fscanf(input, "%d %d %d\n", &n, &m, &k)
		if err != nil {
		}

		var h = make([]int, n)
		for i := 0; i < n; i++ {
			_, err := fmt.Fscanf(input, "%v", &h[i])
			if err != nil {
			}
		}
		_, err = fmt.Fscanf(input, "\n")
		if err != nil {
		}

		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Println("YES")
				break
			}
			if h[i] <= h[i+1] {
				// i 个柱子比 i+1 个柱子低
				if h[i+1]-h[i] <= k {
					// i 个柱子比 i+1 个柱子 低 k 内
					if k > h[i+1] {
						m += h[i]
						continue
					}
					m += h[i] + k - h[i+1]
					continue
				} else if h[i+1]-h[i]-m <= k {
					// i 个柱子比 i+1 个柱子 低 k 外, 包内往外拿
					m += h[i] + k - h[i+1]
					continue
				} else {
					fmt.Println("NO")
					break
				}
			} else if h[i] > h[i+1] {
				// i 个柱子比 i+1 个柱子 高，外包里放
				if h[i+1] < k {
					// i 个柱子比 i+1 个柱子 高，外包里放, 第 i+1 个柱子比 k 低
					m += h[i]
					continue
				}
				m += h[i] + k - h[i+1]
				continue
			}
		}
	}

}

package main
import "fmt"
import "os"
import "bufio"

var input *bufio.Reader

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

func solve() {
    var n, m, k int
    fmt.Fscanf(input, "%d%d%d\n", &n, &m, &k)
    h := make([]int, n)
    for i:=0; i<n; i++ {
        fmt.Fscanf(input, "%d", &h[i])
    }
    fmt.Fscanf(input, "\n")
    for i:=1; i<n; i++ {
        if h[i-1]+m >= h[i]-k {
            if h[i-1]>=h[i]-k {
                m+=h[i-1]-max(0, h[i]-k)
            } else {
                m+=h[i-1]-(h[i]-k)
            }
        } else {
            fmt.Println("NO")
            return
        }
    }
    fmt.Println("YES")
}

func main(){
    input = bufio.NewReader(os.Stdin)
    var T int
    fmt.Fscanf(input, "%d\n", &T)
    for i:=0; i<T; i++ {
        solve()
    }
}

// Author: sighduck
// URL: https://codeforces.com/contest/1200/problem/B

package main

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

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

func Solve(n int, m int, k int, blocks []int) string {
	for i := 0; i < n-1; i++ {
		if blocks[i+1] <= blocks[i] {
			newHeight := max(blocks[i+1]-k, 0)
			blocksToAddOrRemove := blocks[i] - newHeight
			m += blocksToAddOrRemove
		} else if blocks[i+1] > blocks[i] {
			newHeight := max(blocks[i+1]-k, 0)
			blocksToAddOrRemove := newHeight - blocks[i]
			m -= blocksToAddOrRemove
		}
		if m < 0 {
			return "NO"
		}
	}
	return "YES"
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m, k int
		fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &k)
		blocks := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &blocks[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%s\n", Solve(n, m, k, blocks))
	}
}

package main

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

/* solution */

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		if solveOne() {
			print("YES")
		} else {
			print("NO")
		}
	}
}

func solveOne() bool {
	n, m, k := readInt(), readInt(), readInt()
	cur := readInt()
	for i := 1; i < n; i++ {
		next := readInt()
		enough := next - k
		if cur > enough {
			m += cur - enough
		} else {
			m -= enough - cur
		}
		if m < 0 {
			return false
		}
		cur = next
	}
	return true
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

/* solution */

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		if solveOne() {
			print("YES")
		} else {
			print("NO")
		}
	}
}

func solveOne() bool {
	n, m, k := readInt(), readInt(), readInt()
	cur := readInt()
	for i := 1; i < n; i++ {
		next := readInt()
		enough := next - k
		if cur > enough {
			m += cur - enough
		} else {
			m -= enough - cur
		}
		if m < 0 {
			return false
		}
		cur = enough
	}
	return true
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

/* solution */

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		if solveOne() {
			print("YES")
		} else {
			print("NO")
		}
	}
}

func solveOne() bool {
	n, m, k := readInt(), readInt(), readInt()
	cur := readInt()
	for i := 1; i < n; i++ {
		next := readInt()
		enough := next - k
		if cur > enough {
			m += cur - enough
		} else {
			m -= enough - cur
		}
		if m < 0 {
			for j := i + 1; j < n; j++ {
				readInt()
			}
			return false
		}
		cur = next
	}
	return true
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] >= heights[i] {
				// 0o
				m += heights[i-1] - heights[i]
				if k > heights[i] {
					m += heights[i]
				} else {
					m += k
				}

			} else {
				// o0
				if heights[i]-heights[i-1] <= k {
					if k-heights[i]-heights[i-1] > heights[i-1] {
						m += heights[i-1]
					} else {
						m += k - heights[i] - heights[i-1]
					}

				} else {
					if absInt(heights[i]-heights[i-1], k) <= m {
						m -= absInt(heights[i]-heights[i-1], k)
						if m < 0 {
							win = false
							break
						}
					} else {
						win = false
						break
					}
				}
			}
		}

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

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] >= heights[i] {
				// 0o
				m += heights[i-1] - heights[i]
				if k > heights[i] {
					m += heights[i]
				} else {
					m += k
				}

			} else {
				// o0
				if heights[i]-heights[i-1] < k {
					if k-heights[i]-heights[i-1] > heights[i-1] {
						m += heights[i-1]
					} else {
						m += k - heights[i] - heights[i-1]
					}

				} else {
					if absInt(heights[i]-heights[i-1], k) <= m {
						m -= absInt(heights[i]-heights[i-1], k)
						if m < 0 {
							win = false
							break
						}
					} else {
						win = false
						break
					}
				}
			}
		}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] >= heights[i] {
				m += heights[i-1] - heights[i] + k
				continue
			} else {
				if heights[i]-heights[i-1]-k <= m {
					m -= heights[i] - heights[i-1] - k
					if m < 0 {
						win = false
						break
					}
					continue
				} else {
					win = false
					break
				}
			}
		}

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

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] > heights[i] {
				m += heights[i-1] - heights[i] + k
				continue
			} else {
				if heights[i]-heights[i-1]-k <= m {
					m -= heights[i] - heights[i-1] - k
					if m < 0 {
						win = false
						break
					}
					continue
				} else {
					win = false
					break
				}
			}
		}

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

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] >= heights[i] {
				// 0o
				m += heights[i-1] - heights[i]
				if k > heights[i] {
					m += heights[i]
				} else {
					m += k
				}

			} else {
				// o0
				if absInt(heights[i]-heights[i-1], k) <= m {
					m -= absInt(heights[i]-heights[i-1], k)
					if m < 0 {
						win = false
						break
					}
				} else {
					win = false
					break
				}
			}
		}

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

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] >= heights[i] {
				// 0o
				m += heights[i-1] - heights[i]
				if k > heights[i] {
					m += heights[i]
				} else {
					m += k
				}

			} else {
				// o0
				if heights[i]-heights[i-1] <= k {
					if k-(heights[i]-heights[i-1]) > heights[i-1] {
						m += heights[i-1]
					} else {
						m += k - heights[i] - heights[i-1]
					}

				} else {
					if absInt(heights[i]-heights[i-1], k) <= m {
						m -= absInt(heights[i]-heights[i-1], k)
						if m < 0 {
							win = false
							break
						}
					} else {
						win = false
						break
					}
				}
			}
		}

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

package main

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

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var (
		total int
		n     int
		m     int
		k     int
	)

	_, _ = fmt.Fscan(input, &total)

	for total > 0 {
		total -= 1

		_, _ = fmt.Fscan(input, &n, &m, &k)
		heights := make([]int, n)
		for i := 0; i < n; i += 1 {
			_, _ = fmt.Fscan(input, &heights[i])
		}

		win := true
		for i := 1; i < n; i += 1 {
			if heights[i-1] > heights[i] {
				m += heights[i-1] - heights[i]
				continue
			} else {
				if heights[i]-heights[i-1]-k <= m {
					m -= heights[i] - heights[i-1] - k
					if m < 0 {
						win = false
						break
					}
					continue
				} else {
					win = false
					break
				}
			}
		}

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

package main

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

// 1200
// 27.05.2020
// https://codeforces.com/problemset/problem/1200/B

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

	r := bufio.NewReader(os.Stdin)
LOOP:
	for tt := 0; tt < t; tt++ {
		var n, m, k int
		fmt.Fscanln(r, &n, &m, &k)
		str, _ := r.ReadString('\n')
		strs := strings.SplitN(str, " ", n)
		strs[len(strs)-1] = strings.TrimSuffix(strs[len(strs)-1], "\n")

		next, cur := -1, -1
		for i := 0; i < n; i++ {
			cur = next
			next, _ = strconv.Atoi(strs[i])
			if cur == -1 {
				continue
			}
			m += cur - next + k
			if m < 0 {
				fmt.Println("NO")
				continue LOOP
			}
		}
		fmt.Println("YES")
	}
}

package main

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

// 1200
// 27.05.2020
// https://codeforces.com/problemset/problem/1200/B

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

	r := bufio.NewReader(os.Stdin)
LOOP:
	for tt := 0; tt < t; tt++ {
		var n, m, k int
		fmt.Fscanln(r, &n, &m, &k)
		b, _, err := r.ReadLine()
		if err != nil {
			panic(err)
		}
		str := string(b)

		strs := strings.SplitN(str, " ", n)

		next, cur := -1, -1
		for i := 0; i < n; i++ {
			cur = next
			var err error
			next, err = strconv.Atoi(strs[i])
			if err != nil {
				panic(err)
			}

			if cur == -1 {
				continue
			}
			m += cur - next + k
			if m < 0 {
				fmt.Println("NO")
				continue LOOP
			}
		}
		fmt.Println("YES")
	}
}

package main

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

// 1200
// 27.05.2020
// https://codeforces.com/problemset/problem/1200/B

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

LOOP:
	for tt := 0; tt < t; tt++ {
		var n, m, k int
		fmt.Scanln(&n, &m, &k)
		scn := bufio.NewScanner(os.Stdin)
		scn.Split(bufio.ScanWords)
		next, cur := -1, -1
		for i := 0; i < n && scn.Scan(); i++ {

			cur = next
			next, _ = strconv.Atoi(scn.Text())
			if cur == -1 {
				continue
			}
			m += cur - next + k
			if m < 0 {
				fmt.Println("NO")
				continue LOOP
			}
		}
		fmt.Println("YES")
	}
}

package main

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

// 1200
// 27.05.2020
// https://codeforces.com/problemset/problem/1200/B

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

LOOP:
	for tt := 0; tt < t; tt++ {
		var n, m, k int
		fmt.Scanln(&n, &m, &k)
		scn := bufio.NewScanner(os.Stdin)
		scn.Split(bufio.ScanWords)
		next, cur := -1, -1
		for i := 0; i < n; i++ {
			scn.Scan()
			cur = next
			next, _ = strconv.Atoi(scn.Text())
			if cur == -1 {
				continue
			}
			m += cur - next + k
			if m < 0 {
				fmt.Println("NO")
				continue LOOP
			}
		}
		fmt.Println("YES")
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n, m, k int
		_, err := fmt.Fscanf(input, "%d %d %d\n", &n, &m, &k)
		if err != nil {
		}

		var h = make([]int, n)
		for i := 0; i < n; i++ {
			_, err := fmt.Fscanf(input, "%v", &h[i])
			if err != nil {
			}
		}
		_, err = fmt.Fscanf(input, "\n")
		if err != nil {
		}

		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Println("YES")
				break
			}
			if h[i] <= h[i+1] {
				if h[i+1]-h[i]-m <= k {
					m += h[i] + k - h[i+1]
					continue
				} else {
					fmt.Println("NO")
					break
				}
			} else if h[i] > h[i+1] {
				m += h[i] + k - h[i+1]
				continue
			}
		}
	}

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n, m, k int
		_, err := fmt.Fscanf(input, "%d %d %d\n", &n, &m, &k)
		if err != nil {
		}

		var h = make([]int, n)
		for i := 0; i < n; i++ {
			_, err := fmt.Fscanf(input, "%v", &h[i])
			if err != nil {
			}
		}
		_, err = fmt.Fscanf(input, "\n")
		if err != nil {
		}

		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Println("YES")
				break
			}
			if h[i] <= h[i+1] {
				if h[i+1]-h[i] <= k {
					m += h[i] + k - h[i+1]
					continue
				} else if h[i+1]-h[i]-m <= k {
					m += h[i] + k - h[i+1]
					continue
				} else {
					fmt.Println("NO")
					break
				}
			} else if h[i] > h[i+1] {
				if h[i+1] < k {
					m += h[i]
					continue
				}
				m += h[i] + k - h[i+1]
				continue
			}
		}
	}

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n, m, k int
		_, err := fmt.Fscanf(input, "%d %d %d\n", &n, &m, &k)
		if err != nil {
		}

		var h = make([]int, n)
		for i := 0; i < n; i++ {
			_, err := fmt.Fscanf(input, "%v", &h[i])
			if err != nil {
			}
		}
		_, err = fmt.Fscanf(input, "\n")
		if err != nil {
		}

		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Println("YES")
				break
			}
			if h[i] <= h[i+1] {
				if h[i+1]-h[i] <= k {
					m += h[i] + k - h[i+1]
					continue
				} else if h[i+1]-h[i]-m <= k {
					m += h[i] + k - h[i+1]
					if m < 0 {
						fmt.Println("NO")
						break
					}
					continue
				} else {
					fmt.Println("NO")
					break
				}
			} else if h[i] > h[i+1] {
				if h[i+1] < k {
					m += h[i]
					continue
				}
				m += h[i] + k - h[i+1]
				continue
			}
		}
	}

}

package main
import "fmt"
import "os"
import "bufio"

var input *bufio.Reader

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

func solve() {
    var n, m, k int
    fmt.Fscanf(input, "%d%d%d\n", &n, &m, &k)
    h := make([]int, n)
    for i:=0; i<n; i++ {
        fmt.Fscanf(input, "%d", &h[i])
    }
    fmt.Fscanf(input, "\n")
    for i:=1; i<n; i++ {
        if h[i-1]+m >= h[i]-k {
            m+=h[i-1]-(h[i]-k)
        } else {
            fmt.Println("NO")
            return
        }
    }
    fmt.Println("YES")
}

func main(){
    input = bufio.NewReader(os.Stdin)
    var T int
    fmt.Fscanf(input, "%d\n", &T)
    for i:=0; i<T; i++ {
        solve()
    }
}

// Author: sighduck
// URL: https://codeforces.com/contest/1200/problem/B

package main

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

func Solve(n int, m int, k int, blocks []int) string {
	var blocksToAddOrRemove int
	for i := 0; i < n-1; i++ {
		if blocks[i+1] <= blocks[i] {
			newHeight := blocks[i+1] - k
			blocksToAddOrRemove = blocks[i] - newHeight
			m += blocksToAddOrRemove
		} else if blocks[i+1] > blocks[i] {
			newHeight := blocks[i+1] - k
			blocksToAddOrRemove = newHeight - blocks[i]
			m -= blocksToAddOrRemove
		}
		if m < 0 {
			return "NO"
		}
	}
	return "YES"
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m, k int
		fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &k)
		blocks := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &blocks[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%s\n", Solve(n, m, k, blocks))
	}
}


After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $$$n$$$. Let's call them $$$a$$$ and $$$b$$$.Note that a permutation of $$$n$$$ elements is a sequence of numbers $$$a_1, a_2, \ldots, a_n$$$, in which every number from $$$1$$$ to $$$n$$$ appears exactly once. The message can be decoded by an arrangement of sequence $$$a$$$ and $$$b$$$, such that the number of matching pairs of elements between them is maximum. A pair of elements $$$a_i$$$ and $$$b_j$$$ is said to match if:   $$$i = j$$$, that is, they are at the same index.  $$$a_i = b_j$$$ His two disciples are allowed to perform the following operation any number of times:   choose a number $$$k$$$ and cyclically shift one of the permutations to the left or right $$$k$$$ times. A single cyclic shift to the left on any permutation $$$c$$$ is an operation that sets $$$c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$$$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $$$c$$$ is an operation that sets $$$c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$$$ simultaneously.Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.

The first line of the input contains a single integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$ — the size of the arrays. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ $$$(1 \le a_i \le n)$$$ — the elements of the first permutation. The third line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ $$$(1 \le b_i \le n)$$$ — the elements of the second permutation.

Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.

NoteFor the first case: $$$b$$$ can be shifted to the right by $$$k = 1$$$. The resulting permutations will be $$$\{1, 2, 3, 4, 5\}$$$ and $$$\{1, 2, 3, 4, 5\}$$$.For the second case: The operation is not required. For all possible rotations of $$$a$$$ and $$$b$$$, the number of matching pairs won't exceed $$$1$$$.For the third case: $$$b$$$ can be shifted to the left by $$$k = 1$$$. The resulting permutations will be $$$\{1, 3, 2, 4\}$$$ and $$$\{2, 3, 1, 4\}$$$. Positions $$$2$$$ and $$$4$$$ have matching pairs of elements. For all possible rotations of $$$a$$$ and $$$b$$$, the number of matching pairs won't exceed $$$2$$$.

package main

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

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

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

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

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

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

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

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

	return i
}

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

	n := readNum(reader)

	A := readNNums(reader, n)
	B := readNNums(reader, n)

	fmt.Println(solve(n, A, B))
}

func solve(n int, A []int, B []int) int {
	pos := make([]int, n+1)

	for i := 0; i < n; i++ {
		pos[A[i]] = i
	}
	left := make([]int, n)
	right := make([]int, n)

	for i := 0; i < n; i++ {
		j := pos[B[i]]
		if i == j {
			left[0]++
			continue
		}
		if j < i {
			left[i-j]++
			right[j-i+n]++
		} else {
			left[i-j+n]++
			right[j-i]++
		}
	}

	res := left[0]

	for k := 1; k < n; k++ {
		if left[k] > res {
			res = left[k]
		}
		if right[k] > res {
			res = right[k]
		}
	}
	return res
}

package main

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

var checked []bool
var edges [][]int
var cnt int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		pos := make([]int, n+1)
		tmp := 0
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &tmp)
			pos[tmp] = i
		}
		fmt.Fscanf(in, "\n")
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &tmp)
			cnt[((i-pos[tmp])+n)%n]++
		}
		ans := 0
		for _, v := range cnt {
			if ans < v {
				ans = v
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func canWin(a []int) bool {
	//fmt.Println(a)
	if len(a) <= 1 {
		return true
	}
	sum := 0
	for i := range a {
		sum += a[i]
	}
	if (sum-2)%2 == 0 {
		return false
	}
	return true
}

func dfs(cur int) {
	cnt++
	checked[cur] = true
	for _, next := range edges[cur] {
		if !checked[next] {
			dfs(next)
		}
	}
}

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

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

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

func main() {
	//var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Println(solver())
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	a := make([]int, n + 1)
	b := make([]int, n + 1)
	for i := 0; i < n; i++ {
		var t int
		fmt.Fscan(input, &t)
		a[t] = i
	}
	for i := 0; i < n; i++ {
		var t int
		fmt.Fscan(input, &t)
		b[t] = i
	}
	sh := make([]int, n + 1)
	ans := 0
	for i := 1; i <= n; i++ {
		index := (a[i] - b[i] + n) % n
		sh[index]++
		ans = max(ans, sh[index])
	}

	return ans
}

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

package main

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

func main() {
	n := nextInt()
	fmt.Println(solve(nextInts(n), nextInts(n)))
}

func solve(as, bs []int) int {
	n := len(as)
	aIndexes := make([]int, n+1)
	bIndexes := make([]int, n+1)
	for i := 0; i < n; i++ {
		aIndexes[as[i]] = i
		bIndexes[bs[i]] = i
	}

	distToCount := make(map[int]int)
	for i := 1; i <= n; i++ {
		dist := aIndexes[i] - bIndexes[i]
		if dist < 0 {
			dist += n
		}
		distToCount[dist]++
	}

	ans := 0
	for _, c := range distToCount {
		ans = max(ans, c)
	}
	return ans
}

func max(xs ...int) int {
	ret := xs[0]
	for _, x := range xs[1:] {
		if ret < x {
			ret = x
		}
	}
	return ret
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

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

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	n    int
	A, B []int

	am   []int
	bnum []int
)

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)
	B = ReadIntSlice(n)

	am = make([]int, n+50)
	for i := 0; i < n; i++ {
		a := A[i]
		am[a] = i
	}

	bnum = make([]int, n+50)
	for j := 0; j < n; j++ {
		b := B[j]
		i := am[b]

		var num int
		if j <= i {
			num = i - j
		} else {
			num = n - (j - i)
		}
		bnum[num]++
	}

	ans := 0
	for i := 0; i <= n; i++ {
		ChMax(&ans, bnum[i])
	}
	fmt.Println(ans)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var n int
var a [200001]int
var b [200001]int
var pos [200001]int
var shift [200001]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n)

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

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

		s := pos[b[i]] - i
		if s < 0 {
			s += n
		}

		shift[i] = s
	}

	var cnt [200001]int
	res := 0
	for i := 0; i < n; i++ {
		cnt[shift[i]]++
		if cnt[shift[i]] > res {
			res = cnt[shift[i]]
		}
	}

	fmt.Fprint(out, res)
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1365C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, ans int
	Fscan(in, &n)
	cnt := make([]int, n)
	pos := make([]int, n+1)
	for i := range cnt {
		Fscan(in, &v)
		pos[v] = i
	}
	for i := range cnt {
		Fscan(in, &v)
		p := pos[v]
		if p < i {
			p += n
		}
		cnt[p-i]++
	}
	for _, c := range cnt {
		if c > ans {
			ans = c
		}
	}
	Fprint(out, ans)
}

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

package main

import (
	. "fmt"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b ; b = rc() {
		}
		for ; '0' <= b ; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	n := r()
	pos := make([]int, n+1)
	for i := 0; i < n; i++ {
		pos[r()] = i
	}
	cnt := make([]int, n)
	for i := 0; i < n; i++ {
		p := pos[r()]
		if p < i {
			p += n
		}
		cnt[p-i]++
	}
	ans := 0
	for _, c := range cnt {
		if c > ans {
			ans = c
		}
	}
	Print(ans)
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func z(a []int) []int{
	mas := make([]int, len(a))
	var l, r int
	for i := 1; i < len(a);i++ {
		if i <= r {
			mas[i] = min(r-i+ 1, mas[i - l])
		}
		for (i+mas[i] < len(a)) && (a[mas[i]] == a[i+mas[i]]) {
			mas[i]++
		}
		if i+mas[i]-1 > r {
			l, r = i, i+mas[i]-1
		}
	}
	return mas
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	ans := make([]int, n)
	var num int
	for i := 0;i < n;i++ {
		fmt.Fscan(in, &num)
		a[num-1] = i
	}
	fmt.Fscanf(in, "\n")
	for i := 0;i < n;i++ {
		fmt.Fscan(in, &num)
		if a[num-1] < i{
			ans[a[num-1]+n-i]++
		} else{
			ans[a[num-1]-i]++
		}
	}
	fmt.Fscanf(in, "\n")
	var Ans int
	for _, i := range ans {
		Ans = max(Ans, i)
	}
	fmt.Fprintln(out, Ans)
	return
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	scan := func(x ...interface{}) (n int, err error) {
		return fmt.Fscan(in, x...)
	}
	println := func(x ...interface{}) (n int, err error) {
		return fmt.Fprintln(out, x...)
	}

	var n int
	scan(&n)
	aPos := make([]int, n)
	bPos := make([]int, n)
	var x int
	for i := 0; i < n; i++ {
		scan(&x)
		aPos[x-1] = i
	}
	for i := 0; i < n; i++ {
		scan(&x)
		bPos[x-1] = i
	}
	moveCnt := make([]int, n+1)
	for i := 0; i < n; i++ {
		shift := bPos[i] - aPos[i]
		if shift < 0 {
			shift += n
		}
		moveCnt[shift]++
	}

	ans := 0
	for _, cnt := range moveCnt {
		if cnt > ans {
			ans = cnt
		}
	}
	println(ans)
}

package main

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

func solve(a []int, b map[int]int) string {
	v := make([]int, len(a))
	for i, vv := range a {
		vp := b[vv]
		v[((i-vp)+len(a))%len(a)] += 1

	}
	m := 0
	for _, vv := range v {
		if vv > m {
			m = vv
		}
	}
	return fmt.Sprint(m)
}

func output(i int, ans string) {
	fmt.Printf("%s\n", ans)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 10000000), 10000000)
	var numTests int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &numTests)
	scanner.Scan()
	v1 := make([]int, numTests)
	v2 := map[int]int{}
	s1 := strings.Split(scanner.Text(), " ")
	scanner.Scan()
	s2 := strings.Split(scanner.Text(), " ")

	for i := 0; i < numTests; i++ {
		v1[i], _ = strconv.Atoi(s1[i])
		vv, _ := strconv.Atoi(s2[i])
		v2[vv] = i
	}
	output(0, solve(v1, v2))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1365/problem/C

package main

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

func Solve(n int, a, b []int) int {
	al := make([]int, n+1)
	bl := make([]int, n+1)
	for i := 0; i < n; i++ {
		al[a[i]] = i
		bl[b[i]] = i
	}
	rotation := make([]int, n)
	for i := 1; i <= n; i++ {
		if al[i] <= bl[i] {
			rotation[bl[i]-al[i]] += 1
		} else {
			rotation[n-(al[i]-bl[i])] += 1
		}
	}
	max := 0
	for _, elem := range rotation {
		if elem > max {
			max = elem
		}
	}
	return max
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	fmt.Fscanf(reader, "\n")
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d ", &b[i])
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d\n", Solve(n, a, b))
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	n := reader.Int64()
	a := make([]int64, n)
	for i := range a {
		a[i] = reader.Int64()
	}
	b := make([]int64, n)
	for i := range b {
		b[i] = reader.Int64()
	}
	writer.Printf("%d\n", sol(a, b))
}

func sol(a, b []int64) int64 {
	posA := make([]int64, len(a))
	for i := range a {
		posA[a[i]-1] = int64(i)
	}
	posB := make([]int64, len(b))
	for i := range b {
		posB[b[i]-1] = int64(i)
	}
	dist := map[int64]int64{}
	for i := range posA {
		pa := posA[i]
		pb := posB[i]
		diff := (pb-pa+int64(len(a))) % int64(len(a))
		dist[diff]++
	}
	maxSoFar := int64(0)
	for _, d := range dist {
		maxSoFar = max(maxSoFar, d)
	}
	//writer.Printf("%+v %+v\n", posA, posB)
	//writer.Printf("%+v\n", dist)
	return maxSoFar
}