package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority int
	key      int
	sum      int64
}

func (o *node) cmp(b int) int8 {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) rotate(d int8) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root *node
}

func (t *treap) _put(o *node, key, val int) *node {
	if o == nil {
		return &node{priority: rand.Int(), key: key, sum: int64(val)}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key, val)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.sum += int64(val)
	}
	return o
}

func (t *treap) put(key, val int) { t.root = t._put(t.root, key, val) }

func (t *treap) max() int64 {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.sum
}

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz, hsz := 1, 0
		for _, w := range g[v] {
			if w != fa {
				s := f(w, v)
				sz += s
				if s > hsz {
					hsz = s
					hson[v] = w
				}
			}
		}
		return sz
	}
	f(0, -1)

	ans := make([]interface{}, n)
	var f2 func(v, fa int) (map[int]int, *treap)
	f2 = func(v, fa int) (map[int]int, *treap) {
		if hson[v] == 0 {
			ans[v] = a[v]
			return map[int]int{a[v]: 1}, &treap{&node{priority: 1, key: 1, sum: int64(a[v])}}
		}
		cnt, t := f2(hson[v], v)
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				sc, _ := f2(w, v)
				for c, num := range sc {
					if cnt[c] > 0 {
						t.put(cnt[c], -c)
					}
					cnt[c] += num
					t.put(cnt[c], c)
				}
			}
		}
		c := a[v]
		if cnt[c] > 0 {
			t.put(cnt[c], -c)
		}
		cnt[c]++
		t.put(cnt[c], c)
		ans[v] = t.max()
		return cnt, t
	}
	f2(0, -1)
	Fprint(out, ans...)
}

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

package main

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

type Node struct {
	Adj     []*Node
	Size    int   // The size of this subtree.
	Big     *Node // The biggest child.
	Subtree []*Node

	Color int
	Ans   int64
}

type Tree []Node

func initSize(p, x *Node) {
	x.Size = 1
	for _, y := range x.Adj {
		if y != p {
			initSize(x, y)
			x.Size += y.Size
		}
	}
}

func initBig(p, x *Node) {
	// Assumes x.Big == nil
	for _, y := range x.Adj {
		if y != p {
			if x.Big == nil || x.Big.Size < y.Size {
				x.Big = y
			}
			initBig(x, y)
		}
	}
}

func (root *Node) initSubtree(p, x *Node) {
	begin := len(root.Subtree)
	root.Subtree = append(root.Subtree, x)
	for _, y := range x.Adj {
		if y != p {
			root.initSubtree(x, y)
		}
	}
	end := len(root.Subtree)
	x.Subtree = root.Subtree[begin:end]
}

type helper struct {
	Cnt    []int // The count of each color.
	MaxCnt int
	Ans    int64
}

func (h *helper) update(color, delta int) {
	h.Cnt[color] += delta
	if h.Cnt[color] > h.MaxCnt {
		h.MaxCnt = h.Cnt[color]
		h.Ans = int64(color)
	} else if h.Cnt[color] == h.MaxCnt {
		h.Ans += int64(color)
	}
}

func (h *helper) dfsAns(p, x *Node, keep bool) {
	for _, y := range x.Adj {
		if y != p && y != x.Big {
			h.dfsAns(x, y, false)
		}
	}
	// Assumes h is empty, i.e. h.Cnt is empty, h.MaxCnt == 0 and h.Ans == 0.
	// Handles biggest child first to provide it a clean enviroment.
	if x.Big != nil {
		h.dfsAns(x, x.Big, true)
	}
	// Handles small children.
	for _, y := range x.Adj {
		if y != p && y != x.Big {
			for _, z := range y.Subtree {
				h.update(z.Color, +1)
			}
		}
	}
	// Handles x itself.
	h.update(x.Color, +1)
	x.Ans = h.Ans
	// Cleans up.
	if !keep {
		for _, z := range x.Subtree {
			h.update(z.Color, -1)
		}
		h.MaxCnt = 0
		h.Ans = 0
	}
}

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

	n := 0
	fmt.Fscan(reader, &n)
	tree := Tree(make([]Node, n))
	for i, _ := range tree {
		fmt.Fscan(reader, &tree[i].Color)
	}
	for i := 0; i < n-1; i++ {
		x, y := -1, -1
		fmt.Fscan(reader, &x, &y)
		x--
		y--
		tree[x].Adj = append(tree[x].Adj, &tree[y])
		tree[y].Adj = append(tree[y].Adj, &tree[x])
	}

	root := &tree[0]
	initSize(nil, root)
	initBig(nil, root)
	root.initSubtree(nil, root)
	h := &helper{
		Cnt: make([]int, n+5),
	}
	h.dfsAns(nil, &tree[0], true)
	for _, x := range tree {
		fmt.Fprint(writer, x.Ans, " ")
	}
	fmt.Fprintln(writer)
}

package main

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

const NMAX = 100000 + 5

var (
	n     int
	color = make([]int, NMAX)
	graph = make([][]int, NMAX)

	frecv   = make([]int, NMAX)
	best    int
	bestSum int64
	ans     = make([]int64, NMAX)
)

func insert(val int) {
	frecv[val]++
	if frecv[val] > best {
		best = frecv[val]
		bestSum = int64(val)
	} else if frecv[val] == best {
		bestSum += int64(val)
	}
}

var sz = make([]int, NMAX)

func dfsSz(node, father int) {
	sz[node] = 1
	for _, it := range graph[node] {
		if it != father {
			dfsSz(it, node)
			sz[node] += sz[it]
		}
	}
}

func addDfs(node, father int) {
	insert(color[node])
	for _, it := range graph[node] {
		if it != father {
			addDfs(it, node)
		}
	}
}

func removeDfs(node, father int) {
	frecv[color[node]] = 0
	for _, it := range graph[node] {
		if it != father {
			removeDfs(it, node)
		}
	}
}

func dfs(node, father int, keep bool) {
	mx, maxSon := -1, -1
	for _, it := range graph[node] {
		if it != father && sz[it] > mx {
			mx = sz[it]
			maxSon = it
		}
	}
	for _, it := range graph[node] {
		if it != father && it != maxSon {
			dfs(it, node, false)
		}
	}
	if maxSon != -1 {
		dfs(maxSon, node, true)
	}
	for _, it := range graph[node] {
		if it != father && it != maxSon {
			addDfs(it, node)
		}
	}
	insert(color[node])
	ans[node] = bestSum
	if !keep {
		best = 0
		bestSum = 0
		removeDfs(node, father)
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := 0
	fmt.Fscan(reader, &n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(reader, &color[i])
	}
	for i := 1; i <= n; i++ {
		a, b := 0, 0
		fmt.Fscan(reader, &a, &b)
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}
	dfsSz(1, 0)
	dfs(1, 0, false)
	for i := 1; i <= n; i++ {
		fmt.Fprintln(writer, ans[i])
	}
}

package main

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

type Node struct {
	Adj   []*Node
	Label int

	Color  int
	Cnt    map[int]int   // Color -> Amount of the color.
	Sum    map[int]int64 // Amount -> Sum of colors that have the amount.
	MaxCnt int
	Ans    int64
}

func (x *Node) Update(y *Node) {
	// Merge small to large.
	if len(x.Cnt) < len(y.Cnt) {
		x.Cnt, y.Cnt = y.Cnt, x.Cnt
		x.Sum, y.Sum = y.Sum, x.Sum
		x.MaxCnt, y.MaxCnt = y.MaxCnt, x.MaxCnt
	}
	for color, amount := range y.Cnt {
		if _, has := x.Cnt[color]; has {
			x.Sum[x.Cnt[color]] -= int64(color)
		}
		x.Cnt[color] += amount
		x.Sum[x.Cnt[color]] += int64(color)
		if x.MaxCnt < x.Cnt[color] {
			x.MaxCnt = x.Cnt[color]
		}
	}
}

type Tree []Node

func (t Tree) AddEdge(x, y int) {
	t[x].Adj = append(t[x].Adj, &t[y])
}

func dfs(p, x *Node) {
	x.Cnt = map[int]int{x.Color: 1}
	x.Sum = map[int]int64{1: int64(x.Color)}
	x.MaxCnt = 1
	for _, y := range x.Adj {
		if y != p {
			dfs(x, y)
			x.Update(y)
		}
	}
	x.Ans = x.Sum[x.MaxCnt]
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := 0
	fmt.Fscan(reader, &n)

	tree := Tree(make([]Node, n))
	for i := 0; i < n; i++ {
		tree[i].Label = i + 1
		fmt.Fscan(reader, &tree[i].Color)
	}

	for i := 0; i < n-1; i++ {
		x, y := 0, 0
		fmt.Fscan(reader, &x, &y)
		x--
		y--
		tree.AddEdge(x, y)
		tree.AddEdge(y, x)
	}

	dfs(nil, &tree[0])

	for _, x := range tree {
		fmt.Fprint(writer, x.Ans, " ")
	}
	fmt.Fprintln(writer)
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	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...) }

type GraphSolver struct {
	graph   map[int][]int
	weights []int
	dsu     []map[int]int
	res     []int64
	n       int
}

func NewGraphSolver(n int) *GraphSolver {
	return &GraphSolver{
		graph:   make(map[int][]int),
		weights: make([]int, n),
		res:     make([]int64, n),
		dsu:     make([]map[int]int, n),
		n:       n,
	}
}

func (p *GraphSolver) addEdge(u, v int) {
	if c, ok := p.graph[u]; ok {
		p.graph[u] = append(c, v)
	} else {
		p.graph[u] = []int{v}
	}

	if c, ok := p.graph[v]; ok {
		p.graph[v] = append(c, u)
	} else {
		p.graph[v] = []int{u}
	}
}

func (p *GraphSolver) dfs(at, parent int) (r, maxFreq int, sumOfMaxFreq int64) {
	p.dsu[at], r = make(map[int]int), at
	p.dsu[at][p.weights[at]] = 1

	maxFreq, sumOfMaxFreq = 1, int64(p.weights[at])
	for _, v := range p.graph[at] {
		if v == parent {
			continue
		}

		x, xMaxFreq, xSumOfMaxFreq := p.dfs(v, at)
		if len(p.dsu[x]) > len(p.dsu[r]) {
			x, r = r, x
			maxFreq, sumOfMaxFreq = xMaxFreq, xSumOfMaxFreq
		}

		for key, count := range p.dsu[x] {
			tmpCount := p.dsu[r][key] + count
			// if at == 0 {
			// 	fmt.Println(key, count)
			// }

			if maxFreq == tmpCount {
				sumOfMaxFreq += int64(key)
			} else if maxFreq < tmpCount {
				maxFreq, sumOfMaxFreq = tmpCount, int64(key)
			}

			p.dsu[r][key] = tmpCount
		}
	}

	p.res[at] = sumOfMaxFreq
	return
}

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)

	var u, v int
	graphSolver := NewGraphSolver(n)
	for i := 0; i < n; i++ {
		scanf("%d", &graphSolver.weights[i])
	}
	scanf("\n")

	for i := 0; i < n-1; i++ {
		scanf("%d %d\n", &u, &v)
		graphSolver.addEdge(u-1, v-1)
	}

	graphSolver.dfs(0, -1)
	for i := 0; i < n; i++ {
		printf("%d ", graphSolver.res[i])
	}
	printf("\n")
}

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority int
	key      int
	sum      int64
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root *node
}

func (t *treap) _put(o *node, key, val int) *node {
	if o == nil {
		return &node{priority: rand.Int(), key: key, sum: int64(val)}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key, val)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.sum += int64(val)
	}
	return o
}

func (t *treap) put(key, val int) { t.root = t._put(t.root, key, val) }

func (t *treap) max() int64 {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.sum
}

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz, hsz := 1, 0
		for _, w := range g[v] {
			if w != fa {
				s := f(w, v)
				sz += s
				if s > hsz {
					hsz = s
					hson[v] = w
				}
			}
		}
		return sz
	}
	f(0, -1)

	ans := make([]interface{}, n)
	var f2 func(v, fa int) (map[int]int, *treap)
	f2 = func(v, fa int) (map[int]int, *treap) {
		if hson[v] == 0 {
			ans[v] = a[v]
			return map[int]int{a[v]: 1}, &treap{&node{key: 1, sum: int64(a[v])}}
		}
		cnt, t := f2(hson[v], v)
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				sc, _ := f2(w, v)
				for c, num := range sc {
					if cnt[c] > 0 {
						t.put(cnt[c], -c)
					}
					cnt[c] += num
					t.put(cnt[c], c)
				}
			}
		}
		c := a[v]
		if cnt[c] > 0 {
			t.put(cnt[c], -c)
		}
		cnt[c]++
		t.put(cnt[c], c)
		ans[v] = t.max()
		return cnt, t
	}
	f2(0, -1)
	Fprint(out, ans...)
}

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

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz, hsz := 1, 0
		for _, w := range g[v] {
			if w != fa {
				s := f(w, v)
				sz += s
				if s > hsz {
					hsz = s
					hson[v] = w
				}
			}
		}
		return sz
	}
	f(0, -1)

	ans := make([]interface{}, n)
	var f2 func(v, fa int) (map[int]int, map[int]int64, int)
	f2 = func(v, fa int) (cnt map[int]int, val map[int]int64, maxCnt int) {
		if hson[v] == 0 {
			ans[v] = a[v]
			return map[int]int{a[v]: 1}, map[int]int64{1: int64(a[v])}, 1
		}
		cnt, val, maxCnt = f2(hson[v], v)
		merge := func(c, num int) {
			if cnt[c] > 0 {
				val[cnt[c]] -= int64(c)
			}
			cnt[c] += num
			val[cnt[c]] += int64(c)
			if cnt[c] > maxCnt {
				maxCnt = cnt[c]
			}
		}
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				sc, _, _ := f2(w, v)
				for c, num := range sc {
					merge(c, num)
				}
			}
		}
		merge(a[v], 1)
		ans[v] = val[maxCnt]
		return
	}
	f2(0, -1)
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key      int
	sum      int64
}

func (o *node) cmp(b int) int8 {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) rotate(d int8) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key, val int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key, sum: int64(val)} // todo : rand.Int()
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key, val)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.sum += int64(val)
	}
	return o
}

func (t *treap) put(key, val int) { t.root = t._put(t.root, key, val) }

func (t *treap) max() int64 {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.sum
}

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz, hsz := 1, 0
		for _, w := range g[v] {
			if w != fa {
				s := f(w, v)
				sz += s
				if s > hsz {
					hsz = s
					hson[v] = w
				}
			}
		}
		return sz
	}
	f(0, -1)

	ans := make([]interface{}, n)
	var f2 func(v, fa int) (map[int]int, *treap)
	f2 = func(v, fa int) (map[int]int, *treap) {
		if hson[v] == 0 {
			ans[v] = a[v]
			return map[int]int{a[v]: 1}, &treap{1, &node{priority: 1, key: 1, sum: int64(a[v])}}
		}
		cnt, t := f2(hson[v], v)
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				sc, _ := f2(w, v)
				for c, num := range sc {
					if cnt[c] > 0 {
						t.put(cnt[c], -c)
					}
					cnt[c] += num
					t.put(cnt[c], c)
				}
			}
		}
		c := a[v]
		if cnt[c] > 0 {
			t.put(cnt[c], -c)
		}
		cnt[c]++
		t.put(cnt[c], c)
		ans[v] = t.max()
		return cnt, t
	}
	f2(0, -1)
	Fprint(out, ans...)
}

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

// Codeforces c600Ev7.go
// http://codeforces.com/blog/entry/44351
package main

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

type Node struct {
	Adj     []*Node
	Parent  *Node
	Size    int   // The size of this subtree.
	Big     *Node // The biggest child.
	Subtree []*Node

	Color int
	Ans   int64
}

type Tree []Node

func (x *Node) InitParent(p *Node) {
	x.Parent = p
	for _, y := range x.Adj {
		if y != p {
			y.InitParent(x)
		}
	}
}

// Depends on InitParent.
func (x *Node) InitSize() {
	x.Size = 1
	x.ForAll(func(y *Node) {
		y.InitSize()
		x.Size += y.Size
	})
}

// Depends on InitParent and InitSize.
func (x *Node) InitBig() {
	// Assumes x.Big == nil
	x.ForAll(func(y *Node) {
		if x.Big == nil || x.Big.Size < y.Size {
			x.Big = y
		}
		y.InitBig()
	})
}

// Depends on InitParent.
func (x *Node) InitSubtree(root *Node) {
	begin := len(root.Subtree)
	root.Subtree = append(root.Subtree, x)
	x.ForAll(func(y *Node) {
		y.InitSubtree(root)
	})
	end := len(root.Subtree)
	x.Subtree = root.Subtree[begin:end]
}

// Depends on InitParent.
func (x *Node) ForAll(handle func(*Node)) {
	for _, y := range x.Adj {
		if y != x.Parent {
			handle(y)
		}
	}
}

// Depends on InitParent and InitBig.
func (x *Node) ForSmall(handle func(*Node)) {
	for _, y := range x.Adj {
		if y != x.Parent && y != x.Big {
			handle(y)
		}
	}
}

type helper struct {
	Cnt    []int // The count of each color.
	MaxCnt int
	Ans    int64
}

func (h *helper) update(color, delta int) {
	h.Cnt[color] += delta
	if h.Cnt[color] > h.MaxCnt {
		h.MaxCnt = h.Cnt[color]
		h.Ans = int64(color)
	} else if h.Cnt[color] == h.MaxCnt {
		h.Ans += int64(color)
	}
}

func (h *helper) dfsAns(x *Node, keep bool) {
	x.ForSmall(func(y *Node) {
		h.dfsAns(y, false)
	})
	// Assumes h is empty, i.e. h.Cnt is empty, h.MaxCnt == 0 and h.Ans == 0.
	// Handles biggest child first to provide it a clean enviroment.
	if x.Big != nil {
		h.dfsAns(x.Big, true)
	}
	// Handles small children.
	x.ForSmall(func(y *Node) {
		for _, z := range y.Subtree {
			h.update(z.Color, +1)
		}
	})
	// Handles x itself.
	h.update(x.Color, +1)
	x.Ans = h.Ans
	// Cleans up.
	if !keep {
		for _, z := range x.Subtree {
			h.update(z.Color, -1)
		}
		h.MaxCnt = 0
		h.Ans = 0
	}
}

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

	n := 0
	fmt.Fscan(reader, &n)
	tree := Tree(make([]Node, n))
	for i, _ := range tree {
		fmt.Fscan(reader, &tree[i].Color)
	}
	for i := 0; i < n-1; i++ {
		x, y := -1, -1
		fmt.Fscan(reader, &x, &y)
		x--
		y--
		tree[x].Adj = append(tree[x].Adj, &tree[y])
		tree[y].Adj = append(tree[y].Adj, &tree[x])
	}

	root := &tree[0]
	root.InitParent(nil)
	root.InitSize()
	root.InitBig()
	root.InitSubtree(root)
	h := &helper{
		Cnt: make([]int, n+5),
	}
	h.dfsAns(&tree[0], true)
	for _, x := range tree {
		fmt.Fprint(writer, x.Ans, " ")
	}
	fmt.Fprintln(writer)
}

package main

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

type Node struct {
	Adj  []*Node
	Size int   // The size of this subtree.
	Big  *Node // The biggest child.

	Color int
	Ans   int64
}

type Tree []Node

func initSize(p, x *Node) {
	x.Size = 1
	for _, y := range x.Adj {
		if y != p {
			initSize(x, y)
			x.Size += y.Size
		}
	}
}

func initBig(p, x *Node) {
	// Assumes x.Big == nil
	for _, y := range x.Adj {
		if y != p {
			if x.Big == nil || x.Big.Size < y.Size {
				x.Big = y
			}
			initBig(x, y)
		}
	}
}

type helper struct {
	Cnt    []int // The count of each color.
	MaxCnt int
	Ans    int64
}

func (h *helper) update(color, delta int) {
	h.Cnt[color] += delta
	if h.Cnt[color] > h.MaxCnt {
		h.MaxCnt = h.Cnt[color]
		h.Ans = int64(color)
	} else if h.Cnt[color] == h.MaxCnt {
		h.Ans += int64(color)
	}
}

func (h *helper) smallWalk(p, x *Node) {
	h.update(x.Color, +1)
	for _, y := range x.Adj {
		if y != p {
			h.smallWalk(x, y)
		}
	}
}

func (h *helper) walk(p, x *Node) {
	h.update(x.Color, -1)
	for _, y := range x.Adj {
		if y != p {
			h.walk(x, y)
		}
	}
}

func (h *helper) dfsAns(p, x *Node, keep bool) {
	for _, y := range x.Adj {
		if y != p && y != x.Big {
			h.dfsAns(x, y, false)
		}
	}
	// Assumes h is empty, i.e. h.Cnt is empty, h.MaxCnt == 0 and h.Ans == 0.
	// Handles biggest child first to provide it a clean enviroment.
	if x.Big != nil {
		h.dfsAns(x, x.Big, true)
	}
	// Handles small children.
	for _, y := range x.Adj {
		if y != p && y != x.Big {
			h.smallWalk(x, y)
		}
	}
	// Handles x itself.
	h.update(x.Color, +1)
	x.Ans = h.Ans
	// Cleans up.
	if !keep {
		h.walk(p, x)
		h.MaxCnt = 0
		h.Ans = 0
	}
}

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

	n := 0
	fmt.Fscan(reader, &n)
	tree := Tree(make([]Node, n))
	for i, _ := range tree {
		fmt.Fscan(reader, &tree[i].Color)
	}
	for i := 0; i < n-1; i++ {
		x, y := -1, -1
		fmt.Fscan(reader, &x, &y)
		x--
		y--
		tree[x].Adj = append(tree[x].Adj, &tree[y])
		tree[y].Adj = append(tree[y].Adj, &tree[x])
	}

	initSize(nil, &tree[0])
	initBig(nil, &tree[0])
	h := &helper{
		Cnt: make([]int, n+5),
	}
	h.dfsAns(nil, &tree[0], true)
	for _, x := range tree {
		fmt.Fprint(writer, x.Ans, " ")
	}
	fmt.Fprintln(writer)
}

package main

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

type Node struct {
	Adj   []*Node
	Label int

	Size    int
	HChild  *Node   // The heaviest child.
	Subtree []*Node // Subtree rooted at this node.

	Color int
	Ans   int64
}

func (n *Node) String() string {
	return fmt.Sprint(n.Label)
}

type Tree []Node

func (t Tree) AddEdge(x, y int) {
	t[x].Adj = append(t[x].Adj, &t[y])
}

func (x *Node) InitSize(p *Node) {
	x.Size = 1
	for _, y := range x.Adj {
		if y != p {
			y.InitSize(x)
			x.Size += y.Size
		}
	}
}

func (x *Node) InitHChild(p *Node) {
	x.HChild = nil
	for _, y := range x.Adj {
		if y != p {
			y.InitHChild(x)
			if x.HChild == nil || x.HChild.Size < y.Size {
				x.HChild = y
			}
		}
	}
}

func (x *Node) InitSubtree(p *Node, log *[]*Node) {
	begin := len(*log)
	*log = append(*log, x)
	for _, y := range x.Adj {
		if y != p {
			y.InitSubtree(x, log)
		}
	}
	end := len(*log)
	x.Subtree = (*log)[begin:end]
}

const NMAX = 100000 + 5

var (
	frecv   = make([]int, NMAX)
	best    int
	bestSum int64
)

func insert(val int) {
	frecv[val]++
	if frecv[val] > best {
		best = frecv[val]
		bestSum = int64(val)
	} else if frecv[val] == best {
		bestSum += int64(val)
	}
}

func dfsColor(p, x *Node, keep bool, cnt []int) {
	// Solve light children first.
	for _, y := range x.Adj {
		if y != p && y != x.HChild {
			dfsColor(x, y, false, cnt)
		}
	}
	// Solve node x.
	if x.HChild != nil {
		dfsColor(x, x.HChild, true, cnt)
	}
	for _, y := range x.Adj {
		if y != p && y != x.HChild {
			for _, s := range y.Subtree {
				insert(s.Color)
			}
		}
	}
	insert(x.Color)
	// Update answer.
	x.Ans = bestSum
	// Tear down.
	if !keep {
		best = 0
		bestSum = 0
		for _, s := range x.Subtree {
			frecv[s.Color] = 0
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscan(reader, &n)

	tree := Tree(make([]Node, n+1))
	for i := 1; i <= n; i++ {
		tree[i].Label = i
		fmt.Fscan(reader, &tree[i].Color)
	}

	for i := 0; i < n-1; i++ {
		x, y := 0, 0
		fmt.Fscan(reader, &x, &y)
		tree.AddEdge(x, y)
		tree.AddEdge(y, x)
	}

	tree[1].InitSize(nil)
	tree[1].InitHChild(nil)
	tree[1].InitSubtree(nil, &[]*Node{})

	dfsColor(nil, &tree[1], true, make([]int, n+1))

	writer := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(writer, tree[i].Ans, " ")
	}
	fmt.Fprintln(writer)
	writer.Flush()
}

// Codeforces c600Ev7.go rejudge
// http://codeforces.com/blog/entry/44351
package main

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

type Node struct {
	Adj     []*Node
	Parent  *Node
	Size    int   // The size of this subtree.
	Big     *Node // The biggest child.
	Subtree []*Node

	Color int
	Ans   int64
}

type Tree []Node

func (x *Node) InitParent(p *Node) {
	x.Parent = p
	for _, y := range x.Adj {
		if y != p {
			y.InitParent(x)
		}
	}
}

// Depends on InitParent.
func (x *Node) InitSize() {
	x.Size = 1
	x.ForAll(func(y *Node) {
		y.InitSize()
		x.Size += y.Size
	})
}

// Depends on InitParent and InitSize.
func (x *Node) InitBig() {
	// Assumes x.Big == nil
	x.ForAll(func(y *Node) {
		if x.Big == nil || x.Big.Size < y.Size {
			x.Big = y
		}
		y.InitBig()
	})
}

// Depends on InitParent.
func (x *Node) InitSubtree(root *Node) {
	begin := len(root.Subtree)
	root.Subtree = append(root.Subtree, x)
	x.ForAll(func(y *Node) {
		y.InitSubtree(root)
	})
	end := len(root.Subtree)
	x.Subtree = root.Subtree[begin:end]
}

// Depends on InitParent.
func (x *Node) ForAll(handle func(*Node)) {
	for _, y := range x.Adj {
		if y != x.Parent {
			handle(y)
		}
	}
}

// Depends on InitParent and InitBig.
func (x *Node) ForSmall(handle func(*Node)) {
	for _, y := range x.Adj {
		if y != x.Parent && y != x.Big {
			handle(y)
		}
	}
}

type helper struct {
	Cnt    []int // The count of each color.
	MaxCnt int
	Ans    int64
}

func (h *helper) update(color, delta int) {
	h.Cnt[color] += delta
	if h.Cnt[color] > h.MaxCnt {
		h.MaxCnt = h.Cnt[color]
		h.Ans = int64(color)
	} else if h.Cnt[color] == h.MaxCnt {
		h.Ans += int64(color)
	}
}

func (h *helper) dfsAns(x *Node, keep bool) {
	x.ForSmall(func(y *Node) {
		h.dfsAns(y, false)
	})
	// Assumes h is empty, i.e. h.Cnt is empty, h.MaxCnt == 0 and h.Ans == 0.
	// Handles biggest child first to provide it a clean enviroment.
	if x.Big != nil {
		h.dfsAns(x.Big, true)
	}
	// Handles small children.
	x.ForSmall(func(y *Node) {
		for _, z := range y.Subtree {
			h.update(z.Color, +1)
		}
	})
	// Handles x itself.
	h.update(x.Color, +1)
	x.Ans = h.Ans
	// Cleans up.
	if !keep {
		for _, z := range x.Subtree {
			h.update(z.Color, -1)
		}
		h.MaxCnt = 0
		h.Ans = 0
	}
}

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

	n := 0
	fmt.Fscan(reader, &n)
	tree := Tree(make([]Node, n))
	for i, _ := range tree {
		fmt.Fscan(reader, &tree[i].Color)
	}
	for i := 0; i < n-1; i++ {
		x, y := -1, -1
		fmt.Fscan(reader, &x, &y)
		x--
		y--
		tree[x].Adj = append(tree[x].Adj, &tree[y])
		tree[y].Adj = append(tree[y].Adj, &tree[x])
	}

	root := &tree[0]
	root.InitParent(nil)
	root.InitSize()
	root.InitBig()
	root.InitSubtree(root)
	h := &helper{
		Cnt: make([]int, n+5),
	}
	h.dfsAns(&tree[0], true)
	for _, x := range tree {
		fmt.Fprint(writer, x.Ans, " ")
	}
	fmt.Fprintln(writer)
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	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...) }

type GraphSolver struct {
	graph   map[int][]int
	weights []int
	dsu     []map[int]int
	res     []int
	n       int
}

func NewGraphSolver(n int) *GraphSolver {
	return &GraphSolver{
		graph:   make(map[int][]int),
		weights: make([]int, n),
		res:     make([]int, n),
		dsu:     make([]map[int]int, n),
		n:       n,
	}
}

func (p *GraphSolver) addEdge(u, v int) {
	if c, ok := p.graph[u]; ok {
		p.graph[u] = append(c, v)
	} else {
		p.graph[u] = []int{v}
	}

	if c, ok := p.graph[v]; ok {
		p.graph[v] = append(c, u)
	} else {
		p.graph[v] = []int{u}
	}
}

func (p *GraphSolver) dfs(at, parent int) (r, maxFreq, sumOfMaxFreq int) {
	p.dsu[at], r = make(map[int]int), at
	p.dsu[at][p.weights[at]] = 1

	maxFreq, sumOfMaxFreq = 1, p.weights[at]
	for _, v := range p.graph[at] {
		if v == parent {
			continue
		}

		x, xMaxFreq, xSumOfMaxFreq := p.dfs(v, at)
		if len(p.dsu[x]) > len(p.dsu[r]) {
			x, r = r, x
			maxFreq, sumOfMaxFreq = xMaxFreq, xSumOfMaxFreq
		}

		for key, count := range p.dsu[x] {
			tmpCount := p.dsu[r][key] + count
			// if at == 0 {
			// 	fmt.Println(key, count)
			// }

			if maxFreq == tmpCount {
				sumOfMaxFreq += key
			} else if maxFreq < tmpCount {
				maxFreq, sumOfMaxFreq = tmpCount, key
			}

			p.dsu[r][key] = tmpCount
		}
	}

	p.res[at] = sumOfMaxFreq
	return
}

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)

	var u, v int
	graphSolver := NewGraphSolver(n)
	for i := 0; i < n; i++ {
		scanf("%d", &graphSolver.weights[i])
	}
	scanf("\n")

	for i := 0; i < n-1; i++ {
		scanf("%d %d\n", &u, &v)
		graphSolver.addEdge(u-1, v-1)
	}

	graphSolver.dfs(0, -1)
	for i := 0; i < n; i++ {
		printf("%d ", graphSolver.res[i])
	}
	printf("\n")
}

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key, val int
}

func (o *node) cmp(b int) int8 {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) rotate(d int8) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key, val int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key, val: val} // todo : rand.Int()
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key, val)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	} else {
		o.val += val
	}
	return o
}

func (t *treap) put(key, val int) { t.root = t._put(t.root, key, val) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.val
}

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz, hsz := 1, 0
		for _, w := range g[v] {
			if w != fa {
				s := f(w, v)
				sz += s
				if s > hsz {
					hsz = s
					hson[v] = w
				}
			}
		}
		return sz
	}
	f(0, -1)

	ans := make([]interface{}, n)
	var f2 func(v, fa int) (map[int]int, *treap)
	f2 = func(v, fa int) (map[int]int, *treap) {
		if hson[v] == 0 {
			ans[v] = a[v]
			return map[int]int{a[v]: 1}, &treap{1, &node{priority: 1, key: 1, val: a[v]}}
		}
		cnt, t := f2(hson[v], v)
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				sc, _ := f2(w, v)
				for c, num := range sc {
					if cnt[c] > 0 {
						t.put(cnt[c], -c)
					}
					cnt[c] += num
					t.put(cnt[c], c)
				}
			}
		}
		c := a[v]
		if cnt[c] > 0 {
			t.put(cnt[c], -c)
		}
		cnt[c]++
		t.put(cnt[c], c)
		ans[v] = t.max()
		return cnt, t
	}
	f2(0, -1)
	Fprint(out, ans...)
}

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

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz, hsz := 1, 0
		for _, w := range g[v] {
			if w != fa {
				s := f(w, v)
				sz += s
				if s > hsz {
					hsz = s
					hson[v] = w
				}
			}
		}
		return sz
	}
	f(0, -1)

	ans := make([]interface{}, n)
	var f2 func(v, fa int) (cnt, val map[int]int, maxCnt int)
	f2 = func(v, fa int) (cnt, val map[int]int, maxCnt int) {
		if hson[v] == 0 {
			ans[v] = a[v]
			return map[int]int{a[v]: 1}, map[int]int{1: a[v]}, 1
		}
		cnt, val, maxCnt = f2(hson[v], v)
		merge := func(c, num int) {
			if cnt[c] > 0 {
				val[cnt[c]] -= c
			}
			cnt[c] += num
			val[cnt[c]] += c
			if cnt[c] > maxCnt {
				maxCnt = cnt[c]
			}
		}
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				sc, _, _ := f2(w, v)
				for c, num := range sc {
					merge(c, num)
				}
			}
		}
		merge(a[v], 1)
		ans[v] = val[maxCnt]
		return
	}
	f2(0, -1)
	Fprint(out, ans...)
}

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

// Codeforces c600Ev7.go
// http://codeforces.com/blog/entry/44351
package main

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

type Node struct {
	Adj     []*Node
	Parent  *Node
	Size    int   // The size of this subtree.
	Big     *Node // The biggest child.
	Subtree []*Node

	Color int
	Ans   int64
}

type Tree []Node

func (x *Node) InitParent(p *Node) {
	x.Parent = p
	for _, y := range x.Adj {
		if y != p {
			y.InitParent(x)
		}
	}
}

// Depends on InitParent.
func (x *Node) InitSize() {
	x.Size = 1
	x.ForAll(func(y *Node) {
		y.InitSize()
		x.Size += y.Size
	})
}

// Depends on InitParent and InitSize.
func (x *Node) InitBig() {
	// Assumes x.Big == nil
	x.ForAll(func(y *Node) {
		if x.Big == nil || x.Big.Size < y.Size {
			x.Big = y
		}
		y.InitBig()
	})
}

// Depends on InitParent.
func (x *Node) InitSubtree(root *Node) {
	begin := len(root.Subtree)
	root.Subtree = append(root.Subtree, x)
	x.ForAll(func(y *Node) {
		y.InitSubtree(root)
	})
	end := len(root.Subtree)
	x.Subtree = root.Subtree[begin:end]
}

// Depends on InitParent.
func (x *Node) ForAll(handle func(*Node)) {
	for _, y := range x.Adj {
		if y != x.Parent {
			handle(y)
		}
	}
}

// Depends on InitParent and InitBig.
func (x *Node) ForSmall(handle func(*Node)) {
	for _, y := range x.Adj {
		if y != x.Parent && y != x.Big {
			handle(y)
		}
	}
}

type helper struct {
	Cnt    []int // The count of each color.
	MaxCnt int
	Ans    int64
}

func (h *helper) update(color, delta int) {
	h.Cnt[color] += delta
	if h.Cnt[color] > h.MaxCnt {
		h.MaxCnt = h.Cnt[color]
		h.Ans = int64(color)
	} else if h.Cnt[color] == h.MaxCnt {
		h.Ans += int64(color)
	}
}

func (h *helper) dfsAns(x *Node, keep bool) {
	x.ForSmall(func(y *Node) {
		h.dfsAns(y, false)
	})
	// Assumes h is empty, i.e. h.Cnt is empty, h.MaxCnt == 0 and h.Ans == 0.
	// Handles biggest child first to provide it a clean enviroment.
	if x.Big != nil {
		h.dfsAns(x.Big, true)
	}
	// Handles small children.
	x.ForSmall(func(s *Node) {
		h.update(s.Color, +1)
	})
	// Handles x itself.
	h.update(x.Color, +1)
	x.Ans = h.Ans
	// Cleans up.
	if !keep {
		for _, z := range x.Subtree {
			h.update(z.Color, -1)
		}
		h.MaxCnt = 0
		h.Ans = 0
	}
}

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

	n := 0
	fmt.Fscan(reader, &n)
	tree := Tree(make([]Node, n))
	for i, _ := range tree {
		fmt.Fscan(reader, &tree[i].Color)
	}
	for i := 0; i < n-1; i++ {
		x, y := -1, -1
		fmt.Fscan(reader, &x, &y)
		x--
		y--
		tree[x].Adj = append(tree[x].Adj, &tree[y])
		tree[y].Adj = append(tree[y].Adj, &tree[x])
	}

	root := &tree[0]
	root.InitParent(nil)
	root.InitSize()
	root.InitBig()
	root.InitSubtree(root)
	h := &helper{
		Cnt: make([]int, n+5),
	}
	h.dfsAns(&tree[0], true)
	for _, x := range tree {
		fmt.Fprint(writer, x.Ans, " ")
	}
	fmt.Fprintln(writer)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1358D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	var x, ans int64
	Fscan(in, &n, &x)
	d := make([]int64, n)
	for i := range d {
		Fscan(in, &d[i])
	}
	d = append(d, d...)
	n *= 2
	sumD := make([]int64, n+1)
	sumH := make([]int64, n+1)
	for i, c := range d {
		sumD[i+1] = sumD[i] + c
		sumH[i+1] = sumH[i] + c*(c+1)/2
	}
	for r := 1; r <= n; r++ {
		l := sort.Search(r, func(i int) bool { return sumD[r]-sumD[i] <= x })
		sd := sumD[r] - sumD[l]
		sh := sumH[r] - sumH[l]
		if l > 0 {
			c := x - sd
			sh += c * (2*d[l-1] - c + 1) / 2
		}
		if sh > ans {
			ans = sh
		}
	}
	Fprint(_w, ans)
}

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

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

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

var p []int
var c []int
var children [][]int
var invalid bool

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, m := 0, int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([]int64, n)
		b := make([]int64, n)
		c := make([]int64, n)
		d := make([]int64, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
			b[i] = (1 + a[i]) * a[i] / 2
			sum += b[i]
			if i == 0 {
				c[i] = a[i]
				d[i] = b[i]
			} else {
				c[i] = c[i-1] + a[i]
				d[i] = d[i-1] + b[i]
			}
		}
		//fmt.Println(n, m, a)
		fmt.Fscanf(in, "\n")
		ans := sum * (m / c[n-1])
		m %= c[n-1]
		best := int64(0)
		if m > 0 {
			for i := 0; i < n; i++ {
				l := 1
				r := n
				for l < r {
					mid := (l + r) / 2
					from := i - mid + 1
					days := c[i]
					if from < 0 {
						days += c[n-1] - c[n+from-1]
					} else if from > 0 {
						days -= c[from-1]
					}
					if days < m {
						l = mid + 1
					} else {
						r = mid
					}
				}
				from := i - r + 1
				tmpAns := d[i]
				if from > 0 {
					tmpAns -= d[from-1]
				} else if from < 0 {
					tmpAns += d[n-1] - d[n-1+from]
				}
				days := c[i]
				if from < 0 {
					days += c[n-1] - c[n+from-1]
				} else if from > 0 {
					days -= c[from-1]
				}
				diffDays := days - m
				tmpAns -= (1 + diffDays) * diffDays / 2
				if tmpAns > best {
					best = tmpAns
				}
			}
		}
		fmt.Fprintf(out, "%d\n", ans+best)
	}
	return
}

func output(w io.Writer, out1 []int, out2 []string) {
	n := len(out1)
	tmpN := n
	for i := 0; i < len(out1); i++ {
		if out1[i] == 0 {
			tmpN--
		}
	}
	fmt.Fprintf(w, "YES\n")
	fmt.Fprintf(w, "%d\n", tmpN)
	for i := 0; i < n; i++ {
		if out1[i] > 0 {
			fmt.Fprintf(w, "%d %s\n", out1[i], out2[i])
		}
	}
	return
}

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

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
	x int64
	D []int64
)

func main() {
	n = ReadInt()
	x = ReadInt64()
	D = ReadInt64Slice(n)

	solve()
}

func solve() {
	A := []int64{}
	A = append(A, D...)
	A = append(A, D...)
	// PrintfDebug("A: %v\n", A)

	S := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		S[i+1] = S[i] + A[i]
	}
	SS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		SS[i+1] = SS[i] + ArithmeticSequenceSum(1, 1, A[i])
	}

	revA := []int64{}
	revA = append(revA, Reverse(D)...)
	revA = append(revA, Reverse(D)...)
	revS := make([]int64, len(revA)+1)
	for i := 0; i < len(revA); i++ {
		revS[i+1] = revS[i] + revA[i]
	}
	revSS := make([]int64, len(revA)+1)
	for i := 0; i < len(revA); i++ {
		revSS[i+1] = revSS[i] + ArithmeticSequenceSum(1, 1, revA[i])
	}
	PrintfDebug("revA: %v\n", revA)

	ans := int64(0)
	for i := 0; i < n; i++ {
		if ChMax(&ans, right(i, A, S, SS)) {
			PrintfDebug("right %d: %d\n", i, ans)
		}
		if ChMax(&ans, left(i, revA, revS, revSS)) {
			PrintfDebug("left %d: %d\n", i, ans)
		}
	}
	fmt.Println(ans)
}

func right(i int, A, S, SS []int64) int64 {
	res := A[i]

	nokori := x - 1
	ok := BinarySearch(i+1, len(A)+1, func(mid int) bool {
		d := S[mid] - S[i+1]
		return d <= nokori
	})

	full := SS[ok] - SS[i+1]
	delta := nokori - (S[ok] - S[i+1])
	diff := ArithmeticSequenceSum(1, 1, delta)

	// PrintfDebug("i: %d, ok: %d, init: %d, full: %d, delta: %d, diff: %d\n", i, ok, res, full, delta, diff)

	return res + full + diff
}

func left(i int, A, S, SS []int64) int64 {
	res := int64(0)

	nokori := x
	ok := BinarySearch(i, len(A)+1, func(mid int) bool {
		d := S[mid] - S[i]
		return d <= nokori
	})

	full := SS[ok] - SS[i]
	delta := nokori - (S[ok] - S[i])
	diff := ArithmeticSequenceSum(A[ok], -1, delta)

	PrintfDebug("i: %d, ok: %d, init: %d, full: %d, delta: %d, diff: %d\n", i, ok, res, full, delta, diff)

	return res + full + diff
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

// ArithmeticSequenceSum returns a sum of an arithmetic sequence.
// a: 初項, d: 公差, n: 項数
func ArithmeticSequenceSum(a, d, n int64) int64 {
	return (2*a + (n-1)*d) * n / 2
}

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

func Reverse(A []int64) []int64 {
	res := []int64{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

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

/*********** 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...)
}

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

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
	x int64
	D []int64
)

func main() {
	n = ReadInt()
	x = ReadInt64()
	D = ReadInt64Slice(n)

	solve()
}

func solve() {
	A := []int64{}
	A = append(A, D...)
	A = append(A, D...)
	// PrintfDebug("A: %v\n", A)

	S := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		S[i+1] = S[i] + A[i]
	}
	SS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		SS[i+1] = SS[i] + ArithmeticSequenceSum(1, 1, A[i])
	}

	revA := []int64{}
	revA = append(revA, Reverse(D)...)
	revA = append(revA, Reverse(D)...)
	revS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		revS[i+1] = revS[i] + A[i]
	}
	revSS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		revSS[i+1] = revSS[i] + ArithmeticSequenceSum(1, 1, A[i])
	}

	ans := int64(0)
	for i := 0; i < n; i++ {
		ChMax(&ans, right(i, A, S, SS))
		ChMax(&ans, left(i, revA, revS, revSS))
	}
	fmt.Println(ans)
}

func right(i int, A, S, SS []int64) int64 {
	res := A[i]

	nokori := x - 1
	ok := BinarySearch(i, len(A)+1, func(mid int) bool {
		d := S[mid] - S[i]
		return d <= nokori
	})

	full := SS[ok] - SS[i]
	delta := nokori - (S[ok] - S[i])
	diff := ArithmeticSequenceSum(1, 1, delta)

	return res + full + diff
}

func left(i int, A, S, SS []int64) int64 {
	res := int64(0)

	nokori := x
	ok := BinarySearch(i, len(A)+1, func(mid int) bool {
		d := S[mid] - S[i]
		return d <= nokori
	})

	full := SS[ok] - SS[i]
	delta := nokori - (S[ok] - S[i])
	diff := ArithmeticSequenceSum(A[ok], -1, delta)

	return res + full + diff
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

// ArithmeticSequenceSum returns a sum of an arithmetic sequence.
// a: 初項, d: 公差, n: 項数
func ArithmeticSequenceSum(a, d, n int64) int64 {
	return (2*a + (n-1)*d) * n / 2
}

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

func Reverse(A []int64) []int64 {
	res := []int64{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

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

/*********** 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...)
}

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

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
	x int64
	D []int64
)

func main() {
	n = ReadInt()
	x = ReadInt64()
	D = ReadInt64Slice(n)

	solve()
}

func solve() {
	A := []int64{}
	A = append(A, D...)
	A = append(A, D...)
	// PrintfDebug("A: %v\n", A)

	S := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		S[i+1] = S[i] + A[i]
	}
	SS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		SS[i+1] = SS[i] + ArithmeticSequenceSum(1, 1, A[i])
	}

	revA := []int64{}
	revA = append(revA, Reverse(D)...)
	revA = append(revA, Reverse(D)...)
	revS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		revS[i+1] = revS[i] + A[i]
	}
	revSS := make([]int64, len(A)+1)
	for i := 0; i < len(A); i++ {
		revSS[i+1] = revSS[i] + ArithmeticSequenceSum(1, 1, A[i])
	}

	ans := int64(0)
	for i := 0; i < n; i++ {
		ChMax(&ans, right(i, A, S, SS))
		ChMax(&ans, left(i, revA, revS, revSS))
	}
	fmt.Println(ans)
}

func right(i int, A, S, SS []int64) int64 {
	res := A[i]

	nokori := x - 1
	ok := BinarySearch(i, len(A)+1, func(mid int) bool {
		d := S[mid] - S[i]
		return d <= nokori
	})

	full := SS[ok] - SS[i]
	delta := nokori - (S[ok] - S[i])
	diff := ArithmeticSequenceSum(1, 1, delta)

	return res + full + diff
}

func left(i int, A, S, SS []int64) int64 {
	res := int64(0)

	nokori := x
	ok := BinarySearch(i, len(A)+1, func(mid int) bool {
		d := S[mid] - S[i]
		return d <= nokori
	})

	full := SS[ok] - SS[i]
	delta := nokori - (S[ok] - S[i])
	diff := ArithmeticSequenceSum(A[i], -1, delta)

	return res + full + diff
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

// ArithmeticSequenceSum returns a sum of an arithmetic sequence.
// a: 初項, d: 公差, n: 項数
func ArithmeticSequenceSum(a, d, n int64) int64 {
	return (2*a + (n-1)*d) * n / 2
}

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

func Reverse(A []int64) []int64 {
	res := []int64{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

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

/*********** 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"
)

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		i := 1
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for ; n > 1; n-- {
			i++
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			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()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		tmp := a[0]
		ans1l := 0
		ans1r := -1
		for i := 1; i < n; i++ {
			if a[i]-tmp >= i+1 {
				ans1r = i
				break
			}
			if a[i]-i < tmp {
				tmp = a[i] - i
				ans1l = i
			}
		}
		if ans1r != -1 {
			fmt.Fprintf(out, "YES\n")
			fmt.Fprintf(out, "%d %d\n", ans1l+1, ans1r+1)
			continue
		}
		tmp = a[n-1]
		ans2r := n - 1
		ans2l := -1
		for i := 1; i < n; i++ {
			if a[n-i-1]-tmp >= i+1 {
				ans2l = n - i - 1
				break
			}
			if a[n-i-1]-i < tmp {
				tmp = a[n-1-i] - i
				ans2r = n - i - 1
			}
		}
		if ans2l != -1 {
			fmt.Fprintf(out, "YES\n")
			fmt.Fprintf(out, "%d %d\n", ans2l+1, ans2r+1)
			continue
		}
		fmt.Fprintf(out, "NO\n")
	}
	return
}

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t int
	var a [2e5 + 7]int
	for scanf("%d\n", &t); t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		ok := false
		for i := 1; i < n; i++ {
			if abs(a[i]-a[i-1]) >= 2 {
				ok = true
				printf("YES\n%d %d\n", i, i+1)
				break
			}
		}
		if !ok {
			printf("NO\n")
		}
	}
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

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

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

	t := readInt(reader)

	for _i := 0; _i < t; _i++ {
		n := readInt(reader)
		arr := make([]int, n)
		line := strings.Split(readLine(reader), " ")
		for i := range arr {
			arr[i] = parseInt(line[i])
		}

		i := 1
		for ; i < n; i++ {
			if math.Abs(float64(arr[i]-arr[i-1])) > 1 {
				break
			}
		}
		if i == n {
			i--
		}
		if math.Abs(float64(arr[i]-arr[i-1])) > 1 {
			fmt.Println("YES")
			fmt.Println(i, " ", i+1)
		} else {
			fmt.Println("NO")
		}
	}
}

func readInt(reader *bufio.Reader) int {
	return parseInt(readLine(reader))
}

func parseInt(s string) int {
	v, err := strconv.ParseInt(s, 10, 64)
	checkError(err)
	return int(v)
}

func readLine(reader *bufio.Reader) string {
	str, err := reader.ReadString('\n')
	if err == io.EOF {
		return ""
	}

	return strings.TrimSpace(str)
}

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

package main

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n, a := readIntsll(0)
		ok, x, y := solve(n, a)
		if !ok {
			println("NO")
			continue
		}
		println("YES")
		println(x+1, y+1)
	}
}

func solve(n int, a []int64) (bool, int, int) {
	for i := 0; i+1 < n; i++ {
		if 1 < absll(a[i]-a[i+1]) {
			return true, i, i + 1
		}
	}
	return false, 0, 0
}

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

// 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"
	"strconv"
)

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		N := sc.NextInt()
		a := sc.NextIntArray()
		flag := false
		for i := 0; i < N-1; i++ {
			if abs(a[i]-a[i+1]) > 1 {
				fmt.Println("YES")
				fmt.Println(i+1, i+2)
				flag = true
				break
			}
		}
		if flag {
			continue
		}
		fmt.Println("NO")

	}
}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	// answer the leftmost min sub array
	for ; t > 0; t-- {
		n := 0
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &n, &a)
		for i := 2; i <= n; i++ {
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	// answer the leftmost min sub array
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for i := 2; i <= n; i++ {
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func absDiff(x, y int) int {
	if x > y {
		return x - y
	}
	return y - x
}
func main() {

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

	var n, arrLen int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d\n", &arrLen)
		arr := make([]int, arrLen)
		for j := 1; j <= arrLen; j++ {
			fmt.Fscanf(reader, "%d", &arr[j-1])
		}
		fmt.Fscanf(reader, "%d\n")
		flag := false
		for j := 1; j < arrLen; j++ {
			if absDiff(arr[j], arr[j-1]) >= 2 {
				fmt.Fprintf(writer, "YES\n%d %d\n", j, j+1)
				flag = true
				break
			}
		}
		if !flag {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

type heap struct {
  array []int
}

func (h *heap) push(val int) {
  h.array = append(h.array, val)
  cur := len(h.array) - 1
  for cur > 0 {
    var parent int
    if (cur & 1) == 1 {
      parent = (cur - 1) / 2
    } else {
      parent = (cur - 2) / 2
    }
    if h.array[cur] < h.array[parent] {
      h.array[cur], h.array[parent] = h.array[parent], h.array[cur]
      cur = parent
    } else {
      break
    }
  }
}

func (h *heap) pop() int {
  res := h.array[0]
  h.array[0], h.array[len(h.array)-1] = h.array[len(h.array)-1], h.array[0]
  h.array = h.array[:len(h.array)-1]
  cur := 0
  for cur < len(h.array) {
    smallest := cur
    if cur*2+1 < len(h.array) && h.array[smallest] > h.array[cur*2+1] {
      smallest = cur*2 + 1
    }
    if cur*2+2 < len(h.array) && h.array[smallest] > h.array[cur*2+2] {
      smallest = cur*2 + 2
    }
    if smallest != cur {
      h.array[smallest], h.array[cur] = h.array[cur], h.array[smallest]
      cur = smallest
    } else {
      break
    }
  }
  return res
}

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--
    var n int
    fmt.Fscan(in, &n)
    arr := make([]int, n)
    l, r := 0, 0
    for i, _ := range arr {
      fmt.Fscan(in, &arr[i])
      if i >= 1 && math.Abs(float64(arr[i]-arr[i-1])) > 1.0 {
        l, r = i, i+1
      }
    }
    if l == 0 && r == 0 {
      fmt.Fprintln(out, "NO")
    } else {
      fmt.Fprintln(out, "YES")
      fmt.Fprintln(out, l, r)
    }
  }
}

package main

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

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)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		tmp := a[0]
		ans1l := 0
		ans1r := -1
		for i := 1; i < n; i++ {
			if a[i]-tmp >= n {
				ans1r = i
				break
			}
			if a[i]-i < tmp {
				tmp = a[i] - i
				ans1l = i
			}
		}
		if ans1r != -1 {
			fmt.Fprintf(out, "YES\n")
			fmt.Fprintf(out, "%d %d\n", ans1l+1, ans1r+1)
			continue
		}
		tmp = a[n-1]
		ans2r := n - 1
		ans2l := -1
		for i := 1; i < n; i++ {
			if a[n-i-1]-tmp >= n {
				ans2l = n - i - 1
				break
			}
			if a[n-i-1]-i < tmp {
				tmp = a[n-1-i] - i
				ans2r = n - i - 1
			}
		}
		if ans2l != -1 {
			fmt.Fprintf(out, "YES\n")
			fmt.Fprintf(out, "%d %d\n", ans2l+1, ans2r+1)
			continue
		}
		fmt.Fprintf(out, "NO\n")
	}
	return
}

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t int
	var a [2e5 + 7]int
	for scanf("%d\n", &t); t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		ok := false
		for i := 1; i < n; i++ {
			if abs(a[i]-a[i-1]) >= 2 {
				ok = true
				printf("YES\n%d %d\n", i-1, i)
				break
			}
		}
		if !ok {
			printf("NO\n")
		}
	}
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

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

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

	t := readInt(reader)

	for _i := 0; _i < t; _i++ {
		n := readInt(reader)
		arr := make([]int, n)
		line := strings.Split(readLine(reader), " ")
		for i := range arr {
			arr[i] = parseInt(line[i])
		}

		i := 1
		for ; i < n; i++ {
			if math.Abs(float64(arr[i]-arr[i-1])) > 1 {
				break
			}
		}
		if i == n {
			i--
		}
		if math.Abs(float64(arr[i]-arr[i-1])) > 1 {
			fmt.Println("YES")
			fmt.Println(i-1, " ", i)
		} else {
			fmt.Println("NO")
		}
	}
}

func readInt(reader *bufio.Reader) int {
	return parseInt(readLine(reader))
}

func parseInt(s string) int {
	v, err := strconv.ParseInt(s, 10, 64)
	checkError(err)
	return int(v)
}

func readLine(reader *bufio.Reader) string {
	str, err := reader.ReadString('\n')
	if err == io.EOF {
		return ""
	}

	return strings.TrimSpace(str)
}

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

package main

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

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		N := sc.NextInt()
		a := sc.NextIntArray()
		mn := a[0]
		mx := a[0]
		s1 := 0
		s2 := 0
		for i := 0; i < N; i++ {
			if mn > a[i] {
				mn = a[i]
				s1 = i + 1
			}
			if mx < a[i] {
				mx = a[i]
				s2 = i + 1
			}
		}
		if mx-mn >= N {
			fmt.Println("YES")
			fmt.Println(s1, s2)
		} else {
			fmt.Println("NO")
		}
	}
}

func minA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = min(s, v)
	}
	return s
}

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

func maxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = max(s, v)
	}
	return s
}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		N := sc.NextInt()
		a := sc.NextIntArray()
		mn := a[0]
		mx := a[0]
		s1 := 0
		s2 := 0
		for i := 0; i < N; i++ {
			if mn > a[i] {
				mn = a[i]
				s1 = i
			}
			if mx < a[i] {
				mx = a[i]
				s2 = i
			}
		}
		if mx-mn >= N {
			fmt.Println("YES")
			fmt.Println(s1, s2)
		} else {
			fmt.Println("NO")
		}
	}
}

func minA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = min(s, v)
	}
	return s
}

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

func maxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = max(s, v)
	}
	return s
}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		i := 0
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for ; n > 0; n-- {
			i++
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if i >= n || ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func isOdd(a int) bool {
	if a%2 == 1 {
		return true
	}
	return false
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	// even = filler -> present or not they don't affect the outcome
	defer out.Flush()
	q := 0
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		n, k := 0, 0
		cntOdd := 0
		fmt.Fscan(in, &n, &k)
		as := make([]int, n)
		for i := range as {
			fmt.Fscan(in, &as[i])
			if isOdd(as[i]) {
				cntOdd++
			}
		}
		restOdd := cntOdd - (k - 1)
		if k > cntOdd ||
			// too many odds -> reduce to a single one ( require odd number of exceeding odds )
			cntOdd > k && !isOdd(restOdd) {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
		i := 0
		// k - ( 1 last segment: the rest of odds )
		for k-1 > 0 {
			if isOdd(as[i]) {
				fmt.Fprintf(out, "%d ", i+1)
				k--
			}
			i++
		}
		// rest of odds
		fmt.Fprintf(out, "%d\n", n)
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		i := 0
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for ; n > 0; n-- {
			i++
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		N := n + 1
		i := 0
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for ; n > 1; n-- {
			i++
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if i >= N || ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		N := n + 1
		i := 0
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for ; n > 0; n-- {
			i++
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if i >= N || ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	// answer the leftmost min sub array
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		a, b := 0, 0
		ans := false
		fmt.Fscan(in, &a)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &b)
			// answer already found -> exhaust the remaning inputs and skip computation
			if ans {
				continue
			}
			if abs(a-b) <= 1 {
				a = b
			} else {
				ans = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, i-1, i)
			}
		}
		if !ans {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func main() {

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

	var n, arrLen int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d\n", &arrLen)
		arr := make([]int, arrLen)
		for j := 1; j <= arrLen; j++ {
			fmt.Fscanf(reader, "%d", &arr[j-1])
		}
		fmt.Fscanf(reader, "%d\n")
		flag := false
		for j := 1; j < arrLen; j++ {
			if (arr[j]-arr[j-1]) >= 2 {
				fmt.Fprintf(writer, "YES\n%d %d\n", j, j-1)
				flag = true
				break
			}
		}
		if !flag {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

func main() {

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

	var n, arrLen int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d\n", &arrLen)
		arr := make([]int, arrLen)
		for j := 1; j <= arrLen; j++ {
			fmt.Fscanf(reader, "%d", &arr[j-1])
		}
		fmt.Fscanf(reader, "%d\n")
		flag := false
		for j := 1; j < arrLen; j++ {
			if (arr[j] - arr[j-1]) >= 2 {
				fmt.Fprintf(writer, "YES\n%d %d\n", j, j+1)
				flag = true
				break
			}
		}
		if !flag {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

func main() {

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

	var n, arrLen int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d\n", &arrLen)
		arr := make([]int, arrLen)
		for j := 1; j <= arrLen; j++ {
			fmt.Fscanf(reader, "%d", &arr[j-1])
		}
		fmt.Fscanf(reader, "%d\n")
		flag := false
		for j := 1; j < arrLen; j++ {
			if (arr[j] - arr[j-1]) >= 2 {
				fmt.Fprintf(writer, "YES\n%d %d\n", j-1, j)
				flag = true
				break
			}
		}
		if !flag {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

type heap struct {
  array []int
}

func (h *heap) push(val int) {
  h.array = append(h.array, val)
  cur := len(h.array) - 1
  for cur > 0 {
    var parent int
    if (cur & 1) == 1 {
      parent = (cur - 1) / 2
    } else {
      parent = (cur - 2) / 2
    }
    if h.array[cur] < h.array[parent] {
      h.array[cur], h.array[parent] = h.array[parent], h.array[cur]
      cur = parent
    } else {
      break
    }
  }
}

func (h *heap) pop() int {
  res := h.array[0]
  h.array[0], h.array[len(h.array)-1] = h.array[len(h.array)-1], h.array[0]
  h.array = h.array[:len(h.array)-1]
  cur := 0
  for cur < len(h.array) {
    smallest := cur
    if cur*2+1 < len(h.array) && h.array[smallest] > h.array[cur*2+1] {
      smallest = cur*2 + 1
    }
    if cur*2+2 < len(h.array) && h.array[smallest] > h.array[cur*2+2] {
      smallest = cur*2 + 2
    }
    if smallest != cur {
      h.array[smallest], h.array[cur] = h.array[cur], h.array[smallest]
      cur = smallest
    } else {
      break
    }
  }
  return res
}

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--
    var n int
    fmt.Fscan(in, &n)
    arr := make([]int, n)
    l, r := 0, 0
    for i, _ := range arr {
      fmt.Fscan(in, &arr[i])
      if i > 1 && math.Abs(float64(arr[i]-arr[i-1])) > 1.0 {
        l, r = i, i+1
      }
    }
    if l == 0 && r == 0 {
      fmt.Fprintln(out, "NO")
    } else {
      fmt.Fprintln(out, "YES")
      fmt.Fprintln(out, l, r)
    }
  }
}