Marian is at a casino. The game at the casino works like this.Before each round, the player selects a number between $$$1$$$ and $$$10^9$$$. After that, a dice with $$$10^9$$$ faces is rolled so that a random number between $$$1$$$ and $$$10^9$$$ appears. If the player guesses the number correctly their total money is doubled, else their total money is halved. Marian predicted the future and knows all the numbers $$$x_1, x_2, \dots, x_n$$$ that the dice will show in the next $$$n$$$ rounds. He will pick three integers $$$a$$$, $$$l$$$ and $$$r$$$ ($$$l \leq r$$$). He will play $$$r-l+1$$$ rounds (rounds between $$$l$$$ and $$$r$$$ inclusive). In each of these rounds, he will guess the same number $$$a$$$. At the start (before the round $$$l$$$) he has $$$1$$$ dollar.Marian asks you to determine the integers $$$a$$$, $$$l$$$ and $$$r$$$ ($$$1 \leq a \leq 10^9$$$, $$$1 \leq l \leq r \leq n$$$) such that he makes the most money at the end.Note that during halving and multiplying there is no rounding and there are no precision errors. So, for example during a game, Marian could have money equal to $$$\dfrac{1}{1024}$$$, $$$\dfrac{1}{128}$$$, $$$\dfrac{1}{2}$$$, $$$1$$$, $$$2$$$, $$$4$$$, etc. (any value of $$$2^t$$$, where $$$t$$$ is an integer of any sign).

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) — the number of rounds. The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \leq x_i \leq 10^9$$$), where $$$x_i$$$ is the number that will fall on the dice in the $$$i$$$-th round. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output three integers $$$a$$$, $$$l$$$, and $$$r$$$ such that Marian makes the most amount of money gambling with his strategy. If there are multiple answers, you may output any of them.

NoteFor the first test case, the best choice is $$$a=4$$$, $$$l=1$$$, $$$r=5$$$, and the game would go as follows.   Marian starts with one dollar.  After the first round, he ends up with $$$2$$$ dollars because the numbers coincide with the chosen one.  After the second round, he ends up with $$$4$$$ dollars because the numbers coincide again.  After the third round, he ends up with $$$2$$$ dollars because he guesses $$$4$$$ even though $$$3$$$ is the correct choice.  After the fourth round, he ends up with $$$4$$$ dollars again.  In the final round, he ends up $$$8$$$ dollars because he again guessed correctly. There are many possible answers for the second test case, but it can be proven that Marian will not end up with more than $$$2$$$ dollars, so any choice with $$$l = r$$$ with the appropriate $$$a$$$ is acceptable.

package main

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

func max(x int, num ...int) int {
	mx := x
	for _, j := range num {
		if j > mx {
			mx = j
		}
	}
	return mx
}

const maxn = 200100
var a []int

type Node struct {
	ans		int
	pref 	int
	suff 	int
	sum 	int
}

func newNode(v int) Node {
	var res Node
	res.sum = v
	res.pref = max(0, v)
	res.suff = max(0, v)
	res.ans = max(0, v)
	return res
}

func merge(l, r Node) Node {
	var res Node
	res.sum = l.sum + r.sum
	res.pref = max(l.pref, l.sum + r.pref)
	res.suff = max(r.suff, r.sum + l.suff)
	res.ans = max(l.ans, r.ans, l.suff + r.pref)
	return res
}

var t [4 * maxn]Node

func build(id, l, r int) {
	if (r - l == 1) {
		t[id] = newNode(-1)
		return
	}
	m := (r + l) / 2
	build(id * 2 + 1, l, m)
	build(id * 2 + 2, m, r)
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func upd(id, l, r, p, v int) {
	if r - l == 1 {
		t[id] = newNode(v)
		return
	}
	m := (r + l) / 2
	if p < m {
		upd(id * 2 + 1, l, m, p, v)
	} else {
		upd(id * 2 + 2, m, r, p, v)
	}
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var T int
	T = readInt(in)
	for ; T > 0; T-- {
		n := readInt(in)
		a = readArrInt(in)
		build(0, 0, n)
		mp := make(map[int] []int, n)
		for i := 0; i < n; i++ {
			if _, ok := mp[a[i]]; ok {
				mp[a[i]] = append(mp[a[i]], i)
			} else {
				mp[a[i]] = []int {i}
			}
		}
		var ans, ans_v int
		for k, idxs := range mp {
			for _, idx := range idxs {
				upd(0, 0, n, idx, 1)
			}
			cur := t[0].ans
			if cur > ans {
				ans = cur
				ans_v = k
			}
			for _, idx := range idxs {
				upd(0, 0, n, idx, -1)
			}
		}
		for i := 0; i < n; i++ {
			if a[i] == ans_v {
				a[i] = 1
			} else {
				a[i] = -1
			}
		}
		var ans_l, ans_r, mx int
		var cur_l, cur int
		for i := 0; i < n; i++ {
			if cur + a[i] < 0 {
				cur_l = i + 1
				cur = 0
			} else {
				cur += a[i]
				if cur > mx {
					mx = cur
					ans_l = cur_l
					ans_r = i
				}
			}
		}
		fmt.Println(ans_v, ans_l + 1, ans_r + 1)
	}
}

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

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

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

package main

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

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

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

type Elem struct {
	curr   int
	max    int
	start  int
	end    int
	liter  int
	pstart int
}

func NewElem(curr, max, start, end, liter, pstart int) *Elem {
	return &Elem{curr: curr, max: max, start: start, end: end, liter: liter, pstart: pstart}
}

func (e Elem) String() string {
	return fmt.Sprintf("CURR %d ;MAX %d; START: %d, END %d; LITER %d\n", e.curr, e.max, e.start, e.end, e.liter)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slc := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slc[i])
		}
		m := make(map[int]*Elem)
		for i := 0; i < n; i++ {
			if tmp, ok := m[slc[i]]; ok {
				if tmp.curr+2-(i-tmp.liter) > 1 {
					tmp.curr = tmp.curr + 2 - (i - tmp.liter)
				} else {
					tmp.curr = 1
					tmp.pstart = i
					//tmp.end = i
				}
				tmp.liter = i
				if tmp.curr > tmp.max {
					tmp.max = tmp.curr
					tmp.start = tmp.pstart
					tmp.end = i
				}
			} else {
				m[slc[i]] = NewElem(1, 1, i, i, i, i)
			}
		}
		rmax := 0
		res, l, r := 0, 0, 0
		//fmt.Println("!!!", m)
		for key, i := range m {
			if i.max >= rmax {
				rmax = i.max
				res = key
				r = i.end
				l = i.start
			}
		}
		fmt.Fprintln(writer, res, l+1, r+1)
	}
}

package main

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

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

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

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

		segs := make(map[int][][]int)
		for i := 0; i < n; i++ {
			s := []int{i, i}
			for j := i + 1; j < n; j++ {
				if a[i] != a[j] {
					break
				}
				s[1] = j
				i = j
			}

			segs[a[i]] = append(segs[a[i]], s)
		}

		var max int
		z, l, r := a[0], 0, 0
		for k, s2 := range segs {
			c := s2[0][1] - s2[0][0] + 1
			l2 := s2[0][0]
			r2 := s2[0][1]
			if c > max {
				z = k
				max = c
				l, r = l2, r2
			}

			for j := 1; j < len(s2); j++ {
				d := s2[j][0] - s2[j-1][1] - 1
				c -= d
				if c <= 0 {
					c = s2[j][1] - s2[j][0] + 1
					l2 = s2[j][0]
				} else {
					c += s2[j][1] - s2[j][0] + 1
				}
				if c > max {
					z = k
					max = c
					l, r = l2, s2[j][1]
				}
			}
		}
		fmt.Println(z, l+1, r+1)
	}
}

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pos := map[int][]int{}
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			pos[v] = append(pos[v], i)
		}
		maxS, ans, l, r := 1, v, n, n
		for v, ps := range pos {
			for i, sum, st := 1, 1, ps[0]; i < len(ps); i++ {
				if sum -= ps[i] - ps[i-1] - 1; sum < 0 {
					sum, st = 0, ps[i]
				}
				if sum++; sum > maxS {
					maxS, ans, l, r = sum, v, st, ps[i]
				}
			}
		}
		Fprintln(out, ans, l, r)
	}
}

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

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pos := map[int][]int{}
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			pos[v] = append(pos[v], i)
		}
		maxS, ans, l, r := 1, v, n, n
		for v, ps := range pos {
			for i, s, minS, minI := 1, 1, 0, ps[0]; i < len(ps); i++ {
				if s -= ps[i] - ps[i-1] - 1; s < minS {
					minS, minI = s, ps[i]
				}
				if s++; s-minS > maxS {
					maxS, ans, l, r = s-minS, v, minI, ps[i]
				}
			}
		}
		Fprintln(out, ans, l, r)
	}
}

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

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		// int64
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		pos := map[int][]int{}
		for i, v := range a {
			pos[v] = append(pos[v], i)
		}

		mxs := 1
		mxv, mxl, mxr := a[0], 0,0
		for v, ps := range pos {
			mins := 0
			mi := 0
			s := 0
			for i, p := range ps {
				if i == 0 {
					s = 1
					mi = p - 1
				} else if p == ps[i-1]+1 {
					s++
					if s-mins > mxs {
						mxs = s - mins
						mxv, mxl, mxr = v, mi+1, p
					}
				} else {
					s -= p - ps[i-1] - 1
					if s < mins {
						mins = s
						mi = p-1
					}
					s++
					if s-mins > mxs {
						mxs = s - mins
						mxv, mxl, mxr =v, mi+1, p
					}
				}
			}
		}
		Fprintln(out, mxv, mxl+1, mxr+1)
	}

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

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

}

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

package main

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

/*
1
10
2 1 2 2 2 4 2 2 1 4
---
2 3 8
*/

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

	numToIdcs := make(map[int][]int)

	for i := 0; i < n; i++ {
		var num int
		scanf("%d", &num)

		numToIdcs[num] = append(numToIdcs[num], i)
	}
	scanf("\n")

	bestSum := 0
	bestNum := -1
	bestL, bestR := -1, -1

	for num, idcs := range numToIdcs {
		if bestNum == -1 {
			bestSum = 1
			bestNum = num
			bestL, bestR = idcs[0], idcs[0]
		}

		sum := 1
		l := idcs[0]

		for i := 1; i < len(idcs); i++ {
			prevIdx, idx := idcs[i-1], idcs[i]
			toRemove := idx - prevIdx - 1

			sum += 1 - toRemove
			if sum <= 1 {
				sum = 1
				l = idx
			}

			if sum > bestSum {
				bestSum = sum
				bestNum = num
				bestL, bestR = l, idx
			}
		}
	}

	fmt.Fprintln(writer, bestNum, bestL+1, bestR+1)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n+5)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		mp := map[int][]int{}
		for i := 1; i <= n; i++ {
			mp[a[i]] = append(mp[a[i]], i)
		}
		num := -1
		l := 0
		r := 0
		cur := 0
		ans := -1
		al := 0
		ar := 0
		for v, now := range mp {
			l = 0
			r = 0
			for i := 0; i < len(now); i++ {
				if l == 0 && r == 0 {
					l = now[i]
					r = now[i]
					cur = 1
					if ans < cur {
						al = l
						ar = r
						num = v
						ans = cur
					}
					continue
				}
				cur += 1 - (now[i] - r - 1)
				if cur <= 0 {
					cur = 1
					l = now[i]
					r = now[i]
				} else {
					r = now[i]
				}
				if ans < cur {
					al = l
					ar = r
					num = v
					ans = cur
				}
			}
		}
		fmt.Fprintln(out, num, al, ar)
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		var a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1, w2, w3 := do(a, n)
		fmt.Fprintln(w, w1, w2, w3)
	}
}

func do(a []int, n int) (int, int, int) {
	ans := 1
	l := 0
	r := 0
	d := a[0]
	m := map[int][]int{}
	for i, v := range a {
		m[v] = append(m[v], i)
	}
	// log.Print(a, n)
	for v, b := range m {
		c := 1
		k := b[0]
		if ans == 1 && v < d {
			d = v
			l = b[0]
			r = b[0]
		}
		for i := 1; i < len(b); i++ {
			if c2 := c + 1 - (b[i] - b[i-1] - 1); c2 > 1 {
				c = c2
			} else {
				c = 1
				k = b[i]
			}
			if ans < c || (ans == c && v < d) {
				ans = c
				d = v
				l = k
				r = b[i]
			}
			// log.Print(ans, d, l, r)
		}
	}
	return d, l + 1, r + 1
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

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

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

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

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

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

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

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

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

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

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

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

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

var myio *MyIO

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

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() {
	m := make(map[int][]int)
	n := ri()
	a := ria(n)
	for i, v := range a {
		if _, ok := m[v]; ok {
			m[v] = append(m[v], i)
		} else {
			m[v] = append([]int{}, i)
		}
	}
	ansv, ansl, anss, anse := a[0], 1, 0, 0
	for k, s := range m {
		ps, pv := 1, s[0]
		for i := 1; i < len(s); i++ {
			// last to cur
			ta := ps - (s[i] - s[i-1] - 1) + 1
			if ta > 1 {
				ps = ta
				if ps > ansl {
					ansv = k
					ansl = ps
					anss = pv
					anse = s[i]
				}
			} else {
				ps, pv = 1, s[i]
			}
		}
	}
	myio.Println(ansv, anss+1, anse+1)
}

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

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	hash := make(map[int][]int)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		hash[nums[i]] = append(hash[nums[i]], i)
	}
	ans := 1
	a1, a2, a3 := nums[0], 0, 0
	for k, v := range hash {
		cur := 1
		left := v[0]
		for i:=1;i<len(v);i++ {
			cur += v[i-1] - v[i] + 2
			cur = max(1, cur)
			if cur == 1 {
				left = v[i]
			}
			if ans < cur {
				ans = cur
				a1 = k
				a2 = left
				a3 = v[i]
			}
		}
	}
	fmt.Fprintln(w, a1, a2+1, a3+1)

}

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

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

package main

import "fmt"

func max(x int, num ...int) int {
	mx := x
	for _, j := range num {
		if j > mx {
			mx = j
		}
	}
	return mx
}

const maxn = 200100
var a[maxn]int

type Node struct {
	ans		int
	pref 	int
	suff 	int
	sum 	int
}

func newNode(v int) Node {
	var res Node
	res.sum = v
	res.pref = max(0, v)
	res.suff = max(0, v)
	res.ans = max(0, v)
	return res
}

func merge(l, r Node) Node {
	var res Node
	res.sum = l.sum + r.sum
	res.pref = max(l.pref, l.sum + r.pref)
	res.suff = max(r.suff, r.sum + l.suff)
	res.ans = max(l.ans, r.ans, l.suff + r.pref)
	return res
}

var t [4 * maxn]Node

func build(id, l, r int) {
	if (r - l == 1) {
		t[id] = newNode(-1)
		return
	}
	m := (r + l) / 2
	build(id * 2 + 1, l, m)
	build(id * 2 + 2, m, r)
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func upd(id, l, r, p, v int) {
	if r - l == 1 {
		t[id] = newNode(v)
		return
	}
	m := (r + l) / 2
	if p < m {
		upd(id * 2 + 1, l, m, p, v)
	} else {
		upd(id * 2 + 2, m, r, p, v)
	}
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func solve() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	build(0, 0, n)
	mp := make(map[int] []int, n)
	for i := 0; i < n; i++ {
		if _, ok := mp[a[i]]; ok {
			mp[a[i]] = append(mp[a[i]], i)
		} else {
			mp[a[i]] = []int {i}
		}
	}
	var ans, ans_v int
	for k, idxs := range mp {
		for _, idx := range idxs {
			upd(0, 0, n, idx, 1)
		}
		cur := t[0].ans
		if cur > ans {
			ans = cur
			ans_v = k
		}
		for _, idx := range idxs {
			upd(0, 0, n, idx, -1)
		}
	}
	for i := 0; i < n; i++ {
		if a[i] == ans_v {
			a[i] = 1
		} else {
			a[i] = -1
		}
	}
	var ans_l, ans_r, mx int
	var cur_l, cur int
	for i := 0; i < n; i++ {
		if cur + a[i] < 0 {
			cur_l = i + 1
			cur = 0
		} else {
			cur += a[i]
			if cur > mx {
				mx = cur
				ans_l = cur_l
				ans_r = i
			}
		}
	}
	fmt.Println(ans_v, ans_l + 1, ans_r + 1)
	fmt.Println(ans, mx)
}

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

import "fmt"

func max(x int, num ...int) int {
	mx := x
	for _, j := range num {
		if j > mx {
			mx = j
		}
	}
	return mx
}

const maxn = 200100
var a[maxn]int

type Node struct {
	ans		int
	pref 	int
	suff 	int
	sum 	int
}

func newNode(v int) Node {
	var res Node
	res.sum = v
	res.pref = max(0, v)
	res.suff = max(0, v)
	res.ans = max(0, v)
	return res
}

func merge(l, r Node) Node {
	var res Node
	res.sum = l.sum + r.sum
	res.pref = max(l.pref, l.sum + r.pref)
	res.suff = max(r.suff, r.sum + l.suff)
	res.ans = max(l.ans, r.ans, l.suff + r.pref)
	return res
}

var t [4 * maxn]Node

func build(id, l, r int) {
	if (r - l == 1) {
		t[id] = newNode(-1)
		return
	}
	m := (r + l) / 2
	build(id * 2 + 1, l, m)
	build(id * 2 + 2, m, r)
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func upd(id, l, r, p, v int) {
	if r - l == 1 {
		t[id] = newNode(v)
		return
	}
	m := (r + l) / 2
	if p < m {
		upd(id * 2 + 1, l, m, p, v)
	} else {
		upd(id * 2 + 2, m, r, p, v)
	}
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func solve() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	mp := make(map[int] []int, n)
	for i := 0; i < n; i++ {
		if _, ok := mp[a[i]]; ok {
			mp[a[i]] = append(mp[a[i]], i)
		} else {
			mp[a[i]] = []int {i}
		}
	}
	var ans, ans_v int
	for k, idxs := range mp {
		for _, idx := range idxs {
			upd(0, 0, n, idx, 1)
		}
		cur := t[0].ans
		if cur >= ans {
			ans = cur
			ans_v = k
		}
		for _, idx := range idxs {
			upd(0, 0, n, idx, -1)
		}
	}
	for i := 0; i < n; i++ {
		if a[i] == ans_v {
			a[i] = 1
		} else {
			a[i] = -1
		}
	}
	var ans_l, ans_r, mx int
	var cur_l, cur int
	for i := 0; i < n; i++ {
		if cur + a[i] < 0 {
			cur_l = i + 1
			cur = 0
		} else {
			cur += a[i]
			if cur > mx {
				mx = cur
				ans_l = cur_l
				ans_r = i
			}
		}
	}
	if mx != ans {
		panic("123")
	}
	fmt.Println(ans_v, ans_l + 1, ans_r + 1)
}

func main() {
	build(0, 0, maxn)
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

import "fmt"

func max(x int, num ...int) int {
	mx := x
	for _, j := range num {
		if j > mx {
			mx = j
		}
	}
	return mx
}

const maxn = 200100
var a[maxn]int

type Node struct {
	ans		int
	pref 	int
	suff 	int
	sum 	int
}

func newNode(v int) Node {
	var res Node
	res.sum = v
	res.pref = max(0, v)
	res.suff = max(0, v)
	res.ans = max(0, v)
	return res
}

func merge(l, r Node) Node {
	var res Node
	res.sum = l.sum + r.sum
	res.pref = max(l.pref, l.sum + r.pref)
	res.suff = max(r.suff, r.sum + l.suff)
	res.ans = max(l.ans, r.ans, l.suff + r.pref)
	return res
}

var t [4 * maxn]Node

func build(id, l, r int) {
	if (r - l == 1) {
		t[id] = newNode(-1)
		return
	}
	m := (r + l) / 2
	build(id * 2 + 1, l, m)
	build(id * 2 + 2, m, r)
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func upd(id, l, r, p, v int) {
	if r - l == 1 {
		t[id] = newNode(v)
		return
	}
	m := (r + l) / 2
	if p < m {
		upd(id * 2 + 1, l, m, p, v)
	} else {
		upd(id * 2 + 2, m, r, p, v)
	}
	t[id] = merge(t[id * 2 + 1], t[id * 2 + 2])
}

func solve() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	mp := make(map[int] []int, n)
	for i := 0; i < n; i++ {
		if _, ok := mp[a[i]]; ok {
			mp[a[i]] = append(mp[a[i]], i)
		} else {
			mp[a[i]] = []int {i}
		}
	}
	var ans, ans_v int
	for k, idxs := range mp {
		for _, idx := range idxs {
			upd(0, 0, n, idx, 1)
		}
		cur := t[0].ans
		if cur >= ans {
			ans = cur
			ans_v = k
		}
		for _, idx := range idxs {
			upd(0, 0, n, idx, -1)
		}
	}
	for i := 0; i < n; i++ {
		if a[i] == ans_v {
			a[i] = 1
		} else {
			a[i] = -1
		}
	}
	var ans_l, ans_r, mx int
	var cur_l, cur int
	for i := 0; i < n; i++ {
		if cur + a[i] < 0 {
			cur_l = i + 1
			cur = 0
		} else {
			cur += a[i]
			if cur > mx {
				mx = cur
				ans_l = cur_l
				ans_r = i
			}
		}
	}
	fmt.Println(ans_v, ans_l + 1, ans_r + 1)
}

func main() {
	build(0, 0, maxn)
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

type Elem struct {
	curr  int
	max   int
	start int
	end   int
	liter int
}

func NewElem(curr, max, start, end, liter int) *Elem {
	return &Elem{curr: curr, max: max, start: start, end: end, liter: liter}
}

func (e Elem) String() string {
	return fmt.Sprintf("CURR %d ;MAX %d; START: %d, END %d; LITER %d\n", e.curr, e.max, e.start, e.end, e.liter)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slc := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slc[i])
		}
		m := make(map[int]*Elem)
		for i := 0; i < n; i++ {
			if tmp, ok := m[slc[i]]; ok {
				if tmp.curr+2-(i-tmp.liter) > 1 {
					tmp.curr = tmp.curr + 2 - (i - tmp.liter)
				} else {
					tmp.curr = 1
					tmp.start = i
					tmp.end = i
				}
				tmp.liter = i
				if tmp.curr > tmp.max {
					tmp.max = tmp.curr
					tmp.end = i
				}
			} else {
				m[slc[i]] = NewElem(1, 1, i, i, i)
			}
		}
		rmax := 0
		res, l, r := 0, 0, 0
		//fmt.Println("!!!", m)
		for key, i := range m {
			if i.max >= rmax {
				rmax = i.max
				res = key
				r = i.end
				l = i.start
			}
		}
		fmt.Fprintln(writer, res, l+1, r+1)
	}
}

package main

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

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

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

type Elem struct {
	curr  int
	max   int
	start int
	end   int
	liter int
}

func NewElem(curr, max, start, end, liter int) *Elem {
	return &Elem{curr: curr, max: max, start: start, end: end, liter: liter}
}

func (e Elem) String() string {
	return fmt.Sprintf("CURR %d ;MAX %d; START: %d, END %d; LITER %d\n", e.curr, e.max, e.start, e.end, e.liter)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slc := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slc[i])
		}
		m := make(map[int]*Elem)
		for i := 0; i < n; i++ {
			if tmp, ok := m[slc[i]]; ok {
				if tmp.curr+2-(i-tmp.liter) > 1 {
					tmp.curr = tmp.curr + 2 - (i - tmp.liter)
				} else {
					tmp.curr = 1
					tmp.start = i
					tmp.end = i
				}
				tmp.liter = i
				if tmp.curr > tmp.max {
					tmp.max = tmp.curr
					tmp.end = i
				}
			} else {
				m[slc[i]] = NewElem(1, 1, i, i, i)
			}
		}
		rmax := 0
		res, l, r := 0, 0, 0
		fmt.Println("!!!", m)
		for key, i := range m {
			if i.max >= rmax {
				rmax = i.max
				res = key
				r = i.end
				l = i.start
			}
		}
		fmt.Fprintln(writer, res, l+1, r+1)
	}
}

package main

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

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

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

type Elem struct {
	curr  int
	max   int
	start int
	end   int
	liter int
}

func NewElem(curr, max, start, end, liter int) *Elem {
	return &Elem{curr: curr, max: max, start: start, end: end, liter: liter}
}

func (e Elem) String() string {
	return fmt.Sprintf("CURR %d ;MAX %d; START: %d, END %d; LITER %d\n", e.curr, e.max, e.start, e.end, e.liter)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slc := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slc[i])
		}
		m := make(map[int]*Elem)
		for i := 0; i < n; i++ {
			if tmp, ok := m[slc[i]]; ok {
				if tmp.curr+2-(i-tmp.liter) > 1 {
					tmp.curr = tmp.curr + 2 - (i - tmp.liter)
				} else {
					tmp.curr = 1
					tmp.start = i
					tmp.end = i
				}
				tmp.liter = i
				if tmp.curr > tmp.max {
					tmp.max = tmp.curr
					tmp.end = i
				}
			} else {
				m[slc[i]] = NewElem(1, 1, i, i, i)
			}
		}
		res, l, r := 0, 0, 0
		//fmt.Println("!!!", m)
		for key, i := range m {
			if i.max >= res {
				res = key
				r = i.end
				l = i.start
			}
		}
		fmt.Fprintln(writer, res, l+1, r+1)
	}
}

package main

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

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

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

type Elem struct {
	curr  int
	max   int
	start int
	end   int
	liter int
}

func NewElem(curr, max, start, end, liter int) *Elem {
	return &Elem{curr: curr, max: max, start: start, end: end, liter: liter}
}

func (e Elem) String() string {
	return fmt.Sprintf("CURR %d ;MAX %d; START: %d, END %d; LITER %d\n", e.curr, e.max, e.start, e.end, e.liter)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slc := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slc[i])
		}
		m := make(map[int]*Elem)
		for i := 0; i < n; i++ {
			if tmp, ok := m[slc[i]]; ok {
				if tmp.curr+2-(i-tmp.liter) > 1 {
					tmp.curr = tmp.curr + 2 - (i - tmp.liter)
				} else {
					tmp.curr = 1
					tmp.start = i
					tmp.end = i
				}
				tmp.liter = i
				if tmp.curr > tmp.max {
					tmp.max = tmp.curr
					tmp.end = i
				}
			} else {
				m[slc[i]] = NewElem(1, 1, i, i, i)
			}
		}
		res, l, r := 0, 0, 0
		fmt.Println("!!!", m)
		for key, i := range m {
			if i.max >= res {
				res = key
				r = i.end
				l = i.start
			}
		}
		fmt.Fprintln(writer, res, l+1, r+1)
	}
}

package main

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

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

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

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

		segs := make(map[int][][]int)
		for i := 0; i < n; i++ {
			s := []int{i, i}
			for j := i + 1; j < n; j++ {
				if a[i] != a[j] {
					break
				}
				s[1] = j
				i = j
			}
			if s[0] != s[1] {
				segs[a[i]] = append(segs[a[i]], s)
			}
		}

		var max int
		z, l, r := a[0], 0, 0
		for k, s2 := range segs {
			c := s2[0][1] - s2[0][0] + 1
			l2 := s2[0][0]
			r2 := s2[0][1]
			if c > max {
				z = k
				max = c
				l, r = l2, r2
			}

			for j := 1; j < len(s2); j++ {
				d := s2[j][0] - s2[j-1][1] - 1
				c -= d
				if c <= 0 {
					c = s2[j][1] - s2[j][0] + 1
					l2 = s2[j][0]
				} else {
					c += s2[j][1] - s2[j][0] + 1
				}
				if c > max {
					z = k
					max = c
					l, r = l2, s2[j][1]
				}
			}
		}
		fmt.Println(z, l+1, r+1)
	}
}

package main

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

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

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

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

		segs := make(map[int][][]int)
		for i := 0; i < n; i++ {
			s := []int{i, i}
			for j := i + 1; j < n; j++ {
				if a[i] != a[j] {
					break
				}
				s[1] = j
				i = j
			}
			if s[0] != s[1] {
				segs[a[i]] = append(segs[a[i]], s)
			}
		}

		var max int
		z, l, r := a[0], 0, 0
		for k, s2 := range segs {
			c := s2[0][1] - s2[0][0] + 1
			l2 := s2[0][0]
			r2 := s2[0][1]
			if c > max {
				z = k
				max = c
				l, r = l2, r2
			}

			for j := 1; j < len(s2); j++ {
				d := s2[j][0] - s2[j-1][1] - 1
				c -= d
				if c-d <= 0 {
					c = s2[j][1] - s2[j][0] + 1
					l2, r2 = s2[j][0], s2[j][1]
				}

				if c > max {
					z = k
					max = c
					l, r = l2, r2
				}
			}
		}
		fmt.Println(z, l+1, r+1)
	}
}

package main

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

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

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

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

		m := make([]bool, n)
		var max int
		z, l, r := a[0], 0, 0
		for i := 0; i < n; i++ {
			if m[i] || counts[a[i]] <= max {
				continue
			}
			counts[a[i]]--
			c := 1
			for j := i + 1; j < n; j++ {
				if a[i] == a[j] {
					m[i] = true
					counts[a[i]]--
					c++
				} else {
					c--
					if c == 0 {
						break
					}
				}

				if c > max {
					max = c
					z, l, r = a[i], i, j
				}
			}
		}

		fmt.Fprintln(out, z, l+1, r+1)
	}
}

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pos := map[int][]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			pos[v] = append(pos[v], i)
		}
		maxS, ans, l, r := 1, v, n-1, n-1
		for v, ps := range pos {
			for i, s, minS, minI := 1, 1, 0, ps[0]; i < len(ps); i++ {
				if ps[i]-ps[i-1] > 1 {
					s -= ps[i] - ps[i-1] - 1
					if s < minS {
						minS, minI = s, ps[i-1]
					}
				}
				s++
				if s-minS > maxS {
					maxS, ans, l, r = s-minS, v, minI, ps[i]
				}
			}
		}
		Fprintln(out, ans, l+1, r+1)
	}
}

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

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		// int64
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		pos := map[int][]int{}
		for i, v := range a {
			pos[v] = append(pos[v], i)
		}

		mxs := 1
		mxv, mxl, mxr := a[0], 0,0
		for v, ps := range pos {
			mins := 0
			mi := 0
			s := 0
			for i, p := range ps {
				if i == 0 {
					s = 1
					mi = p - 1
				} else if p == ps[i]+1 {
					s++
					if s-mins > mxs {
						mxs = s - mins
						mxv, mxl, mxr = v, mi+1, p
					}
				} else {
					s -= p - ps[i] - 1
					if s < mins {
						mins = s
						mi = p-1
					}
					s++
					if s-mins > mxs {
						mxs = s - mins
						mxv, mxl, mxr =v, mi+1, p
					}
				}
			}
		}
		Fprintln(out, mxv, mxl+1, mxr+1)
	}

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

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

}

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

package main

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

/*
1
10
2 1 2 2 2 4 2 2 1 4
---
2 3 8
*/

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

	numToIdcs := make(map[int][]int)

	for i := 0; i < n; i++ {
		var num int
		scanf("%d", &num)

		numToIdcs[num] = append(numToIdcs[num], i)
	}
	scanf("\n")

	bestSum := 0
	bestNum := -1
	bestL, bestR := -1, -1

	for num, idcs := range numToIdcs {
		if bestNum == -1 {
			bestSum = 1
			bestNum = num
			bestL, bestR = idcs[0], idcs[0]
		}

		sum := 1
		l := idcs[0]

		for i := 1; i < len(idcs); i++ {
			prevIdx, idx := idcs[i-1], idcs[i]
			toRemove := idx - prevIdx - 1

			if toRemove >= sum {
				sum = 1
				l = idx
			} else {
				sum += 1 + toRemove
			}

			if sum > bestSum {
				bestSum = sum
				bestNum = num
				bestL, bestR = l, idx
			}
		}
	}

	fmt.Fprintln(writer, bestNum, bestL+1, bestR+1)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

/*
1
10
2 1 2 2 2 4 2 2 1 4
---
2 3 8
*/

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

	numToIdcs := make(map[int][]int)

	for i := 0; i < n; i++ {
		var num int
		scanf("%d", &num)

		numToIdcs[num] = append(numToIdcs[num], i)
	}
	scanf("\n")

	bestSum := 0
	bestNum := -1
	bestL, bestR := -1, -1

	for num, idcs := range numToIdcs {
		sum := 1
		l := idcs[0]

		if bestNum == -1 {
			bestSum = 1
			bestNum = num
			bestL, bestR = idcs[0], idcs[0]
		}

		for i := 1; i < len(idcs); i++ {
			prevIdx, idx := idcs[i-1], idcs[i]
			toRemove := idx - prevIdx - 1

			if toRemove >= sum {
				sum = 1
				l = idx
			} else {
				sum += 1
			}

			if sum > bestSum {
				bestSum = sum
				bestNum = num
				bestL, bestR = l, idx
			}
		}
	}

	fmt.Fprintln(writer, bestNum, bestL+1, bestR+1)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}


Monocarp has been collecting rare magazines for quite a while, and now he has decided to sell them. He distributed the magazines between $$$n$$$ boxes, arranged in a row. The $$$i$$$-th box contains $$$a_i$$$ magazines. Some of the boxes are covered with lids, others are not. Suddenly it started to rain, and now Monocarp has to save as many magazines from the rain as possible. To do this, he can move the lids between boxes as follows: if the $$$i$$$-th box was covered with a lid initially, he can either move the lid from the $$$i$$$-th box to the box $$$(i-1)$$$ (if it exists), or keep the lid on the $$$i$$$-th box. You may assume that Monocarp can move the lids instantly at the same moment, and no lid can be moved more than once. If a box will be covered with a lid after Monocarp moves the lids, the magazines in it will be safe from the rain; otherwise they will soak.You have to calculate the maximum number of magazines Monocarp can save from the rain.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of the testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of boxes. The second line contains a string of $$$n$$$ characters 0 and/or 1. If the $$$i$$$-th character is 1, the $$$i$$$-th box is initially covered with a lid. If the $$$i$$$-th character is 0, the $$$i$$$-th box is initially not covered. The third line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of magazines in the $$$i$$$-th box. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print one integer — the maximum number of magazines Monocarp can save from the rain.

NoteIn the first testcase of the example, Monocarp can move the lid from the second box to the first box, so the boxes $$$1$$$, $$$3$$$ and $$$4$$$ are covered, and $$$10 + 8 + 9 = 27$$$ magazines are saved.In the second testcase, Monocarp can move the lid from the second box to the first box, then from the third box to the second box, then from the fifth box to the fourth box, and then from the sixth box to the fifth box. The boxes $$$1$$$, $$$2$$$, $$$4$$$ and $$$5$$$ will be covered, so $$$20 + 10 + 30 + 20 = 80$$$ magazines can be saved.There are no lids in the third testcase, so it's impossible to save even a single magazine.

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		ans := 0
		n, s := nextInt(), nextString()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = nextInt()
		}
		var i int
		for i = 0; i < n && s[i] == '1'; i++ {
			ans += a[i]
		}
		if i < n {
			sum, mn := a[i], a[i]
			for i = i + 1; i < n; i++ {
				if s[i] == '0' {
					ans += sum - mn
					sum = a[i]
					mn = a[i]
				} else {
					sum += a[i]
					mn = min(mn, a[i])
				}
			}
			fmt.Println(ans + sum - mn)
		} else {
			fmt.Println(ans)
		}
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func min(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

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

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

package main

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

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

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

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

		aa := make([]int64, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		last := -1
		var tot int64
		for i := 0; i < n; i++ {
			if s[i] == '1' {
				if last >= 0 && aa[i] < aa[last] {
					tot += aa[last]
					s[last] = '1'
					s[i] = '0'
					last = i
				} else {
					tot += aa[i]
				}
			} else if s[i] == '0' {
				last = i
			}
		}

		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		aa := make([]int64, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		last := -1
		if s[0] == '0' {
			last = 0
		}

		for i := 1; i < n; i++ {
			if s[i] == '1' && last >= 0 && aa[i] < aa[last] {
				s[last] = '1'
				s[i] = '0'
				last = i
			} else if s[i] == '0' {
				last = i
			}
		}

		var tot int64
		for i, ch := range s {
			if ch == '1' {
				tot += aa[i]
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
var r *bufio.Reader
var w *bufio.Writer
func max(nums ...int) int{
	res:=math.MinInt
	for _,i:=range nums{
		if i>res{
			res=i
		}
	}
	return res
}
func solve(){
	defer w.Flush()
	var n int
	var good []byte
	fmt.Fscan(r, &n, &good)
	nums:=make([]int, n)

	take:=make([]int, n) //take[i], ans of [i..n-1], if i has used its 1 on itself
	leave:=make([]int, n) //leave[i], ans of [i..n-1], if i has not used its own 1

	for i:=0;i<n;i++{
		fmt.Fscan(r, &nums[i])
	}
	if good[n-1]==49{
		take[n-1]=nums[n-1]
	}
	for i:=n-2;i>=0;i--{
		leave[i]= max(leave[i+1], take[i+1])
		take[i] = max(leave[i+1], take[i+1])
		if good[i]==49{
			take[i]=max(take[i], nums[i]+take[i+1])
			if good[i+1]==48{
				take[i]=max(take[i], nums[i]+leave[i+1])
			}
		}
		if good[i+1]==49{
			leave[i]=max(leave[i], nums[i]+leave[i+1])
		}
	}
	//fmt.Println("take ", take)
	//fmt.Println("leave", leave)
	fmt.Fprintln(w, max(take[0],leave[0]));
}
func init(){
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
}
func main(){
	defer  w.Flush()
	var t int;
	fmt.Fscan(r, &t);
	for t>0{
		solve();
		t--;
	}
}

package main

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

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

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

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

	var T int
	var n int
	var s string
	var x int

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

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

		a, b := 0, 0
		if s[0] == '1' {
			a = r[0]
		}

		for i := 1; i < n; i++ {
			if s[i] == '0' {
				continue
			}
			tb := b
			if s[i-1] == '0' {
				b = max(a, b) + r[i-1]
			} else {
				b = b + r[i-1]
			}
			a = max(a, tb) + r[i]
			//Fprintln(out, "i ", i, a, b)
		}

		Fprintln(out, max(a, b))
	}
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		var b []byte
		fmt.Fscan(r, &n, &b)
		for i := range b { b[i] -= '0' }
		b = append([]byte{0}, b...)

		a := make([]int, n+1)
		for i := 1; i <= n; i++ { fmt.Fscan(r, &a[i]) }

		i := 0
		res := 0
		for i <= n {
			for i <= n && b[i] == 0 { i++ }
			j := i
			sum_ := a[j-1]
			min_ := a[j-1]
			for j <= n && b[j] == 1 {
				sum_ += a[j]
				if a[j] < min_ { min_ = a[j] }
				j++
			}
			if j > i { res += sum_ - min_ }
			i = j
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

func sum(a []int, i int) int {
	_sum := 0
	for j := 0; j < i; j++ { _sum += a[j] }
	return _sum
}

func sum_min(a []int, l, r int) (int, int) {
	_sum := 0
	_min := a[l]
	for j := l; j < r; j++ {
		_sum += a[j]
		if a[j] < _min { _min = a[j] }
	}
	return _sum, _min
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		var b []byte
		fmt.Fscan(r, &n, &b)
		for i := range b { b[i] -= '0' }

		a := make([]int, n)
		for i := range a { fmt.Fscan(r, &a[i]) }

		i := 0
		res := 0
		for i < n {
			for i < n && b[i] == 0 { i++ }
			j := i
			for j < n && b[j] == 1 { j++ }
			if i == 0 {
				res += sum(a, j)
			} else if j > i {
				_sum, _min := sum_min(a, i-1, j)
				res += _sum - _min
			}
			i = j
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

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

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

func solve() {
    var n int
    var s string
    Fscan(in, &n, &s)

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

    ans := 0
    for i := 1; i <= n; i++ {
        if string(s[i - 1]) != "1" {
            continue;
        }

        j := i;
        for ; j < n && string(s[j]) == "1"; j++ {

        }

        res := a[j] - a[i - 1];
        for k := i; k <= j; k++ {
            v := 0
            if i >= 2 {
                v = a[i - 2]
            }
            res = max(res, a[k - 1] - v + a[j] - a[k])
        }
        ans += res

        i = j;
    }

    Fprintln(out, ans)
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

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

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

type BestAns struct {
	withLid    int64
	withoutLid int64
}

var MOD int64 = 1000*1000*1000 + 7

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func main() {
	defer writer.Flush()

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

	for q := 0; q < t; q++ {
		var n int
		var boxes string

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

		boxStates := make([]bool, n, n)
		arr := make([]int64, n, n)

		scanf("%s\n", &boxes)
		for i := 0; i < n; i++ {
			if boxes[i] == '1' {
				boxStates[i] = true
			}
		}

		for i := 0; i < n; i++ {
			if i != n-1 {
				scanf("%d ", &arr[i])
			} else {
				scanf("%d\n", &arr[i])
			}
		}

		dp := make([]BestAns, n, n)

		if boxStates[0] {
			dp[0] = BestAns{
				withLid:    arr[0],
				withoutLid: 0,
			}
		}

		for i := 1; i < n; i++ {
			if boxStates[i] {
				dp[i].withLid = arr[i] + max(dp[i-1].withLid, dp[i-1].withoutLid)
				dp[i].withoutLid = max(dp[i-1].withLid, dp[i-1].withoutLid+arr[i-1])
			} else {
				dp[i].withLid = -math.MaxInt64
				dp[i].withoutLid = max(dp[i-1].withLid, dp[i-1].withoutLid)
			}
		}
		ans := max(dp[n-1].withLid, dp[n-1].withoutLid)

		printf("%d\n", ans)
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		ans := 0
		n, s := nextInt(), nextString()
		a := make([]int, n)
		sum, mn := 0, N
		flag := false
		for i := 0; i < n; i++ {
			a[i] = nextInt()
			if s[i] == '0' {
				if !flag {
					if s[0] == '1' {
						ans += sum
					} else {
						ans += max(0, sum-mn)
					}
					flag = true
				} else {
					ans += max(0, sum-mn)
				}
				sum = a[i]
				mn = a[i]
			} else {
				sum += a[i]
				mn = min(mn, a[i])
			}
		}
		ans += max(0, sum-mn)
		fmt.Println(ans)
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func min(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		ans := 0
		n, s := nextInt(), nextString()
		a := make([]int, n)
		sum, mn := 0, N
		flag := false
		for i := 0; i < n; i++ {
			a[i] = nextInt()
			if s[i] == '0' {
				if !flag {
					ans += sum
					flag = true
				} else {
					ans += max(0, sum-mn)
				}
				sum = a[i]
				mn = a[i]
			} else {
				sum += a[i]
				mn = min(mn, a[i])
			}
		}
		ans += max(0, sum-mn)
		fmt.Println(ans)
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func min(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		ans := 0
		n, s := nextInt(), nextString()
		a := make([]int, n)
		sum, mn := 0, N
		flag := false
		for i := 0; i < n; i++ {
			a[i] = nextInt()
			if s[i] == '0' {
				if !flag {
					ans += sum
					flag = true
				} else {
					ans += sum - mn
				}
				sum = a[i]
				mn = a[i]
			} else {
				sum += a[i]
				mn = min(mn, a[i])
			}
		}
		ans += sum - mn
		fmt.Println(ans)
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func min(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		ans := 0
		n, s := nextInt(), nextString()
		a := make([]int, n)
		sum, mn := 0, N
		for i := 0; i < n; i++ {
			a[i] = nextInt()
			if s[i] == '0' {
				if i-1 >= 0 {
					ans += sum - mn
				}
				sum = a[i]
				mn = a[i]
			} else {
				sum += a[i]
				mn = min(mn, a[i])
			}
		}
		ans += sum - mn
		fmt.Println(ans)
	}
}

func min(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

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

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

package main

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

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

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

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

		aa := make([]int64, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		last := -1
		if s[0] == '0' {
			last = 0
		}

		var tot int64
		for i := 1; i < n; i++ {
			if s[i] == '1' {
				if last >= 0 && aa[i] < aa[last] {
					tot += aa[last]
					s[last] = '1'
					s[i] = '0'
					last = i
				} else {
					tot += aa[i]
				}
			} else if s[i] == '0' {
				last = i
			}
		}

		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		aa := make([]int64, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		last := -1
		if s[0] == '0' {
			last = 0
		}

		for i := 1; i < n; i++ {
			if s[i] == '1' && aa[i] < aa[i-1] && last >= 0 {
				s[last] = '1'
				s[i] = '0'
				last = i
			} else if s[i] == '0' {
				last = i
			}
		}

		var tot int64
		for i, ch := range s {
			if ch == '1' {
				tot += aa[i]
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"fmt"
	"math"
)
func max(nums ...int) int{
	res:=math.MinInt
	for _,i:=range nums{
		if i>res{
			res=i
		}
	}
	return res
}
func solve(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	good:=[]byte(s)
	nums:=make([]int, n)

	take:=make([]int, n) //take[i], ans of [i..n-1], if i has used its 1 on itself
	leave:=make([]int, n) //leave[i], ans of [i..n-1], if i has not used its own 1

	for i:=0;i<n;i++{
		fmt.Scan(&nums[i])
	}
	if good[n-1]==49{
		take[n-1]=nums[n-1]
	}
	for i:=n-2;i>=0;i--{
		leave[i]= max(leave[i+1], take[i+1])
		take[i] = max(leave[i+1], take[i+1])
		if good[i]==49{
			take[i]=max(take[i], nums[i]+take[i+1])
		}
		if good[i+1]==49{
			leave[i]=max(leave[i], nums[i]+leave[i+1])
		}
	}
	//fmt.Println("take ", take)
	//fmt.Println("leave", leave)
	fmt.Println(max(take[0],leave[0]));
}
func main(){
	var t int;
	fmt.Scan(&t);
	for t>0{
		solve();
		t--;
	}
}

package main

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

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

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

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

	var T int
	var n int
	var s string
	var x int

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

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

		a, b := 0, 0
		if s[0] == '1' {
			a = r[0]
			b = r[0]
		}

		for i := 1; i < n; i++ {
			if s[i] == '0' {
				continue
			}
			tb := b
			if s[i-1] == '0' {
				b = max(a, b) + r[i-1]
			} else {
				b = b + r[i-1]
			}
			a = max(a, tb) + r[i]
			//Fprintln(out, "i ", i, a, b)
		}

		Fprintln(out, max(a, b))
	}
}

package main

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

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

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

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

	var T int
	var n int
	var s string
	var x int

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

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

		a, b := 0, 0
		if s[0] == '1' {
			a = r[0]
			b = r[0]
		}

		for i := 1; i < n; i++ {
			if s[i] == '0' {
				continue
			}
			if s[i-1] == '0' {
				a, b = max(a, b)+r[i], max(a, b)+r[i-1]
			} else {
				a, b = max(a, b)+r[i], b+r[i-1]
			}
			//Fprintln(out, "i ", i, a, b)
		}

		Fprintln(out, max(a, b))
	}
}


There is a robot in a warehouse and $$$n$$$ packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point $$$(0, 0)$$$. The $$$i$$$-th package is at the point $$$(x_i, y_i)$$$. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point $$$(0, 0)$$$ doesn't contain a package.The robot is semi-broken and only can move up ('U') and right ('R'). In other words, in one move the robot can go from the point $$$(x, y)$$$ to the point ($$$x + 1, y$$$) or to the point $$$(x, y + 1)$$$.As we say above, the robot wants to collect all $$$n$$$ packages (in arbitrary order). He wants to do it with the minimum possible number of moves. If there are several possible traversals, the robot wants to choose the lexicographically smallest path.The string $$$s$$$ of length $$$n$$$ is lexicographically less than the string $$$t$$$ of length $$$n$$$ if there is some index $$$1 \le j \le n$$$ that for all $$$i$$$ from $$$1$$$ to $$$j-1$$$ $$$s_i = t_i$$$ and $$$s_j < t_j$$$. It is the standard comparison of string, like in a dictionary. Most programming languages compare strings in this way.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then test cases follow. The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of packages. The next $$$n$$$ lines contain descriptions of packages. The $$$i$$$-th package is given as two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i, y_i \le 1000$$$) — the $$$x$$$-coordinate of the package and the $$$y$$$-coordinate of the package. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point $$$(0, 0)$$$ doesn't contain a package. The sum of all values $$$n$$$ over test cases in the test doesn't exceed $$$1000$$$.

Print the answer for each test case. If it is impossible to collect all $$$n$$$ packages in some order starting from ($$$0,0$$$), print "NO" on the first line. Otherwise, print "YES" in the first line. Then print the shortest path — a string consisting of characters 'R' and 'U'. Among all such paths choose the lexicographically smallest path. Note that in this problem "YES" and "NO" can be only uppercase words, i.e. "Yes", "no" and "YeS" are not acceptable.

NoteFor the first test case in the example the optimal path RUUURRRRUU is shown below:

package main

import (
	"fmt"
	"strings"
)

func CollectingPackages(iList [][]int) (string, string) {
	rs := ""
	xTemp := 0
	yTemp := 0
	count := 0
	for {
		ySub := yTemp
		for j := 0; j < len(iList); j++ {
			if iList[j][0] == xTemp {
				if iList[j][1] < ySub {
					return "NO", ""
				}
				count++
				if iList[j][1] > yTemp {
					rs += strings.Repeat("U", iList[j][1]-yTemp)
					yTemp = iList[j][1]
				}
			}
		}
		xTemp++
		if count == len(iList) {
			return "YES", rs
		}
		rs += "R"
	}
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		var iList [][]int
		fmt.Scanf("%d\n", &n)
		for j := 0; j < n; j++ {
			var x, y int
			var temp []int
			fmt.Scanf("%d %d\n", &x, &y)
			temp = append(temp, x, y)
			iList = append(iList, temp)
		}
		ok, rs := CollectingPackages(iList)
		if ok == "YES" {
			fmt.Println(ok)
			fmt.Println(rs)
		} else {
			fmt.Println(ok)
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

type point struct {
	x, y int
}

func main() {
	var (
		n int
		t int
	)
	fmt.Scan(&t)
	for ; t > 0; t-- {
		fmt.Scan( &n)
		arr := make([] point, n)

		for i := 0; i < n; i++ {
			var x , y int
			fmt.Scan(&x, &y)
			arr[i] = point{x, y}
		}
		sort.SliceStable(arr, func(i, j int) bool{
			if arr[i].x != arr[j].x {
				return arr[i].x < arr[j].x
			}
			return arr[i].y < arr[j].y
		})

		start := point{0,0}
		succ := true
		ans := ""
		for i := 0; i < n; i++ {
			if start.x > arr[i].x || start.y > arr[i].y {
				succ = false
				break
			}
			for j := 0; j < arr[i].x - start.x; j++ {
				ans = ans + "R"
			}
			for j := 0; j < arr[i].y - start.y; j++ {
				ans = ans + "U"
			}
			start = arr[i];
		}
		if (succ) {
			fmt.Println("YES")
			fmt.Println(ans)
		} else {
			fmt.Println("NO")
		}
	}

}

package main

import (
	"fmt"
	"sort"
)

type Point struct {
	x,y int
}

func main() {
	var t int
	fmt.Scan(&t)
	for T := 0 ; T < t ; T ++ {
		var n int
		fmt.Scan(&n)
		 var pts []Point
		pts = make([]Point , n)
		for i := 0 ; i < n ; i ++ {
			fmt.Scan(&pts[i].x,&pts[i].y)
		}
		var zer Point
		zer.x = 0
		zer.y = 0
		pts = append(pts , zer)
		sort.Slice(pts , func(i,j int) bool{
			if pts[i].x < pts[j].x {
				return true
			} else if pts[i].x == pts[j].x {
				if pts[i].y < pts[j].y {
					return true
				} else{
					return false
				}
			} else {
				return false
			}
		})
		ok := true
		var output string
		output = ""
		for i := 1 ; i <= n ; i ++ {
			if pts[i-1].x <= pts[i].x && pts[i-1].y <= pts[i].y {
				var r,u int
				r = pts[i].x - pts[i-1].x
				u = pts[i].y - pts[i-1].y
				for j := 0 ; j < r ; j ++ {
					output = output + "R"
				}
				for j := 0 ; j < u ; j ++ {
					output = output + "U"
				}
			} else{
				ok = false
				break
			}
		}
		if ok == true {
			fmt.Println("YES")
			fmt.Println(output)
		}else{
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

type atom struct{x,y int}

func Main(){
	var n int
	fmt.Scanf("%d\n",&n)
	a:=make([]atom,n)
	for i:=0;i<n;i++{
		var x,y int
		fmt.Scanf("%d %d\n",&x,&y)
		a[i]=atom{x,y}
	}
	for rd:=0;rd<n;rd++{
		for i:=0;i+1<n;i++{
			if a[i].x+a[i].y>a[i+1].x+a[i+1].y{
				a[i],a[i+1]=a[i+1],a[i]
			}
		}
	}
	nowx,nowy:=0,0
	for i:=0;i+1<n;i++{
		if a[i].x>a[i+1].x || a[i].y>a[i+1].y{
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	for i:=0;i<n;i++{
		for ;nowx<a[i].x;nowx++{
			fmt.Print("R")
		}
		for ;nowy<a[i].y;nowy++{
			fmt.Print("U")
		}
	}
	fmt.Print("\n")
}

func main(){
	var t int
	fmt.Scanf("%d\n",&t)
	for ;t>0;t--{
		Main()
	}
}

package main

import (
	"fmt"
	"sort"
	"strings"
)

type point struct {
	x, y, d int
}

type points []point

func (p points) Len() int {
	return len(p)
}
func (p points) Less(i, j int) bool {
	return p[i].d < p[j].d
}
func (p points) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

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

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		p := make([]point, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&p[j].x, &p[j].y)
			p[j].d = p[j].x + p[j].y
		}
		sort.Sort(points(p))
		// 近い順に全て辿れるか？
		// fmt.Println("debug - points", p)
		now := point{0, 0, 0}
		ans := ""
		ok := true
		for j := 0; j < n; j++ {
			if abs(p[j].x-now.x)+abs(p[j].y-now.y) != abs(p[j].d-now.d) {
				ok = false
				break
			} else {
				ans += strings.Repeat("R", p[j].x-now.x)
				ans += strings.Repeat("U", p[j].y-now.y)
				now = p[j]
			}
		}
		if ok {
			fmt.Println("YES")
			fmt.Println(ans)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import(
	"fmt"
	"sort"
)
type point struct{
	x int
	y int
}
type newlist []*point

func check(list newlist,n int) bool {
	for i:=1;i<n;i++{
		if list[i].y < list[i-1].y{
			return false
		}
	}
	return true
}
func main(){
	var t,n int
	fmt.Scan(&t)
	for ;t>0;t--{
		fmt.Scan(&n)
		var list newlist
		for i:=0;i<n;i++{
			var x,y int
			fmt.Scan(&x,&y)
			list = append(list,&point{x,y})
		}
		sort.Sort(list)
		if check(list,n)==false{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			x,y:=0,0
			for i:=0;i<n;i++{
				for j:=x;j<list[i].x;j++{
					fmt.Printf("R")
				}
				for j:=y;j<list[i].y;j++{
					fmt.Printf("U")
				}
				x,y = list[i].x,list[i].y
			}
			fmt.Printf("\n")
		}
	}
}

func (a newlist) Len() int{
	return len(a)
}
func (a newlist) Less(i,j int) bool{
	if a[i].x == a[j].x{
		return a[i].y<a[j].y
	}else{
		return a[i].x < a[j].x
	}
}
func (a newlist) Swap(i,j int){
	a[i],a[j] = a[j],a[i]
}

package main

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

type Point struct {
	x, y int
}

type PointArr []Point

func (p PointArr) Len() int {
	return len(p)
}

func (p PointArr) Less(i, j int) bool {
	return p[i].x < p[j].x || (p[i].x == p[j].x && p[i].y <= p[j].y)
}

func (p PointArr) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t, n, x, y int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n)
		coords := make([]Point, n)
		for i := 0; i < n; i++ {
			fmt.Fscanln(reader, &x, &y)
			coords[i] = Point{x: x, y: y}
		}
		sort.Sort(PointArr(coords))
		var ans strings.Builder
		has_error := false
		prev := Point{x: 0, y: 0}
		for i := 0; i < n; i++ {
			b := coords[i]
			if prev.y > b.y {
				// Can't move down
				has_error = true
				break
			}
			for prev.x < b.x {
				ans.WriteString("R")
				prev.x += 1
			}
			for prev.y < b.y {
				ans.WriteString("U")
				prev.y += 1
			}
			prev = b
		}
		if has_error {
			fmt.Fprintln(writer, "NO")
			continue
		}
		fmt.Fprintln(writer, "YES")
		fmt.Fprintln(writer, ans.String())
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

type Point struct {
	x    int
	y    int
	dist float64
}

type PointList []Point

func (p PointList) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p PointList) Len() int           { return len(p) }
func (p PointList) Less(i, j int) bool { return p[i].dist < p[j].dist }

func main() {

	var t, n int
	fmt.Scanln(&t)

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

		var plist PointList
		for j := 0; j < n; j++ {
			var x, y int
			fmt.Scanf("%d %d\n", &x, &y)

			point := Point{x: x, y: y, dist: math.Sqrt(float64(x*x + y*y))}
			plist = append(plist, point)
		}

		sort.Sort(plist)

		steps := ""
		currX := 0
		currY := 0

		for j := 0; j < n; j++ {
			p := plist[j]

			if p.x >= currX {
				for k := 0; k < p.x-currX; k++ {
					steps += "R"
				}
				currX = p.x
			} else {
				if currX != 0 {
					steps = ""
					break
				}
			}

			if p.y >= currY {
				for k := 0; k < p.y-currY; k++ {
					steps += "U"
				}
				currY = p.y
			} else {
				if currY != 0 {
					steps = ""
					break
				}
			}
		}

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

package main

import "fmt"

import "sort"

type point struct {
	x, y int
}

func (a point) Less(p point) bool {
	if a.x == p.x {
		return a.y < p.y
	}
	return a.x < p.x
}

// ByXY is used for sort point
type ByXY []point

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

func main() {
	var t int
	fmt.Scan(&t)
	for tt := 0; tt < t; tt++ {
		var n int
		fmt.Scan(&n)
		p := make([]point, n)
		for i := range p {
			fmt.Scan(&p[i].x, &p[i].y)
		}
		sort.Sort(ByXY(p))
		flag := false
		var lx, ly int
		for i := range p {
			if p[i].x < lx || p[i].y < ly {
				flag = true
				break
			}
			lx, ly = p[i].x, p[i].y
		}
		if flag {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			var lx, ly int
			for i := range p {
				for lx < p[i].x {
					fmt.Print("R")
					lx++
				}
				for ly < p[i].y {
					fmt.Print("U")
					ly++
				}
			}
			fmt.Println()
		}
	}
}

package main

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

type Vertex struct {
	x, y int
}

func getMove(from, to Vertex) string{
	var move string
	for i := 0; i < to.x - from.x; i++ {
		move = move + "R"
	}
	for j := 0; j < to.y - from.y; j++ {
		move = move + "U"
	}
	return move
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	var ans []string
	for i := 0; i < t; i++ {
		var n int
		var input []Vertex
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			var x, y int
			fmt.Fscan(in, &x, &y)
			input = append(input, Vertex{x, y})
		}
		input = append(input, Vertex{0, 0})
		sort.Slice(input, func(i, j int)bool {
			if input[i].x < input[j].x{
				return true;
			}else{
				if input[i].y < input[j].y{
					return true;
				}else{
					return false;
				}
			}
		})
		ok := true
		n = n + 1
		var tmp string
		//fmt.Println(input)
		for j := 1; j < n; j++ {
			if input[j].x>=input[j-1].x&&input[j].y>=input[j-1].y {
				tmp = tmp + getMove(input[j-1], input[j])
			}else{
				ok = false
			}
		}
		if ok {
			ans = append(ans, "YES")
			ans = append(ans, tmp)
		}else{
			ans = append(ans, "NO")
		}
	}
	fmt.Fprintln(out, strings.Join(ans, "\n"));
}

package main

import (
	"fmt"
	"strings"
)

func CollectingPackages(iList [][]int) (string, string) {
	rs := ""
	xTemp := 0
	yTemp := 0
	count := 0
	for {
		flag := 0
		for j := 0; j < len(iList); j++ {
			if iList[j][0] == xTemp {
				flag++
				if flag == 1 {
					if iList[j][1] < yTemp {
						return "NO", ""
					}
				}
				count++
				if iList[j][1] > yTemp {
					rs += strings.Repeat("U", iList[j][1] - yTemp)
					yTemp = iList[j][1]
				}
			}
		}
		xTemp++
		if count == len(iList) {
			return "YES", rs
		}
		rs += "R"
	}
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		var iList [][]int
		fmt.Scanf("%d\n", &n)
		for j := 0; j < n; j++ {
			var x, y int
			var temp []int
			fmt.Scanf("%d %d\n", &x, &y)
			temp = append(temp, x, y)
			iList = append(iList, temp)
		}
		ok, rs := CollectingPackages(iList)
		if ok == "YES" {
			fmt.Println(ok)
			fmt.Println(rs)
		} else {
			fmt.Println(ok)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func CollectingPackages(iList [][]int) (string, string) {
	rs := ""
	xTemp := 0
	yTemp := 0
	count := 0
	for {
		flag := 0
		for j := 0; j < len(iList); j++ {
			if iList[j][0] == xTemp {
				flag++
				if flag == 1 {
					if iList[j][1] < yTemp {
						return "NO", ""
					}
					if iList[j][1] == yTemp {
						flag--
					}
				}
				count++
				if iList[j][1] > yTemp {
					rs += strings.Repeat("U", iList[j][1] - yTemp)
					yTemp = iList[j][1]
				}
			}
		}
		xTemp++
		if count == len(iList) {
			return "YES", rs
		}
		rs += "R"
	}
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		var iList [][]int
		fmt.Scanf("%d\n", &n)
		for j := 0; j < n; j++ {
			var x, y int
			var temp []int
			fmt.Scanf("%d %d\n", &x, &y)
			temp = append(temp, x, y)
			iList = append(iList, temp)
		}
		ok, rs := CollectingPackages(iList)
		if ok == "YES" {
			fmt.Println(ok)
			fmt.Println(rs)
		} else {
			fmt.Println(ok)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

//
//func swap(xp *float64, yp *float64) {
//	temp := *xp;
//	*xp = *yp;
//	*yp = temp;
//}
//
//func swapArr(xp *[]int, yp *[]int) {
//	temp := *xp;
//	*xp = *yp;
//	*yp = temp;
//}
//
//
//// A function to implement bubble sort
//func bubbleSort(arr []float64, iList [][]int)  [][]int {
//	for i := 0; i < len(arr)-1; i++ {
//		for j := 0; j < len(arr)-i-1; j++ {
//			if arr[j] > arr[j+1] {
//				swap(&arr[j], &arr[j+1])
//				swapArr(&iList[j], &iList[j+1])
//			}
//		}
//	}
//	return iList
//}
//
//func calDistance(x1, y1 int) float64 {
//	return math.Sqrt(math.Pow(float64(x1), 2) + math.Pow(float64(y1), 2))
//}
//

func CollectingPackages(iList [][]int) (string, string) {
	rs := ""
	xTemp := 0
	yTemp := 0
	count := 0
	for {
		flag := 0
		for j := 0; j < len(iList); j++ {
			if iList[j][0] == xTemp {
				flag++
				if flag == 1 {
					if iList[j][1] < yTemp {
						return "NO", ""
					}
				}
				count++
				if iList[j][1] > yTemp {
					rs += strings.Repeat("U", iList[j][1] - yTemp)
					yTemp = iList[j][1]
				}
			}
		}
		xTemp++
		if count == len(iList) {
			return "YES", rs
		}
		rs += "R"
	}
}

func main() {
	var t int
	var iList [][]int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		for j := 0; j < n; j++ {
			var x, y int
			var temp []int
			fmt.Scanf("%d %d\n", &x, &y)
			temp = append(temp, x, y)
			iList = append(iList, temp)
		}
	}
	ok, rs := CollectingPackages(iList)
	if ok == "YES" {
		fmt.Println(ok)
		fmt.Println(rs)
	} else {
		fmt.Println(ok)
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

type Point struct {
	x    int
	y    int
	dist float64
}

type PointList []Point

func (p PointList) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p PointList) Len() int           { return len(p) }
func (p PointList) Less(i, j int) bool { return p[i].dist < p[j].dist }

func main() {

	var t, n int
	fmt.Scanln(&t)

	//reader := bufio.NewReader(os.Stdin)
	//scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n)

		var plist PointList
		for j := 0; j < n; j++ {
			//var str string
			/*if scanner.Scan() {
				str = scanner.Text()
			}
			//str, _ := reader.ReadString('\n')
			//str = str[0 : len(str)-1]
			coords := strings.Split(str, " ")

			x, _ := strconv.Atoi(coords[0])
			y, _ := strconv.Atoi(coords[1])*/
			var x, y int
			fmt.Scan(&x)
			fmt.Scan(&y)
			//fmt.Scanln()

			point := Point{x: x, y: y, dist: math.Sqrt(float64(x*x + y*y))}
			plist = append(plist, point)
		}

		sort.Sort(plist)

		steps := ""
		currX := 0
		currY := 0
		prevDist := float64(0)
		for j := 0; j < n; j++ {
			p := plist[j]

			if p.dist == prevDist {
				steps = ""
				break
			} else {
				prevDist = p.dist
			}

			if p.x > currX {
				for k := 0; k < p.x-currX; k++ {
					steps += "R"
				}
				currX = p.x
			}

			if p.y > currY {
				for k := 0; k < p.y-currY; k++ {
					steps += "U"
				}
				currY = p.y
			}
		}

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

package main

import (
	"fmt"
	"math"
	"sort"
)

type Point struct {
	x    int
	y    int
	dist float64
}

type PointList []Point

func (p PointList) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p PointList) Len() int           { return len(p) }
func (p PointList) Less(i, j int) bool { return p[i].dist < p[j].dist }

func main() {

	var t, n int
	fmt.Scanln(&t)

	//reader := bufio.NewReader(os.Stdin)
	//scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n)

		var plist PointList
		for j := 0; j < n; j++ {
			//var str string
			/*if scanner.Scan() {
				str = scanner.Text()
			}
			//str, _ := reader.ReadString('\n')
			//str = str[0 : len(str)-1]
			coords := strings.Split(str, " ")

			x, _ := strconv.Atoi(coords[0])
			y, _ := strconv.Atoi(coords[1])*/
			var x, y int
			fmt.Scanf("%d %d\n", &x, &y)

			point := Point{x: x, y: y, dist: math.Sqrt(float64(x*x + y*y))}
			plist = append(plist, point)
		}

		sort.Sort(plist)

		steps := ""
		currX := 0
		currY := 0
		prevDist := float64(0)
		for j := 0; j < n; j++ {
			p := plist[j]

			if p.dist == prevDist {
				steps = ""
				break
			} else {
				prevDist = p.dist
			}

			if p.x > currX {
				for k := 0; k < p.x-currX; k++ {
					steps += "R"
				}
				currX = p.x
			}

			if p.y > currY {
				for k := 0; k < p.y-currY; k++ {
					steps += "U"
				}
				currY = p.y
			}
		}

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

package main

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

type Vertex struct {
	x, y int
}

func getMove(from, to Vertex) string{
	var move string
	for i := 0; i < to.x - from.x; i++ {
		move = move + "R"
	}
	for j := 0; j < to.y - from.y; j++ {
		move = move + "U"
	}
	return move
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	var ans []string
	for i := 0; i < t; i++ {
		var n int
		var input []Vertex
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			var x, y int
			fmt.Fscan(in, &x, &y)
			input = append(input, Vertex{x, y})
		}
		input = append(input, Vertex{0, 0})
		sort.Slice(input, func(i, j int)bool {
			if input[i].x < input[j].x{
				return true;
			}else{
				if input[i].y < input[j].y{
					return true;
				}else{
					return false;
				}
			}
		})
		ok := true
		n = n + 1
		var tmp string
		for j := 1; j < n; j++ {
			if (input[j].x+input[j].y)>(input[j-1].x+input[j-1].y) {
				tmp = tmp + getMove(input[j-1], input[j])
			}else{
				ok = false
			}
		}
		if ok {
			ans = append(ans, "YES")
			ans = append(ans, tmp)
		}else{
			ans = append(ans, "NO")
		}
	}
	fmt.Fprintln(out, strings.Join(ans, "\n"));
}

package main

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

type Vertex struct {
	x, y int
}

func getMove(from, to Vertex) string{
	var move string
	for i := 0; i < to.x - from.x; i++ {
		move = move + "R"
	}
	for j := 0; j < to.y - from.y; j++ {
		move = move + "U"
	}
	return move
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	var ans []string
	for i := 0; i < t; i++ {
		var n int
		var input []Vertex
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			var x, y int
			fmt.Fscan(in, &x, &y)
			input = append(input, Vertex{x, y})
		}
		input = append(input, Vertex{0, 0})
		sort.Slice(input, func(i, j int)bool {
			if input[i].x < input[j].x{
				return true;
			}else{
				if input[i].y < input[j].y{
					return true;
				}else{
					return false;
				}
			}
		})
		ok := true
		n = n + 1
		var tmp string
		for j := 1; j < n; j++ {
			if input[j].x>input[j-1].x&&input[j].y>input[j-1].y {
				tmp = tmp + getMove(input[j-1], input[j])
			}else{
				ok = false
			}
		}
		if ok {
			ans = append(ans, "YES")
			ans = append(ans, tmp)
		}else{
			ans = append(ans, "NO")
		}
	}
	fmt.Fprintln(out, strings.Join(ans, "\n"));
}