There are $$$n$$$ people who want to participate in a boat competition. The weight of the $$$i$$$-th participant is $$$w_i$$$. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.So, if there are $$$k$$$ teams $$$(a_1, b_1)$$$, $$$(a_2, b_2)$$$, $$$\dots$$$, $$$(a_k, b_k)$$$, where $$$a_i$$$ is the weight of the first participant of the $$$i$$$-th team and $$$b_i$$$ is the weight of the second participant of the $$$i$$$-th team, then the condition $$$a_1 + b_1 = a_2 + b_2 = \dots = a_k + b_k = s$$$, where $$$s$$$ is the total weight of each team, should be satisfied.Your task is to choose such $$$s$$$ that the number of teams people can create is the maximum possible. Note that each participant can be in no more than one team.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of participants. The second line of the test case contains $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \le w_i \le n$$$), where $$$w_i$$$ is the weight of the $$$i$$$-th participant.

For each test case, print one integer $$$k$$$: the maximum number of teams people can compose with the total weight $$$s$$$, if you choose $$$s$$$ optimally.

NoteIn the first test case of the example, we can reach the optimal answer for $$$s=6$$$. Then the first boat is used by participants $$$1$$$ and $$$5$$$ and the second boat is used by participants $$$2$$$ and $$$4$$$ (indices are the same as weights).In the second test case of the example, we can reach the optimal answer for $$$s=12$$$. Then first $$$6$$$ participants can form $$$3$$$ pairs.In the third test case of the example, we can reach the optimal answer for $$$s=3$$$. The answer is $$$4$$$ because we have $$$4$$$ participants with weight $$$1$$$ and $$$4$$$ participants with weight $$$2$$$.In the fourth test case of the example, we can reach the optimal answer for $$$s=4$$$ or $$$s=6$$$.In the fifth test case of the example, we can reach the optimal answer for $$$s=3$$$. Note that participant with weight $$$3$$$ can't use the boat because there is no suitable pair for him in the list.

package main

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

const (
	MaxN int = 50 + 5
	MaxWeight int = 100
)

var (
	read = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
	weight [MaxN]int
	vis [MaxN]bool
)

func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(read, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(read, &weight[i])
		}
		var ans int = 0
		for w := 2; w <= MaxWeight; w++ {
			for i := 0; i < n; i++ {
				vis[i] = false
			}
			var tempAns int = 0
			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					if i != j && !vis[i] && !vis[j] && weight[i]+weight[j] == w {
						vis[i], vis[j] = true, true
						tempAns++
					}
				}
			}
			if ans < tempAns {
				ans = tempAns
			}
		}
		fmt.Fprintln(write, ans)
	}
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,cur int
		Fscan(in, &n)
		a:=make([]int,n+1)
		pos:=make([]int,2*n+1)

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

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

		for i:=0;i<=n;i++{
			pos[2*i]+=a[i]/2
			for j:=i+1;j<=n;j++{
				pos[i+j]+=min(a[i],a[j])
			}
		}

		ans:=0
		for i:=0;i<=2*n;i++{
			if ans<pos[i]{
				ans=pos[i]
			}
		}

		Fprintln(out,ans)
	}
}

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

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, W []int) int {
	sort.Ints(W)

	var best int

	for s := 2; s <= 2*n; s++ {
		var cnt int
		for i, j := 0, n-1; i < j; {
			if W[i]+W[j] == s {
				cnt++
				i++
				j--
			} else if W[i]+W[j] < s {
				i++
			} else {
				j--
			}
		}
		if cnt > best {
			best = cnt
		}
	}

	return best
}

package main

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

func main() {

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

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

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

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

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

		sort.Ints(a)

		result := 0
		if n > 1 {
			result = 1
		}

		for s := 1; s <= 2*n; s++ {
			cnt := 0
			l, r := 0, n-1
			for l < r {
				if a[l]+a[r] == s {
					l, r = l+1, r-1
					cnt++
				} else if a[l]+a[r] > s {
					r--
				} else {
					l++
				}
			}
			result = max(result, cnt)
		}

		fmt.Fprintln(out, result)

	}

}

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

package main

import (
    "fmt"
)

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

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

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

        cnt := make([]int, 2 * n + 1)
        for i := 0; i < n; i++ {
            cnt[w[i]]++
        }

        maxTotal := 0
        for s := 2; s <= 2 * n; s++ {
            total := 0
            for i := 1; i < s / 2; i++ {
                total += min(cnt[i], cnt[s - i])
            }
            if s % 2 == 0 {
                total += cnt[s / 2] / 2
            } else {
                total += min(cnt[s / 2], cnt[s / 2 + 1])
            }
            maxTotal = max(maxTotal, total)
        }

        fmt.Println(maxTotal)

        t--
    }
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		w := io.NextInts(n)
		f := make([]int, n+1)
		for _, x := range w {
			f[x]++
		}
		ans := 0
		for s := 2; s <= 2*n; s++ {
			c := 0
			for i := 1; i < s-i; i++ {
				if s-i <= n {
					c += min(f[i], f[s-i])
				}
			}
			if s%2 == 0 {
				c += f[s/2] / 2
			}
			ans = max(ans, c)
		}
		io.Println(ans)
	}
}

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

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(' ', x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

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

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

		for i := 0; i < n; i++ {
			a[input()]++
		}

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(max)
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		w := [110]int{}
		w_c := [110]int{}

		for i := 0; i < n; i++ {
			fmt.Scan(&w[i])
			w_c[w[i]]++
		}

		ans := 0
		for s := 2 * n; s > 0; s-- {
			w_c2 := w_c

			cnt := 0
			for i := 0; i < n; i++ {
				a := w[i]
				b := s - a

				if w_c2[a] <= 0 {
					continue
				}

				if a == b {
					if w_c2[a] >= 2 {
						cnt++
						w_c2[b] -= 2
					}
				} else if b > 0 && w_c2[b] > 0 {
					cnt++
					w_c2[a]--
					w_c2[b]--
				}
			}

			if cnt > ans {
				ans = cnt
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        w = make([]int, 0)
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            continue
        }
        if n == 2 {
            fmt.Println(1)
            continue
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 0
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

func solve() {
	n := nxt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nxt()
	}

	ans := 0
	for val := 1; val <= 2*n; val++ {

		used := make([]bool, n)
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if used[j] {
					continue
				}
				if a[i]+a[j] == val {
					used[j] = true
					break
				}
			}
		}
		var curAns int = 0
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

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

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

// only when n > 1
func match(dict []int, sorted []int) int {
	// Fetching the maximum possible weight of a team
	partNum := len(sorted)
	maxWeight := sorted[partNum-1] + sorted[partNum-2]

	var maxTeamNum = 0
	for teamWeight := maxWeight; teamWeight > 1; teamWeight-- {
		counter := 0
		var lighter int
		for heavier := len(dict); heavier > teamWeight/2; heavier-- {
			lighter = teamWeight - heavier
			if lighter < 1 {
				continue
			}
			counter += min(dict[heavier-1], dict[lighter-1])
		}
		if teamWeight&1 == 0 {
			counter += dict[(teamWeight/2)-1] / 2
		}
		if maxTeamNum < counter {
			maxTeamNum = counter
		}
	}
	return maxTeamNum
}

func solver(weights []int) int {
	if len(weights) < 2 {
		return 0
	}

	sorted := make([]int, len(weights))
	copy(sorted, weights)
	sort.Slice(sorted, func(i, j int) bool {
		return sorted[i] < sorted[j]
	})

	maxWeight := sorted[len(sorted)-1]
	inds := make([]int, maxWeight, maxWeight+1)
	dict := make([]int, maxWeight)
	for i := range inds {
		inds[i] = sort.SearchInts(sorted, i+1)
	}
	inds = append(inds, len(sorted))
	for i := range dict {
		dict[i] = inds[i+1] - inds[i]
	}
	return match(dict, sorted)
}

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

func main() {
	defer writer.Flush()
	var t int
	text, _ := reader.ReadString('\n')
	text = strings.TrimSpace(text)
	t, _ = strconv.Atoi(text)

	for i := 0; i < t; i++ {
		_, _ = reader.ReadString('\n')
		text, _ = reader.ReadString('\n')
		split := strings.Fields(text)
		arr := make([]int, len(split))
		for i, v := range split {
			arr[i], _ = strconv.Atoi(v)
		}
		fmt.Fprintln(writer, solver(arr))
	}
}

func test() {
	arr := []int{1, 1, 3, 4, 2, 2}
	fmt.Println(solver(arr))
}

package main

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

/*
5
5
1 2 3 4 5
8
6 6 6 6 6 6 8 8
8
1 2 2 1 2 1 1 2
3
1 3 3
6
1 1 3 4 2 2

2
3
4
1
2
*/

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

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		target := make(map[int]int)
		Fscan(in, &N)

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			target[S]++
		}
		sum := 0
		for i := 2 * N; i >= 2; i-- {
			var numOne, numTwo int
			var ok bool
			var tmp int
			for j := 1; j <= i/2; j++ {
				numOne, ok = target[j]
				if !ok {
					continue
				}

				numTwo, ok = target[i-j]
				if !ok {
					continue
				}

				if j == i-j {
					tmp += numOne / 2

				} else {
					tmp += Bmin(numOne, numTwo)
				}

			}

			sum = Bmax(sum, tmp)
		}

		Fprintln(out, sum)

	}
}

func Bmax(i, j int) int {
	if i < j {
		return j
	}
	return i
}

func Bmin(i, j int) int {
	if i < j {
		return i
	}
	return j
}

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

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

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

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

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

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

func sol(n int64, w []int64) int64 {
	sort.Slice(w, func(idx1, idx2 int) bool {
		return w[idx1] < w[idx2]
	})
	utw := map[int64]bool{}
	for i := range w {
		for j := i+1; j < len(w); j++ {
			utw[w[i] + w[j]] = true
		}
	}
	// printf("utw %v\n", utw)
	ret := int64(0)
	for i := range utw {
		curr := int64(0)
		l := int64(0)
		r := n-1
		for l < r {
			if w[l] + w[r] == i {
				curr++
				l++
				r--
				continue
			}
			if w[l] + w[r] < i {
				l++
				continue
			}
			if w[l] + w[r] > i {
				r--
				continue
			}
		}
		ret = max(ret, curr)
	}
	return ret
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, W []int) int {
	sort.Ints(W)

	var best int

	for i := 0; i < n; i++ {
		for j := n - 1; j > i; j-- {
			s := W[i] + W[j]
			cnt := 1
			if j-i+1 < 2*best {
				break
			}
			for a, b := 1, j-1; a < b; {
				if W[a]+W[b] == s {
					cnt++
					a++
					b--
				} else if W[a]+W[b] < s {
					a++
				} else {
					b--
				}
			}
			if cnt > best {
				best = cnt
			}
		}
	}

	return best
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, W []int) int {
	sort.Ints(W)

	var best int
	for j := n - 1; j > 0; j-- {
		s := W[0] + W[j]
		cnt := 1
		for a, b := 1, j-1; a < b; {
			if W[a]+W[b] == s {
				cnt++
				a++
				b--
			} else if W[a]+W[b] < s {
				a++
			} else {
				b--
			}
		}
		if cnt > best {
			best = cnt
		}
	}

	return best
}

package main

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

func main() {

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

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

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

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

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

		sort.Ints(a)

		result := 0
		if n > 1 {
			result = 1
		}

		l, r := 0, n-1

		for l+1 < r-1 {

			cnt := 1
			tmpL, tmpR := l, r
			for tmpL+1 < tmpR-1 {
				if a[tmpL]+a[tmpR] != a[tmpL+1]+a[tmpR-1] {
					break
				}
				tmpL, tmpR = tmpL+1, tmpR-1
				cnt++
			}

			result = max(result, cnt)

			if a[l]+a[r] >= a[l+1]+a[r-1] {
				r--
			} else {
				l++
			}

		}

		fmt.Fprintln(out, result)

	}

}

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

package main

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

func main() {

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

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

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

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

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

		sort.Ints(a)

		result := 0
		if n > 1 {
			result = 1
		}

		for s := 1; s < 2*n; s++ {
			cnt := 0
			l, r := 0, n-1
			for l < r {
				if a[l]+a[r] == s {
					l, r = l+1, r-1
					cnt++
				} else if a[l]+a[r] > s {
					r--
				} else {
					l++
				}
			}
			result = max(result, cnt)
		}

		fmt.Fprintln(out, result)

	}

}

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

package main

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

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

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

		for i := 0; i < n; i++ {
			a[input()]++
		}

		sort.Ints(a)

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(max)

	}
}

package main

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

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

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

		for i := 0; i < n; i++ {
			a[input()]++
		}

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(b)

		fmt.Println(max)

	}
}

package main

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

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

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

		for i := 0; i < n; i++ {
			a[input()]++
		}

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(b)
	}
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        w = make([]int, 0)
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            return
        }
        if n == 2 {
            fmt.Println(1)
            return
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 0
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            return
        }
        if n == 2 {
            fmt.Println(1)
            return
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 0
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            return
        }
        if n == 2 {
            fmt.Println(1)
            return
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 1
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

func solve() {
	n := nxt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nxt()
	}

	ans := 0
	for val := 1; val <= 100; val++ {
		used := make([]bool, n)
		var curAns int = 0
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val {
					used[j] = true
					break
				}
			}
		}
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

func solve() {
	n := nxt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nxt()
	}

	ans := 0
	s := 0
	for val := 1; val <= 50; val++ {
		used := make([]bool, n)
		var curAns int = 0
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			var t int = 0
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val {
					used[j] = true
					t = 1
					break
				}
			}
			curAns += t
		}
		if ans < curAns {
			ans = curAns
			s = val
		}
	}
	fmt.Println(s)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

func solve() {
	n := nxt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nxt()
	}

	ans := 0
	for val := 1; val <= 50; val++ {
		used := make([]bool, n)
		var curAns int = 0
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val {
					used[j] = true
					break
				}
			}
		}
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

func solve() {
	n := nxt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nxt()
	}

	ans := 0
	for val := 3; val <= 3; val++ {

		used := make([]bool, n)
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val && !used[j] {
					used[j] = true
					break
				}
			}
		}
		var curAns int = 0
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}


Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $$$n$$$ km. Let's say that Moscow is situated at the point with coordinate $$$0$$$ km, and Saratov — at coordinate $$$n$$$ km.Driving for a long time may be really difficult. Formally, if Leha has already covered $$$i$$$ kilometers since he stopped to have a rest, he considers the difficulty of covering $$$(i + 1)$$$-th kilometer as $$$a_{i + 1}$$$. It is guaranteed that for every $$$i \in [1, n - 1]$$$ $$$a_i \le a_{i + 1}$$$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $$$1$$$ to $$$n - 1$$$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $$$a_1$$$, the kilometer after it — difficulty $$$a_2$$$, and so on.For example, if $$$n = 5$$$ and there is a rest site in coordinate $$$2$$$, the difficulty of journey will be $$$2a_1 + 2a_2 + a_3$$$: the first kilometer will have difficulty $$$a_1$$$, the second one — $$$a_2$$$, then Leha will have a rest, and the third kilometer will have difficulty $$$a_1$$$, the fourth — $$$a_2$$$, and the last one — $$$a_3$$$. Another example: if $$$n = 7$$$ and there are rest sites in coordinates $$$1$$$ and $$$5$$$, the difficulty of Leha's journey is $$$3a_1 + 2a_2 + a_3 + a_4$$$.Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $$$2^{n - 1}$$$ different distributions of rest sites (two distributions are different if there exists some point $$$x$$$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $$$p$$$ — the expected value of difficulty of his journey.Obviously, $$$p \cdot 2^{n - 1}$$$ is an integer number. You have to calculate it modulo $$$998244353$$$.

The first line contains one number $$$n$$$ ($$$1 \le n \le 10^6$$$) — the distance from Moscow to Saratov. The second line contains $$$n$$$ integer numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$$$), where $$$a_i$$$ is the difficulty of $$$i$$$-th kilometer after Leha has rested.

Print one number — $$$p \cdot 2^{n - 1}$$$, taken modulo $$$998244353$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1009E(_r io.Reader, out io.Writer) {
	const mod = 998244353
	pow2 := [1e6]int64{1}
	for i := 1; i < 1e6; i++ {
		pow2[i] = pow2[i-1] << 1 % mod
	}
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	c := pow2[n-1] * a[0]
	s := int64(0)
	for i, v := range a {
		s += c
		if i+1 < n {
			c = (c + pow2[n-2-i]*(a[i+1]-v)) % mod
		}
	}
	Fprint(out, s%mod)
}

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


You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.Destroy all vertices in the given tree or determine that it is impossible.

The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.

If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.

NoteIn the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.

package main

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

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

	var n, w int
	Fscan(in, &n)
	if n&1 == 0 {
		Fprint(out, "NO")
		return
	}
	Fprintln(out, "YES")
	g := make([][]int, n+1)
	for v := 1; v <= n; v++ {
		if Fscan(in, &w); w > 0 {
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
	}
	size := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz := 1
		for _, w := range g[v] {
			if w != fa {
				sz += f(w, v)
			}
		}
		size[v] = sz
		return sz
	}
	f(1, 0)
	var f2 func(v, fa int)
	f2 = func(v, fa int) {
		for _, w := range g[v] {
			if w != fa && size[w]&1 == 0 {
				f2(w, v)
			}
		}
		Fprintln(out, v)
		for _, w := range g[v] {
			if w != fa && size[w]&1 > 0 {
				f2(w, v)
			}
		}
	}
	f2(1, 0)
}

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

package main

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

var n int
var graph [][]int
var s []int
var visited []int

func dfs1(v, p int) int {
	s[v] = 1
	for _, i := range graph[v] {
		if i != p {
			s[v] += dfs1(i, v)
		}
	}
	return s[v]
}

func dfs2(v, p int) {
	for _, i := range graph[v] {
		if i != p && s[i] % 2 == 0 {
			dfs2(i, v)
		}
	}
	fmt.Printf("%d\n", v)
	for _, i := range graph[v] {
		if i != p && s[i] % 2 == 1 {
			dfs2(i, v)
		}
	}
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	if n % 2 == 0 {
		fmt.Printf("NO\n")
		return
	}
	graph = make([][]int, n + 1)
	s = make([]int, n + 1)
	visited = make([]int, n + 1)
	fmt.Printf("YES\n")
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(stdin, "%d", &tmp)
		if tmp == 0 {
			continue
		}
		graph[i + 1] = append(graph[i + 1], tmp)
		graph[tmp] = append(graph[tmp], i + 1)
	}

	dfs1(1, 0)
	dfs2(1, 0)
}

package main

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

var n int
var graph [][]int
var deg []int
var visited []int

func dfs(v int) {
	for _, i := range graph[v] {
		if deg[i] % 2 == 0 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
	fmt.Printf("%d\n", v)
	for _, i := range graph[v] {
		if deg[i] % 2 == 1 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	if n % 2 == 0 {
		fmt.Printf("No\n")
		return
	}
	graph = make([][]int, n + 1)
	deg = make([]int, n + 1)
	visited = make([]int, n + 1)
	fmt.Printf("Yes\n")
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(stdin, "%d", &tmp)
		if tmp == 0 {
			continue
		}
		graph[i + 1] = append(graph[i + 1], tmp)
		graph[tmp] = append(graph[tmp], i + 1)
		deg[i + 1]++
		deg[tmp]++
	}
	root := 0
	for i := 1; i <= n; i++ {
		if deg[i] % 2 == 0 {
			root = i
		}
	}
	visited[root] = 1
	dfs(root)
}

package main

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

var n int
var graph [][]int
var deg []int
var visited []int

func dfs(v int) {
	for _, i := range graph[v] {
		if deg[i] % 2 == 0 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
	fmt.Printf("%d\n", v)
	for _, i := range graph[v] {
		if deg[i] % 2 == 1 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	if n % 2 == 0 {
		fmt.Printf("NO\n")
		return
	}
	graph = make([][]int, n + 1)
	deg = make([]int, n + 1)
	visited = make([]int, n + 1)
	fmt.Printf("YES\n")
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(stdin, "%d", &tmp)
		if tmp == 0 {
			continue
		}
		graph[i + 1] = append(graph[i + 1], tmp)
		graph[tmp] = append(graph[tmp], i + 1)
		deg[i + 1]++
		deg[tmp]++
	}
	root := 0
	for i := 1; i <= n; i++ {
		if deg[i] % 2 == 0 {
			root = i
		}
	}
	visited[root] = 1
	dfs(root)
}


Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.After the contest was over, Valera was interested in results. He found out that:  each student in the team scored at least l points and at most r points;  in total, all members of the team scored exactly sall points;  the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 ≥ a2 ≥ ... ≥ an), then sk = a1 + a2 + ... + ak. However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.

The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 ≤ n, k, l, r ≤ 1000; l ≤ r; k ≤ n; 1 ≤ sk ≤ sall ≤ 106). It's guaranteed that the input is such that the answer exists.

Print exactly n integers a1, a2, ..., an — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.

package main

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

func main(){
	var n int
	var k int
	var l, r int
	var sall, sk int
	re := bufio.NewScanner(os.Stdin)
	re.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	re.Scan()
	n, _ = strconv.Atoi(re.Text())
	re.Scan()
	k, _ = strconv.Atoi(re.Text())
	re.Scan()
	l, _ = strconv.Atoi(re.Text())
	re.Scan()
	r, _ = strconv.Atoi(re.Text())
	re.Scan()
	sall, _ = strconv.Atoi(re.Text())
	re.Scan()
	sk, _ = strconv.Atoi(re.Text())

	a := make([]int, n+1)
	l = l
	r = r
	sall -= sk
	for i:=k; i>0; i-- {
		a[i] = sk / i
		sk -= a[i]
	}
	for j:=n; j>k; j-- {
		a[j] = sall / (j-k)
		sall -= a[j]
	}
	for m:=1; m<=n; m++ {
		w.WriteString(strconv.Itoa(a[m])+" ")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main
import "fmt"

func main() {
	var i, n, k, l, r, sk, sall, x int
	var a[1001]int
	fmt.Scan(&n, &k, &l, &r, &sall, &sk)
	x=sall-sk
	for i:=0; i<k; i++ {
		a[i] = sk/k
	}
	i=0
	sk-=(sk/k)*k
	for sk=sk; sk>0; sk-- {
		a[i]++
		i++
	}
	if n-k>0 {
		for i=k; i<n; i++ {
			a[i]=x/(n-k)
		}
		i=k
		x-=(x/(n-k))*(n-k)
		for x=x; x>0; x-- {
			a[i]++
			i++
		}
	}
	for i:=0; i<n; i++ {
		fmt.Printf("%d ", a[i])
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
    var n,k,l,r,sall,sk int
    fmt.Scan(&n,&k,&l,&r,&sall,&sk)
    var a,cnt int
    if n != k {
        a = (sall-sk)/(n-k)
        cnt = (sall-sk)%(n-k)
    } else {
        a = 0
    }
    ak := sk/k
    cntk := sk%k
    s := sall-sk
    for i := 0; i < n; i++ {
        if i < k {
            if cntk > 0 {
                fmt.Print(ak+1)
                sk -= ak+1
                cntk--
            } else {
                fmt.Print(ak)
                sk -= ak
            }
        } else {
            if cnt > 0 {
                fmt.Print(a+1)
                s -= a+1
                cnt--
            } else {
                fmt.Print(a)
                s -= a
            }
        }
        if i == (n-1) { fmt.Println() } else { fmt.Print(" ") }
    }
}

// 369B
package main

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

func main() {
	var n, k, l, r, a, q, ek int
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	a -= q
	n -= k
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Fprintf(out, "%d ", ek)
		q -= ek
	}
	for i := 1; i <= n; i++ {
		ek = a / (n - i + 1)
		fmt.Fprintf(out, "%d ", ek)
		a -= ek
	}
	out.Flush()
}

// 369A-mic_rizal
package main

import (
    "fmt"
)

func main() {
    var n, k, l, r, x, y int
    fmt.Scan(&n, &k, &l, &r, &x, &y)
    x -= y
    n -= k
    for i := 1; i <= k; i++ {
        z := y / (k - i + 1)
        fmt.Print(z)
        fmt.Print(" ")
        y -= z
    }
    for i := 1; i <= n; i++ {

        z := x / (n - i + 1)
        fmt.Print(z)
        fmt.Print(" ")
        x -= z
    }
    fmt.Println()
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,k,l,r,sall,sk int
    fmt.Scan(&n,&k,&l,&r,&sall,&sk)
    a := int(math.Ceil(float64(sall-sk)/float64(n-k)))
    ak := sk/k
    s := sall-sk
    for i := 0; i < n; i++ {
        if i < k {
            if i != (k-1) {
                fmt.Print(ak)
                sk -= ak
            } else {
                fmt.Print(sk)
                sk = 0
            }
        } else {
            if s >= a {
                fmt.Print(a)
                s -= a
            } else {
                fmt.Print(s)
                s = 0
            }
        }
        if i == (n-1) { fmt.Println() } else { fmt.Print(" ") }
    }
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,k,l,r,sall,sk int
    fmt.Scan(&n,&k,&l,&r,&sall,&sk)
    a := int(math.Ceil(float64(sall-sk)/float64(n-k)))
    ak := sk/k
    cnt := sk%k
    s := sall-sk
    for i := 0; i < n; i++ {
        if i < k {
            if cnt > 0 {
                fmt.Print(ak+1)
                sk -= ak+1
            } else {
                fmt.Print(ak)
                sk -= ak
            }
        } else {
            if s >= a {
                fmt.Print(a)
                s -= a
            } else {
                fmt.Print(s)
                s = 0
            }
        }
        if i == (n-1) { fmt.Println() } else { fmt.Print(" ") }
    }
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,k,l,r,sall,sk int
    fmt.Scan(&n,&k,&l,&r,&sall,&sk)
    a := int(math.Ceil(float64(sall-sk)/float64(n-k)))
    s := sall-sk
    for i := 0; i < n; i++ {
        if i < k {
            fmt.Print(r)
        } else {
            if s >= a {
                fmt.Print(a)
                s -= a
            } else {
                fmt.Print(s)
                s = 0
            }
        }
        if i == (n-1) { fmt.Println() } else { fmt.Print(" ") }
    }
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,k,l,r,sall,sk int
    fmt.Scan(&n,&k,&l,&r,&sall,&sk)
    a := int(math.Ceil(float64(sall-sk)/float64(n-k)))
    ak := int(math.Ceil(float64(sk)/float64(k)))
    s := sall-sk
    for i := 0; i < n; i++ {
        if i < k {
            if sk >= ak {
                fmt.Print(ak)
                sk -= ak
            } else {
                fmt.Print(sk)
                sk = 0
            }
        } else {
            if s >= a {
                fmt.Print(a)
                s -= a
            } else {
                fmt.Print(s)
                s = 0
            }
        }
        if i == (n-1) { fmt.Println() } else { fmt.Print(" ") }
    }
}

// 369B
package main

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

func main() {
	var l, r, ek int
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Scan()
	n, _ := strconv.Atoi(in.Text())
	k, _ := strconv.Atoi(in.Text())
	fmt.Scan(&l, &r)
	a, _ := strconv.Atoi(in.Text())
	q, _ := strconv.Atoi(in.Text())
	a -= q
	n -= k
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Print(ek, ' ')
		q -= ek
	}
	for i := 1; i <= n; i++ {
		ek = a / (n - i + 1)
		fmt.Print(ek, ' ')
		a -= ek
	}
	return
}

// 369B
package main

import (
	"fmt"
)

func main() {
	var n, k, l, r, a, q, ek int
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	a -= q
	n -= k
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Print(ek, ' ')
		q -= ek
	}
	for i := 1; i <= n; i++ {
		ek = a / (n - i + 1)
		fmt.Print(ek, ' ')
		a -= ek
	}
	return
}

// 369B
package main

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

func main() {
	var l, r, ek int
	in := bufio.NewScanner(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	in.Split(bufio.ScanWords)
	in.Scan()
	n, _ := strconv.Atoi(in.Text())
	k, _ := strconv.Atoi(in.Text())
	fmt.Scan(&l, &r)
	a, _ := strconv.Atoi(in.Text())
	q, _ := strconv.Atoi(in.Text())
	a -= q
	n -= k
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Fprint(out, ek)
		fmt.Print(" ")
		q -= ek
	}
	for i := 1; i <= n; i++ {
		ek = a / (n - i + 1)
		fmt.Fprint(out, ek)
		fmt.Print(" ")
		a -= ek
	}
	out.Flush()
}

// 369B
package main

import (
	"fmt"
)

func main() {
	n, k, l, r, a, q, ek := 0, 0, 0, 0, 0, 0, 0
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	for i := 0; i < k; i++ {
		ek = q / k
		if q%k == 0 {
			ek++
		}
		q -= ek
		a -= ek
		n--
		k--
		fmt.Print(ek, " ")
	}
	for i := 0; i < n; i++ {
		ek = a / n
		if a%n == 0 {
			ek++
		}
		a -= ek
		n--
		fmt.Print(ek, " ")
	}
}

// 369B
package main

import (
	"fmt"
)

func main() {
	var n, k, l, r, a, q, ek int
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	for i := 0; i < k; i++ {
		ek = q / k
		if q%k == 0 {
			ek++
		}
		q -= ek
		a -= ek
		n--
		k--
		fmt.Print(ek, ' ')
	}
	for i := 0; i < n; i++ {
		ek = a / n
		if a%n == 0 {
			ek++
		}
		a -= ek
		n--
		fmt.Print(ek, ' ')
	}
}

// 369B
package main

import (
	"fmt"
)

func main() {
	var n, k, l, r, a, q, ek int
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Print(ek, ' ')
		q -= ek
	}
	for i := 0; i < n; i++ {
		ek = a / (n - i + 1)
		fmt.Print(ek, ' ')
		a -= ek
	}
	return
}

// 369B
package main

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

func main() {
	var n, k, l, r, a, q, ek int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)
	fmt.Fscan(in, &l)
	fmt.Fscan(in, &r)
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &q)
	for i := 0; i < k; i++ {
		ek = q / (k - i)
		q -= ek
		a -= ek
		fmt.Print(ek, ' ')
	}
	for i := k; i < n; i++ {
		ek = a / (n - i)
		a -= ek
		fmt.Print(ek, ' ')
	}
}

// 369B
package main

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

func main() {
	var ek int
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Scan()
	n, _ := strconv.Atoi(in.Text())
	k, _ := strconv.Atoi(in.Text())
	a, _ := strconv.Atoi(in.Text())
	q, _ := strconv.Atoi(in.Text())
	a -= q
	n -= k
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Print(ek, ' ')
		q -= ek
	}
	for i := 1; i <= n; i++ {
		ek = a / (n - i + 1)
		fmt.Print(ek, ' ')
		a -= ek
	}
	return
}

// 369B
package main

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

func main() {
	var n, k, l, r, a, q, ek int
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	a -= q
	n -= k
	for i := 1; i <= k; i++ {
		ek = q / (k - i + 1)
		fmt.Fprint(out, ek)
		fmt.Print(" ")
		q -= ek
	}
	for i := 1; i <= n; i++ {
		ek = a / (n - i + 1)
		fmt.Fprint(out, ek)
		fmt.Print(" ")
		a -= ek
	}
	out.Flush()
}

// 369B
package main

import (
	"fmt"
)

func main() {
	var n, k, l, r, a, q, ek int
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	for i := 0; i < k; i++ {
		ek = q / (k - i)
		q -= ek
		a -= ek
		fmt.Print(ek, ' ')
	}
	for i := k; i < n; i++ {
		ek = a / (n - i)
		a -= ek
		fmt.Print(ek, ' ')
	}
}

// 369B
package main

import (
	"fmt"
)

func main() {
	n, k, l, r, a, q, ek := 0, 0, 0, 0, 0, 0, 0
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	for i := 0; i < k; i++ {
		ek = q / k
		if q%k == 0 {
			ek++
		}
		q -= ek
		a -= ek
		n--
		k--
		fmt.Print(ek, ' ')
	}
	for i := 0; i < n; i++ {
		ek = a / n
		if a%n == 0 {
			ek++
		}
		a -= ek
		n--
		fmt.Print(ek, ' ')
	}
}

// 369B
package main

import (
	"fmt"
)

func main() {
	var n, k, l, r, a, q, ek int
	fmt.Scan(&n, &k, &l, &r, &a, &q)
	for i := 0; i < k; i++ {
		ek = q / (k - i)
		q -= ek
		a -= ek
		fmt.Print(ek, ' ')
	}
	for i := 0; i < n; i++ {
		ek = a / (n - i)
		a -= ek
		fmt.Print(ek, ' ')
	}
}


Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be possible to reach a police station by traveling at most d kilometers along the roads.  There are n cities in the country, numbered from 1 to n, connected only by exactly n - 1 roads. All roads are 1 kilometer long. It is initially possible to travel from a city to any other city using these roads. The country also has k police stations located in some cities. In particular, the city's structure satisfies the requirement enforced by the previously mentioned law. Also note that there can be multiple police stations in one city.However, Zane feels like having as many as n - 1 roads is unnecessary. The country is having financial issues, so it wants to minimize the road maintenance cost by shutting down as many roads as possible.Help Zane find the maximum number of roads that can be shut down without breaking the law. Also, help him determine such roads.

The first line contains three integers n, k, and d (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105, 0 ≤ d ≤ n - 1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively. The second line contains k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — each denoting the city each police station is located in. The i-th of the following n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities directly connected by the road with index i. It is guaranteed that it is possible to travel from one city to any other city using only the roads. Also, it is possible from any city to reach a police station within d kilometers.

In the first line, print one integer s that denotes the maximum number of roads that can be shut down. In the second line, print s distinct integers, the indices of such roads, in any order. If there are multiple answers, print any of them.

NoteIn the first sample, if you shut down road 5, all cities can still reach a police station within k = 4 kilometers.In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line.

package main

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

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

	var n, k, d, v, w int
	Fscan(in, &n, &k, &d)
	type pair struct{ v, fa int }
	q := []pair{}
	vis := make([]bool, n+1)
	for ; k > 0; k-- {
		Fscan(in, &v)
		if !vis[v] {
			vis[v] = true
			q = append(q, pair{v, 0})
		}
	}
	type nb struct{ to, i int }
	g := make([][]nb, n+1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		g[v] = append(g[v], nb{w, i})
		g[w] = append(g[w], nb{v, i})
	}

	ans := []interface{}{}
	inAns := make([]bool, n)
	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		for _, e := range g[p.v] {
			if w := e.to; w != p.fa {
				if vis[w] {
					if !inAns[e.i] {
						ans = append(ans, e.i)
						inAns[e.i] = true
					}
				} else {
					vis[w] = true
					q = append(q, pair{w, p.v})
				}
			}
		}
	}
	Fprintln(out, len(ans))
	Fprintln(out, ans...)
}

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


Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $$$(0, 0)$$$ on an infinite grid.You also have the sequence of instructions of this robot. It is written as the string $$$s$$$ consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell $$$(x, y)$$$ right now, he can move to one of the adjacent cells (depending on the current instruction).  If the current instruction is 'L', then the robot can move to the left to $$$(x - 1, y)$$$;  if the current instruction is 'R', then the robot can move to the right to $$$(x + 1, y)$$$;  if the current instruction is 'U', then the robot can move to the top to $$$(x, y + 1)$$$;  if the current instruction is 'D', then the robot can move to the bottom to $$$(x, y - 1)$$$. You've noticed the warning on the last page of the manual: if the robot visits some cell (except $$$(0, 0)$$$) twice then it breaks.So the sequence of instructions is valid if the robot starts in the cell $$$(0, 0)$$$, performs the given instructions, visits no cell other than $$$(0, 0)$$$ two or more times and ends the path in the cell $$$(0, 0)$$$. Also cell $$$(0, 0)$$$ should be visited at most two times: at the beginning and at the end (if the path is empty then it is visited only once). For example, the following sequences of instructions are considered valid: "UD", "RL", "UUURULLDDDDLDDRRUU", and the following are considered invalid: "U" (the endpoint is not $$$(0, 0)$$$) and "UUDD" (the cell $$$(0, 1)$$$ is visited twice).The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move. Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain.Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric).You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^4$$$) — the number of test cases. The next $$$q$$$ lines contain test cases. The $$$i$$$-th test case is given as the string $$$s$$$ consisting of at least $$$1$$$ and no more than $$$10^5$$$ characters 'L', 'R', 'U' and 'D' — the initial sequence of instructions. It is guaranteed that the sum of $$$|s|$$$ (where $$$|s|$$$ is the length of $$$s$$$) does not exceed $$$10^5$$$ over all test cases ($$$\sum |s| \le 10^5$$$).

For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions $$$t$$$ the robot has to perform. The moves are performed from left to right in the order of the printed sequence. If there are several answers, you can print any. If the answer is $$$0$$$, you are allowed to print an empty line (but you can don't print it).

6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL

2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0

NoteThere are only two possible answers in the first test case: "LR" and "RL".The picture corresponding to the second test case:  Note that the direction of traverse does not matter Another correct answer to the third test case: "URDDLLLUURDR".

package main

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

var str string

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

func main() {
	var n int
	input := bufio.NewReader(os.Stdin)
	//output := bufio.NewWriter(os.Stdout)
	_, _ = fmt.Fscan(input, &n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscan(input, &str)
		countLeft := 0
		countRight := 0
		countUp := 0
		countDown := 0
		for _, ch := range str {
			switch ch {
			case 'U':
				countUp++
			case 'D':
				countDown++
			case 'L':
				countLeft++
			case 'R':
				countRight++
			}
		}
		countX := min(countLeft, countRight)
		countY := min(countUp, countDown)
		if countX == 0 && countY == 0 {
			_, _ = fmt.Fprintln(os.Stdout, 0)
		} else if countX == 0 {
			_, _ = fmt.Fprintln(os.Stdout, 2)
			_, _ = fmt.Fprintf(os.Stdout, "UD\n")
		} else if countY == 0 {
			_, _ = fmt.Fprintln(os.Stdout, 2)
			_, _ = fmt.Fprintf(os.Stdout, "LR\n")
		} else {
			_, _ = fmt.Fprintln(os.Stdout, (countX+countY)<<1)
			for i := 0; i < countX; i++ {
				_, _ = fmt.Fprintf(os.Stdout, "%c", 'L')
			}
			for i := 0; i < countY; i++ {
				_, _ = fmt.Fprintf(os.Stdout, "%c", 'U')
			}
			for i := 0; i < countX; i++ {
				_, _ = fmt.Fprintf(os.Stdout, "%c", 'R')
			}
			for i := 0; i < countY; i++ {
				_, _ = fmt.Fprintf(os.Stdout, "%c", 'D')
			}
			_, _ = fmt.Fprintln(os.Stdout)
		}
	}
}

package main

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

var str string

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

func main() {
	var n int
	input := bufio.NewReader(os.Stdin)
	output := bufio.NewWriter(os.Stdout)
	_, _ = fmt.Fscan(input, &n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscan(input, &str)
		countLeft := 0
		countRight := 0
		countUp := 0
		countDown := 0
		for _, ch := range str {
			switch ch {
			case 'U':
				countUp++
			case 'D':
				countDown++
			case 'L':
				countLeft++
			case 'R':
				countRight++
			}
		}
		countX := min(countLeft, countRight)
		countY := min(countUp, countDown)
		if countX == 0 && countY == 0 {
			_, _ = fmt.Fprintln(output, 0)
		} else if countX == 0 {
			_, _ = fmt.Fprintln(output, 2)
			_, _ = fmt.Fprintf(output, "UD\n")
		} else if countY == 0 {
			_, _ = fmt.Fprintln(output, 2)
			_, _ = fmt.Fprintf(output, "LR\n")
		} else {
			_, _ = fmt.Fprintln(output, (countX+countY)<<1)
			for i := 0; i < countX; i++ {
				_, _ = fmt.Fprintf(output, "%c", 'L')
			}
			for i := 0; i < countY; i++ {
				_, _ = fmt.Fprintf(output, "%c", 'U')
			}
			for i := 0; i < countX; i++ {
				_, _ = fmt.Fprintf(output, "%c", 'R')
			}
			for i := 0; i < countY; i++ {
				_, _ = fmt.Fprintf(output, "%c", 'D')
			}
			_, _ = fmt.Fprintln(output)
		}
	}
	_ = output.Flush()
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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)
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int
var S []rune

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	memo := make(map[rune]int)
	memo['L'], memo['R'], memo['U'], memo['D'] = 0, 0, 0, 0

	for _, r := range S {
		memo[r]++
	}

	// 消した数
	// num := 0
	// num += AbsInt(memo['R'] - memo['L'])
	// num += AbsInt(memo['U'] - memo['D'])

	lrTime := Min(memo['R'], memo['L'])
	udTime := Min(memo['U'], memo['D'])

	if lrTime == 0 && udTime == 0 {
		fmt.Println(0)
		fmt.Println("")
		return
	}

	if lrTime == 0 {
		// UDを1回ずつ
		fmt.Println(2)
		fmt.Println("UD")
		return
	}

	if udTime == 0 {
		// LRを1回ずつ
		fmt.Println(2)
		fmt.Println("LR")
		return
	}

	fmt.Println(lrTime*2 + udTime*2)
	answers := []rune{}
	for i := 0; i < lrTime; i++ {
		answers = append(answers, 'R')
	}
	for i := 0; i < udTime; i++ {
		answers = append(answers, 'D')
	}
	for i := 0; i < lrTime; i++ {
		answers = append(answers, 'L')
	}
	for i := 0; i < udTime; i++ {
		answers = append(answers, 'U')
	}
	fmt.Println(string(answers))
}

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

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

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

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

package main

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

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

func getPath(vertical int, horizontal int) string {
	if vertical == 0 && horizontal == 0 {
		return ""
	} else if vertical == 0 {
		return "LR"
	} else if horizontal == 0 {
		return "UD"
	}
	return strings.Repeat("U", vertical) +
		strings.Repeat("L", horizontal) +
		strings.Repeat("D", vertical) +
		strings.Repeat("R", horizontal)
}

func Solve(s string) string {
	m := make(map[string]int)
	for _, elem := range s {
		si := string(elem)
		m[si] += 1
	}
	return getPath(min(m["U"], m["D"]), min(m["L"], m["R"]))
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var s string
		fmt.Fscanf(reader, "%s\n", &s)
		path := Solve(s)
		fmt.Fprintf(writer, "%d\n", len(path))
		fmt.Fprintf(writer, "%s\n", path)
	}
}


One day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:  Find the number that goes k-th in the current sequence and add the same number to the end of the sequence;  Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 105). The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 105) — the sequence that the shooshuns found.

Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.

NoteIn the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.

package main

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

func main() {
	var i,n,k,flag int64
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n,&k)
	a:=make([]int64,1000000)
	for i=1;i<=n;i++ {
		input.Scan()
		aa, _ := strconv.Atoi(input.Text())
		a[i]=int64(aa)
	}
	for flag=n;flag>1;flag-- {
		if a[flag]!=a[flag-1] {
			break
		}
	}
	if flag>k {
		fmt.Println("-1")
	} else {
		fmt.Println(flag-1)
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,k int
    fmt.Scan(&n,&k)
    a := make([]int,n+1)
    ok := true
    for i := 1; i <= n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        if (i > k) && (a[i] != a[k]) {
            ok = false
        }
    }
    if ok {
        ans := k
        for a[ans-1] == a[k] { ans-- }
        fmt.Println(ans-1)
    } else {
        fmt.Println(-1)
    }
}

package main

import (

    "fmt"

    "bufio"

    "os"

    "strconv"

)

func main() {

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Split(bufio.ScanWords)

    var n,k int

    fmt.Scan(&n,&k)

    a := make([]int,n+1)

    ok := true
    for i := 1; i <= n; i++ {

        scanner.Scan()

        a[i], _ = strconv.Atoi(scanner.Text())

        if (i > k) && (a[i] != a[k]) {

            ok = false

        }

    }

    if ok {

        ans := k

        for a[ans-1] == a[k] {
            ans--
        }

        fmt.Println(ans-1)

    }else {
    fmt.Println(-1)
}
}