Given an array $$$a$$$ of positive integers with length $$$n$$$, determine if there exist three distinct indices $$$i$$$, $$$j$$$, $$$k$$$ such that $$$a_i + a_j + a_k$$$ ends in the digit $$$3$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. Output "YES" if there exist three distinct indices $$$i$$$, $$$j$$$, $$$k$$$ satisfying the constraints in the statement, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, you can select $$$i=1$$$, $$$j=4$$$, $$$k=3$$$. Then $$$a_1 + a_4 + a_3 = 20 + 84 + 19 = 123$$$, which ends in the digit $$$3$$$.In the second test case, you can select $$$i=1$$$, $$$j=2$$$, $$$k=3$$$. Then $$$a_1 + a_2 + a_3 = 1 + 11 + 1 = 13$$$, which ends in the digit $$$3$$$.In the third test case, it can be proven that no such $$$i$$$, $$$j$$$, $$$k$$$ exist. Note that $$$i=4$$$, $$$j=4$$$, $$$k=4$$$ is not a valid solution, since although $$$a_4 + a_4 + a_4 = 1111 + 1111 + 1111 = 3333$$$, which ends in the digit $$$3$$$, the indices need to be distinct.In the fourth test case, it can be proven that no such $$$i$$$, $$$j$$$, $$$k$$$ exist.In the fifth test case, you can select $$$i=4$$$, $$$j=3$$$, $$$k=1$$$. Then $$$a_4 + a_3 + a_1 = 4 + 8 + 1 = 13$$$, which ends in the digit $$$3$$$.In the sixth test case, you can select $$$i=1$$$, $$$j=2$$$, $$$k=6$$$. Then $$$a_1 + a_2 + a_6 = 16 + 38 + 99 = 153$$$, which ends in the digit $$$3$$$.

package main

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

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

// 10 + 3
// 9 + 4
// 8 + 5
// 7 + 6
// 3 13 23
// 3: 1 + 1 + 1; 0 + 1 + 2; 0 + 0 + 3;

// 13: 0 + 4 + 9; 0 + 5 + 8; 0 + 6 + 7; 1 + 3 + 9; 2 + 2 + 9; 2 + 3 + 8; 2 + 4 + 7; 2 + 5 + 6;

// 23: 7 + 7 + 9; 6 + 8 + 9; 5 + 9 + 9;

func solve() string {
	var n int
	fmt.Fscan(in, &n)
	var v [10]int
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &tmp)
		if v[tmp%10] < 3 {
			v[tmp%10]++
		}
	}

	var nums = make([]int, 0, 300)
	for i, j := range v {
		for k := 0; k < j; k++ {
			nums = append(nums, i)
		}
	}

	length := len(nums)
	for i := 0; i < length; i++ {
		for j := i + 1; j < length; j++ {
			for k := j + 1; k < length; k++ {
				if (nums[i]+nums[j]+nums[k])%10 == 3 {
					return "YES"
				}
			}
		}
	}
	return "NO"
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

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

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

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

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

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)
	cnt := make([]int, 10)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		nums[i] %= 10
		cnt[nums[i]]++
	}
	for i := range cnt {
		if cnt[i] > 0 {
			cnt[i]--
		} else {
			continue
		}
		for j := range cnt {
			if cnt[j] > 0 {
				cnt[j]--
			} else {
				continue
			}
			for k := range cnt {
				if cnt[k] > 0 {
					cnt[k]--
					if (i+j+k)%10 == 3 {
						fmt.Fprintln(w, "YES")
						return
					}
					cnt[k]++
				}
			}
			cnt[j]++
		}
		cnt[i]++
	}
	fmt.Fprintln(w, "NO")
}

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

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)

		m := make([]int, 10)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			m[v%10]++
		}

		var f bool
	Loop:
		for i := 0; i < 10; i++ {
			for j := i; j < 10; j++ {
				for k := j; k < 10; k++ {
					if (i+j+k)%10 == 3 {
						m[i]--
						m[j]--
						m[k]--
						if m[i] >= 0 && m[j] >= 0 && m[k] >= 0 {
							f = true
							break Loop
						}
						m[i]++
						m[j]++
						m[k]++
					}
				}
			}
		}

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

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)

		m := make([]int, 10)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			m[v%10]++
		}

		var f bool
	Loop:
		for i := 0; i < 10; i++ {
			if m[i] == 0 {
				continue
			}
			tot := i
			m[i]--
			for j := 0; j < 10; j++ {
				if m[j] == 0 {
					continue
				}
				m[j]--
				tot += j
				if tot <= 3 && m[3-tot] > 0 {
					f = true
					break Loop
				} else if tot > 3 && tot <= 13 && m[13-tot] > 0 {
					f = true
					break Loop
				} else if tot > 13 && m[23-tot] > 0 {
					f = true
					break Loop
				}
				tot -= j
				m[j]++
			}
			m[i]++
		}

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

package main

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

func reader() io.Reader {
	input, err := os.Open("./input.txt")
	if err != nil {
		log.Fatal(err)
	}
	// defer input.Close()
	return input
}

func reader2() *bufio.Reader {
	return bufio.NewReader(os.Stdin)
}

func writer() io.Writer {
	output, err := os.Create("./output.txt")
	if err != nil {
		log.Fatal(err)
	}
	// defer output.Close()
	return output
}

func writer2() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

var t, n, a int
var check bool
var r = reader2()
var w = writer2()

func main() {
	if reflect.TypeOf(w).String() == "*bufio.Writer" {
		defer w.Flush()
	}
	for fmt.Fscan(r, &t); t > 0; t-- {
		check = false
		A := []int{}
		M := [10]int{}
		for fmt.Fscan(r, &n); n > 0; n-- {
			fmt.Fscan(r, &a)
			M[a%10]++
			if M[a%10] <= 3 {
				A = append(A, a%10)
			}
		}
		for i, v1 := range A {
			for j, v2 := range A[:i] {
				for _, v3 := range A[:j] {
					if (v1+v2+v3)%10 == 3 {
						check = true
					}
				}
			}
		}
		if check {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}

}

package main

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

// 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()

	var T, n, v int
o:
	for Fscan(in, &T); T > 0; T-- {
		a := []int{}
		c := [10]int{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			v %= 10
			if c[v] < 3 {
				c[v]++
				a = append(a, v)
			}
		}
		for i, x := range a {
			for j, y := range a[:i] {
				for _, z := range a[:j] {
					if (x+y+z)%10 == 3 {
						Fprintln(out, "YES")
						continue o
					}
				}
			}
		}
		Fprintln(out, "NO")
	}
}

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) bool {
		var n int
		Fscan(in, &n)
		// int64
		cnt := [10]int{}
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		for _, v := range a {
			cnt[v%10]++
		}
		for i := 0; i < 10; i++ {
			if cnt[i] == 0 {
				continue
			}
			for j := 0; j < 10; j++ {
				if cnt[j] == 0 {
					continue
				}
				for k := 0; k < 10; k++ {
					if cnt[k] == 0 || (i+j+k)%10!=3 {
						continue
					}
					c := [10]int{}
					c[i]++
					c[j]++
					c[k]++
					if c[i]<=cnt[i] && c[j]<=cnt[j] &&c[k]<=cnt[k] {
						return true
					}
				}
			}
		}
		return false
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		if solve(curCase) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

	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"
	"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
	var n int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n)
		var a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(a)
		fmt.Fprintln(w, w1)
	}
}

func do(a []int) string {
	m := [10]int{}
	c := [10]int{}
	for _, v := range a {
		m[v%10]++
	}
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			for k := 0; k < 10; k++ {
				c[i]++
				c[j]++
				c[k]++
				if m[i] >= c[i] && m[j] >= c[j] && m[k] >= c[k] && (i+j+k)%10 == 3 {
					return "YES"
				}
				c[i]--
				c[j]--
				c[k]--
			}
		}
	}
	return "NO"
}

package main

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

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

func solve(n int) {

	var (
		a = make([]int, 10)
		b []int
		ok = false
	)
	for i := 0; i < n; i++ {

		var x int
		fmt.Fscan(in, &x)
		x %= 10
		a[x] += 1
		if a[1] > 2 {

			ok = true
		}
		if a[x] <= 2 {

			b = append(b, x)
		}
	}
	for i := 0; i < len(b); i++ {

		for j := i + 1; j < len(b); j++ {

			for k := j + 1; k < len(b); k++ {

				val := b[i] + b[j] + b[k]
				if val % 10 == 3 {

					fmt.Fprintln(out, "YES")
					return
				}
			}
		}
	}
	if ok {

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

		fmt.Fprintln(out, "NO")
	}
}
func main() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)

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

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

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

	var input string
	var strList []string
	if scanner.Scan() {
		input = scanner.Text()
	}

	t, _ := strconv.Atoi(input)

	for test := 0; test < t; test++ {
		if scanner.Scan() {
			input = scanner.Text()
		}

		n, _ := strconv.Atoi(input)

		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		countList := []int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for i := 0; i < n; i++ {
			a, _ := strconv.Atoi(strList[i])
			countList[a%10]++
		}

		var nums []int
		for i, count := range countList {
			for j := 0; j < count; j++ {
				nums = append(nums, i)
				if j == 3 {
					break
				}
			}
		}

		size := len(nums)

		flag := false
		for i := 0; i < size; i++ {
			for j := i + 1; j < size; j++ {
				for k := j + 1; k < size; k++ {
					if (nums[i]+nums[j]+nums[k])%10 == 3 {
						flag = true
						break
					}
				}
			}
		}

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

package main

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

var in = bufio.NewReader(os.Stdin)

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

func readLine() []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	values := strings.Split(line, " ")
	return values
}

func readArrInt() []int {
	line := readLine()
	res := make([]int, 0, 0)
	for i := range line {
		var x, _ = strconv.Atoi(line[i])
		res = append(res, x)
	}
	return res
}

func main() {
	test := readInt()
	for ; 0 < test; test-- {
		var _ = readInt()
		var a = readArrInt()
		var cnt = [10]int{}
		for i := range a {
			cnt[a[i]%10]++
		}
		var found = false
		for i := range cnt {
			for j := range cnt {
				for k := range cnt {
					cnt[i]--
					cnt[j]--
					cnt[k]--
					if 0 <= cnt[i] && 0 <= cnt[j] && 0 <= cnt[k] && (i + j + k) % 10 == 3 {
						found = true
					}
					cnt[i]++
					cnt[j]++
					cnt[k]++
				}
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		cnt := make([]int, 10)
		n := readInt(in)
		arr := readArrInt(in)
		for i := 0; i < n; i++ {
			cnt[arr[i]%10]++
		}
		if solve(cnt) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(cnt []int) bool {
	for i := range cnt {
		if cnt[i] == 0 {
			continue
		} else {
			cnt[i]--
		}
		for j := range cnt {
			if cnt[j] == 0 {
				continue
			} else {
				cnt[j]--
			}
			for k := range cnt {
				if cnt[k] == 0 {
					continue
				} else {
					cnt[k]--
				}
				if (i+j+k)%10 == 3 {
					return true
				}
				cnt[k]++
			}
			cnt[j]++
		}
		cnt[i]++
	}
	return false
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

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

		lastDigits := make([]int, 0)
		mp := make(map[int]int)

		var num int
		for i := 0; i < n; i++ {
			Fscan(in, &num)
			ld := num % 10
			if mp[ld] < 3 {
				mp[ld]++
				lastDigits = append(lastDigits, ld)
			}
		}
		found := false
		for i := 0; i < len(lastDigits); i++ {
			for j := i + 1; j < len(lastDigits); j++ {
				for k := j + 1; k < len(lastDigits); k++ {
					if (lastDigits[i]+lastDigits[j]+lastDigits[k])%10 == 3 {
						found = true
					}
				}
			}
		}

		if found {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}

	}
}

package main

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

/*
1
8
2 4 2 1 6 5 5 3
---
YES 6+5+2
*/

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

	a := make([]int, n)

	numToCnt := make(map[int]int)

	for i := range a {
		scanf("%d", &a[i])
		a[i] %= 10

		numToCnt[a[i]]++
	}
	scanf("\n")

	nums := make([]int, 0)

	for num, _ := range numToCnt {
		nums = append(nums, num)
	}

	for i := 0; i < len(nums); i++ {
		for j := 0; j < len(nums); j++ {
			if i == j && numToCnt[nums[j]] < 2 {
				continue
			}

			for k := 0; k < len(nums); k++ {
				if i == k && numToCnt[nums[k]] < 2 {
					continue
				}

				if j == k && numToCnt[nums[k]] < 2 {
					continue
				}

				if i == j && j == k && numToCnt[nums[k]] < 3 {
					continue
				}

				if (nums[i]+nums[j]+nums[k])%10 == 3 {
					fmt.Fprintln(writer, "YES")
					return
				}
			}
		}
	}

	fmt.Fprintln(writer, "NO")
}

//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"
	"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() bool {
	n := ri()
	c := make([]int, 10)
	for i := 0; i < n; i++ {
		j := ri() % 10
		c[j] += 1
	}
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			for k := 0; k < 10; k++ {
				if (i+j+k)%10 == 3 {
					// check count
					c1 := make([]int, 10)
					c1[i] += 1
					c1[j] += 1
					c1[k] += 1
					// myio.Println(i, j, k, c1[i], c1[j], c1[k], c[i], c[j], c[k])
					if c1[i] <= c[i] && c1[j] <= c[j] && c1[k] <= c[k] {
						return true
					}
				}
			}
		}
	}
	return false
}

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-- {
		if sol() {
			myio.Println("YES")
		} else {
			myio.Println("NO")
		}
	}
}

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)
	a := make([]int,n)
	cnt  := make(map[int]int)
	for i := 0; i < n; i++ {
		var c int
		fmt.Fscan(r,&c)
		c %= 10
		if cnt[c] < 3 {
			a = append(a,c)
			cnt[c]++
		}
	}
	n = len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if(a[i]+a[j]+a[k]) % 10 == 3 {
					fmt.Fprintln(w,"YES")
					return
				}
			}
		}
	}
	fmt.Fprintln(w,"NO")
}
func main() {
	defer w.Flush()
	var T int
	fmt.Fscan(r,&T)
	for i := 0; i < T; i++ {
		slove()
	}
}

package main

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

func slove() {
	var n int
	fmt.Fscan(r, &n)
	a := make([]int,n)
	cnt  := make(map[int]int)
	for i := 0; i < n; i++ {
		var c int
		fmt.Fscan(r,&c)
		c %= 10
		if cnt[c] <= 3 {
			a = append(a,c)
		}
	}
	n = len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if(a[i]+a[j]+a[k]) % 10 == 3 {
					fmt.Fprintln(w,"YES")
					return
				}
			}
		}
	}
	fmt.Fprintln(w,"NO")
}
func main() {
	defer w.Flush()
	var T int
	fmt.Fscan(r,&T)
	for i := 0; i < T; i++ {
		slove()
	}
}

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)

		m := make([]int, 10)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			m[v%10]++
		}

		var f bool
	Loop:
		for i := 0; i < 10; i++ {
			if m[i] == 0 {
				continue
			}
			tot := i
			for j := 0; j < 10; j++ {
				if m[j] == 0 {
					continue
				}
				m[j]--
				tot += j
				if tot <= 3 && m[3-tot] > 0 {
					f = true
					break Loop
				} else if tot > 3 && tot <= 13 && m[13-tot] > 0 {
					f = true
					break Loop
				} else if tot > 13 && m[23-tot] > 0 {
					f = true
					break Loop
				}
				tot -= j
				m[j]++
			}
			m[i]++
		}

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

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
	var n int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n)
		var a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(a)
		fmt.Fprintln(w, w1)
	}
}

func init() {
	for _, v := range []int{3, 13, 23} {
		for i := 0; i <= 9; i++ {
			for j := 0; j <= 9; j++ {
				for k := 0; k <= 9; k++ {
					if i+j+k == v {

					}
				}
			}
		}
	}
}

func do(a []int) string {
	m := [10]int{}
	for _, v := range a {
		m[v%10]++
	}
	for i := 0; i < 10; i++ {
		for j := i + 1; j < 10; j++ {
			for k := j + 1; k < 10; k++ {
				if m[i] > 0 && m[j] > 0 && m[k] > 0 && (i+j+k)%10 == 3 {
					return "YES"
				}
			}
		}
	}
	for i := 0; i < 10; i++ {
		for j := i + 1; j < 10; j++ {
			if m[i] > 1 && m[j] > 0 && (i+i+j)%10 == 3 {
				return "YES"
			}
		}
	}
	for i := 0; i < 10; i++ {
		if m[i] > 2 && (i+i+i)%10 == 3 {
			return "YES"
		}
	}
	return "NO"
}


We just discovered a new data structure in our research group: a suffix three!It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.Let us tell you how it works.  If a sentence ends with "po" the language is Filipino.  If a sentence ends with "desu" or "masu" the language is Japanese.  If a sentence ends with "mnida" the language is Korean. Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.Oh, did I say three suffixes? I meant four.

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 30$$$) denoting the number of test cases. The next lines contain descriptions of the test cases.  Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least $$$1$$$ and at most $$$1000$$$ characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.

NoteThe first sentence ends with "po", so it is written in Filipino.The second and third sentences end with "desu" and "masu", so they are written in Japanese.The fourth sentence ends with "mnida", so it is written in Korean.

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := scanner.Text()
		if s[len(s)-1] == 'o' {
			fmt.Println("FILIPINO")
		} else if s[len(s)-1] == 'a' {
			fmt.Println("KOREAN")
		} else {
			fmt.Println("JAPANESE")
		}
	}
}

package main

import (
	"bufio"
	"os"
  "strings"
	"fmt"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func readLine()(string,error) 			{ return reader.ReadString('\n') }

func main() {
	defer writer.Flush()
	var n int
  scanf("%d\n", &n)
  var a []string
  var s string
  for i := 0; i < n ; i++ {
    scanf("%s\n", &s);
    if strings.HasSuffix(s,"po") {
      a = append(a, "FILIPINO")
    } else if strings.HasSuffix(s, "mnida")  {
      a = append(a, "KOREAN")
    } else {
      a = append(a, "JAPANESE");
    }
  }
	fmt.Println(strings.Join(a, "\n"));
}

// A. Suffix Three
/*
We just discovered a new data structure in our research group: a suffix three!

It's very useful for natural language processing. Given three languages
and three suffixes, a suffix three can determine which language a
sentence is written in.

It's super simple, 100% accurate, and doesn't involve advanced
machine learning algorithms.

Let us tell you how it works.

    If a sentence ends with "po" the language is Filipino.
    If a sentence ends with "desu" or "masu" the language is Japanese.
    If a sentence ends with "mnida" the language is Korean.

Given this, we need you to implement a suffix three that can differentiate
Filipino, Japanese, and Korean.

Oh, did I say three suffixes? I meant four.
Input

The first line of input contains a single integer 𝑡(1≤𝑡≤30) denoting the
number of test cases. The next lines contain descriptions of the test cases.

Each test case consists of a single line containing a single string
denoting the sentence. Spaces are represented as underscores (the symbol "_")
for ease of reading. The sentence has at least 1 and at most 1000 characters,
and consists only of lowercase English letters and underscores.
The sentence has no leading or trailing underscores and no two
consecutive underscores. It is guaranteed that the sentence ends with
one of the four suffixes mentioned above.

Output

For each test case, print a single line containing either "FILIPINO",
"JAPANESE", or "KOREAN" (all in uppercase, without quotes),
depending on the detected language.

Example
Input
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu

Output
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE

Note
The first sentence ends with "po", so it is written in Filipino.

The second and third sentences end with "desu" and "masu", so they are
written in Japanese.

The fourth sentence ends with "mnida", so it is written in Korean.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _, _ := reader.ReadLine()
	n, _ := strconv.Atoi(string(input1))

	for ; n > 0; n-- {
		s, _ := reader.ReadString('\n')
		s = strings.TrimSpace(s)

		if s[len(s)-1] == 'o' {
			fmt.Println("FILIPINO")
		} else if s[len(s)-1] == 'u' {
			fmt.Println("JAPANESE")
		} else {
			fmt.Println("KOREAN")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var str string
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&str)
		if strings.HasSuffix(str, "po") {
			fmt.Println("FILIPINO")
		} else if strings.HasSuffix(str, "mnida") {
			fmt.Println("KOREAN")
		} else {
			fmt.Println("JAPANESE")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var sentence string
	fmt.Scan(&n)
	langs := make([]string, 0)
	for i := 0; i < n; i++ {
		fmt.Scan(&sentence)
		words := strings.Split(sentence, "_")
		if strings.HasSuffix(words[len(words)-1], "a") {
			langs = append(langs, "KOREAN")
		}
		if strings.HasSuffix(words[len(words)-1], "u") {
			langs = append(langs, "JAPANESE")
		}
		if strings.HasSuffix(words[len(words)-1], "o") {
			langs = append(langs, "FILIPINO")
		}

	}
	for _, lang := range langs {
		fmt.Println(lang)
	}
}

package main

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

func main () {
	var t, l int
	var word string
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		word = scanner.Text()
		l = len(word)
		if word[l-2:l] == "po" {
			fmt.Println("FILIPINO")
		} else if word[l-4:l] == "desu" || word[l-4:l] == "masu" {
			fmt.Println("JAPANESE")
		} else {
			fmt.Println("KOREAN")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func has_suffix(str string, suff string) bool {
	if strings.HasSuffix(str, suff) {
		return true
	}
	return false
}

func main() {
	var n int
	var str string

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		if has_suffix(str, "po") {
			fmt.Println("FILIPINO")
		} else if has_suffix(str, "desu") || has_suffix(str, "masu") {
			fmt.Println("JAPANESE")
		} else if has_suffix(str, "mnida") {
			fmt.Println("KOREAN")
		}
	}
}

package main

import "fmt"

func main() {
	var n, l int
	var str string
	fmt.Scan(&n)
	arr := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		l = len(str)
		if l >= 2 && str[l - 2:l] == "po" {
			arr = append(arr, "FILIPINO")
		} else if l >= 4 && ((str[l - 4:l] == "desu") || (str[l - 4:l] == "masu" )) {
			arr = append(arr, "JAPANESE")
		} else if l >= 5 && (str[l - 5:l] == "mnida") {
			arr = append(arr, "KOREAN")
		}
	}
	for i := range arr {
		fmt.Println(arr[i])
	}

}

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 t int
var S []rune

func main() {
	t = ReadInt()

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

		solve()
	}
}

func solve() {
	n := len(S)
	str := S[n-2:]
	// PrintDebug("%s\n", string(str))
	if string(str) == "po" {
		fmt.Println("FILIPINO")
	} else if string(str) == "su" {
		fmt.Println("JAPANESE")
	} else {
		fmt.Println("KOREAN")
	}
}

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

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string
	fmt.Scan(&n)
	for ; n > 0; n-- {
		fmt.Scan(&str)
		if strings.HasSuffix(str, "po") {
			fmt.Println("FILIPINO")
		} else if strings.HasSuffix(str, "desu") || strings.HasSuffix(str, "masu") {
			fmt.Println("JAPANESE")
		} else if strings.HasSuffix(str, "mnida") {
			fmt.Println("KOREAN")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for cas := 0; cas < t; cas++ {
		var s string
		fmt.Scanf("%s\n", &s)
		switch {
		case strings.HasSuffix(s, "po"):
			fmt.Println("FILIPINO")
		case strings.HasSuffix(s, "mnida"):
			fmt.Println("KOREAN")
		default:
			fmt.Println("JAPANESE")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	for cas := 0; cas < t; cas++ {
		var s string
		fmt.Scan(&s)
		switch {
		case strings.HasSuffix(s, "po"):
			fmt.Println("FILIPINO")
		case strings.HasSuffix(s, "mnida"):
			fmt.Println("KOREAN")
		default:
			fmt.Println("JAPANESE")
		}
	}
}

package main

import "fmt"

func main() {
	var n int64
	fmt.Scanln(&n)
	var str string
	for i:=int64(0);i<n ; i++ {
		fmt.Scanln(&str)
		c:=[]byte(str)
		switch c[len(c)-1] {
		case 'o':
			fmt.Println("FILIPINO")
			break
		case 'u':
			fmt.Println("JAPANESE")
			break
		default:
			fmt.Println("KOREAN")
			break
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	var n int
	fmt.Scan(&n)
	//var leng = len(s)
	//var count_a = strings.Count(s, "a")
	for i:=0; i<n; i++{
		fmt.Scan(&s)
		if strings.HasSuffix(s, "po"){
			fmt.Println("FILIPINO")
		} else if strings.HasSuffix(s, "desu") || strings.HasSuffix(s, "masu"){
			fmt.Println("JAPANESE")
		} else{
			fmt.Println("KOREAN")
		}
	}
}

package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var b string
	var a, le int
	fmt.Scan(&a)
	for i := 0; i < a; i++ {
		fmt.Scan(&b)
		le = utf8.RuneCountInString(b)
		if le >= 5 {
			if b[le-5:le] == "mnida" {
				fmt.Println("KOREAN")
			} else if b[le-2:le] == "po" {
				fmt.Println("FILIPINO")
			} else {
				fmt.Println("JAPANESE")
			}
		} else if b[le-2:le] == "po" {
			fmt.Println("FILIPINO")
		} else {
			fmt.Println("JAPANESE")
		}
	}
}

package main

import "fmt"

func main(){
	var n, k int
	var s string
	fmt.Scan(&n)
	ans := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		k = len(s)
		if k >= 2 && s[k - 2:k] == "po" {
			ans = append(ans, "FILIPINO")
		} else if k >= 4 && ((s[k - 4:k] == "desu") || (s[k - 4:k] == "masu" )) {
			ans = append(ans, "JAPANESE")
		} else if k >= 5 && (s[k - 5:k] == "mnida") {
			ans = append(ans, "KOREAN")
		}
	}
	for i := range ans {
		fmt.Println(ans[i])
	}

}

/*
 * cf1281a.go
 *
 * Copyright 2019 Yuriy V. Loymoev <yura@loymoev.ru>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

package main

import (
	"bufio"
	"os"
  "strings"
	"fmt"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func readLine()(string,error) 			{ return reader.ReadString('\n') }

func main() {
	defer writer.Flush()
	var n int
  scanf("%d", &n);
  var a []string
  for i := 0; i < n ; i++ {
    s, _ := readLine();
    if strings.HasSuffix(s,"po") {
      a = append(a, "FILIPINO")
    } else if strings.HasSuffix(s, "mnida")  {
      a = append(a, "KOREAN")
    } else {
      a = append(a, "JAPANESE");
    }
  }
	fmt.Println(strings.Join(a, "\n"));
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var sentence string
	fmt.Scan(&n)
	langs := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&sentence)
		for _, word := range strings.Split(sentence, "_") {
			if strings.HasSuffix(word, "mnida") {
				langs = append(langs, "KOREAN")
				break
			}
			if strings.HasSuffix(word, "masu") || strings.HasSuffix(word, "desu") {
				langs = append(langs, "JAPANESE")
				break
			}
			if strings.HasSuffix(word, "po") {
				langs = append(langs, "FILIPINO")
				break
			}
		}
	}
	for _, lang := range langs {
		fmt.Println(lang)
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(t)
	for cas := 0; cas < t; cas++ {
		var s string
		fmt.Scan(s)
		switch {
		case strings.HasSuffix(s, "po"):
			fmt.Println("FILIPINO")
		case strings.HasSuffix(s, "mnida"):
			fmt.Println("KOREAN")
		default:
			fmt.Println("JAPANESE")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var sentence string
	fmt.Scan(&n)
	langs := make([]string, 0)
	for i := 0; i < n; i++ {
		fmt.Scan(&sentence)
		for _, word := range strings.Split(sentence, "_") {
			if strings.HasSuffix(word, "mnida") {
				langs = append(langs, "KOREAN")
				break
			}
			if strings.HasSuffix(word, "masu") || strings.HasSuffix(word, "desu") {
				langs = append(langs, "JAPANESE")
				break
			}
			if strings.HasSuffix(word, "po") {
				langs = append(langs, "FILIPINO")
				break
			}
		}
	}
	for _, lang := range langs {
		fmt.Println(lang)
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var sentence string
	fmt.Scan(&n)
	langs := make([]string, 0)
	for i := 0; i < n; i++ {
		fmt.Scan(&sentence)
		for _, word := range strings.Split(sentence, "_") {
			if strings.HasSuffix(word, "a") {
				langs = append(langs, "KOREAN")
				break
			}
			if strings.HasSuffix(word, "u") {
				langs = append(langs, "JAPANESE")
				break
			}
			if strings.HasSuffix(word, "o") {
				langs = append(langs, "FILIPINO")
				break
			}
		}
	}
	for _, lang := range langs {
		fmt.Println(lang)
	}
}

package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var b string
	var a, le int
	fmt.Scan(&a)
	for i := 0; i < a; i++ {
		fmt.Scan(&b)
		le = utf8.RuneCountInString(b)
		if le >= 5 {
			if b[le-5:le] == "mnida" {
				fmt.Println("KOREAN")
			}
		} else if b[le-2:le] == "po" {
			fmt.Println("FILIPINO")
		} else {
			fmt.Println("JAPANESE")
		}
	}
}


Phoenix has $$$n$$$ coins with weights $$$2^1, 2^2, \dots, 2^n$$$. He knows that $$$n$$$ is even.He wants to split the coins into two piles such that each pile has exactly $$$\frac{n}{2}$$$ coins and the difference of weights between the two piles is minimized. Formally, let $$$a$$$ denote the sum of weights in the first pile, and $$$b$$$ denote the sum of weights in the second pile. Help Phoenix minimize $$$|a-b|$$$, the absolute value of $$$a-b$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 30$$$; $$$n$$$ is even) — the number of coins that Phoenix has.

For each test case, output one integer — the minimum possible difference of weights between the two piles.

NoteIn the first test case, Phoenix has two coins with weights $$$2$$$ and $$$4$$$. No matter how he divides the coins, the difference will be $$$4-2=2$$$.In the second test case, Phoenix has four coins of weight $$$2$$$, $$$4$$$, $$$8$$$, and $$$16$$$. It is optimal for Phoenix to place coins with weights $$$2$$$ and $$$16$$$ in one pile, and coins with weights $$$4$$$ and $$$8$$$ in another pile. The difference is $$$(2+16)-(4+8)=6$$$.

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx > 0; noEx-- {
		tot := 0
		fmt.Fscan(in, &tot)
		if tot == 2 {
			fmt.Fprint(out, 2)
			fmt.Fprint(out, "\n")
			continue
		}
		val := make([]int64, tot)
		val[0] = 2
		for i:=1; i<tot; i++ {val[i] = 2 * val[i-1]}
		lo, hi := 0, tot-1
		p1 := val[lo] + val[hi]
		lo++
		hi--
		p2 := val[hi] + val[hi-1]
		hi -= 2
		for lo < hi {
			p1 += val[lo]
			p2 += val[hi]
			lo++
			hi--
		}
		diff := p1 - p2
		if diff < 0 {diff *= -1}
		fmt.Fprint(out, diff)
		fmt.Fprint(out, "\n")
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		var diff = (1 << n)
		for a := 1; a < n/2; a++ {
			diff += (1 << a)
		}
		for a := n / 2; a < n; a++ {
			diff -= (1 << a)
		}
		fmt.Println(diff)
	}
}

package main

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

//FOR I/O : STARTS
var Reader *bufio.Reader = bufio.NewReader(os.Stdin)
var Writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func Printf (f string, a ...interface{}) { fmt.Fprintf(Writer, f, a...) }
func Scanf (f string, a ...interface{}) { fmt.Fscanf(Reader, f, a...) }
func Println (a ...interface{}) { fmt.Fprintln(Writer, a...)}
func Scanln (a ...interface{}) { fmt.Fscanln(Reader, a...)}
//I/O ENDS HERE

func main() {
    defer Writer.Flush()

    var t int = 1
    Scanln(&t)

    for t > 0 {
        var n int64
        Scanf("%d\n", &n)
        ans := 2*((1 << (n/2)) - 1)
        Println(ans)
        t -= 1
    }
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		var sum int
		sum += pow(n)
		for j := 1; j < n/2; j++ {
			sum += pow(j)
		}
		for j := n/2; j < n; j++ {
			sum -= pow(j)
		}
		fmt.Fprintln(w, sum)
	}
}
func pow(n int) int {
	sum := 1
	for i := 0; i < n; i++ {
		sum *= 2
	}
	return sum
}

package main

import (
	"fmt"
	"strings"
)

func ipow2(exp int) int {
	res := 1
	for exp > 0 {
		res, exp = res*2, exp-1
	}
	return res
}

// https://codeforces.com/problemset/problem/1348/A
// комментарии к решению
// n=2: 2 4                    => (4)         - (2)            => 2
// n=4: 2 4 8 16               => (16+2)      - (4+8)          => 6
// n=6: 2 4 8 16 32 64         => (64+2+4)    - (32+16+8)      => 14
// n=8: 2 4 8 16 32 64 128 256 => (256+2+4+8) - (128+64+32+16) => 30
// => 2^(n/2+1)-2
func taskSolution(a []int) string {
	ans := make([]int, len(a))
	for i := 0; i < len(a); i += 1 {
		ans[i] = ipow2(a[i]/2+1) - 2
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a))
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0 ;t-- {
		n := reader.NextInt64()
		ret := 0
		curr := 1
		for i := int64(0); i < n; i++ {
			curr *= 2
			if i < n/2-1 || i == n-1 {
				//writer.Printf("+%d\n", curr)
				ret += curr
			} else {
				//writer.Printf("-%d\n", curr)
				ret -= curr
			}
		}
		writer.Printf("%d\n", ret)
	}
}

package main

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

func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	var coin [30]int64
	w := int64(2)
	for i := 0; i < 30; i++ {
		coin[i] = w
		w = w * 2
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &m)
		if m == 2 {
			fmt.Println(2)
			continue
		}
		sum1 := int64(0)
		sum2 := int64(0)
		for j := 0; j < m/2-1; j++ {
			sum1 += coin[j]
		}
		for j := m/2 - 1; j < m-1; j++ {
			sum2 += coin[j]
		}
		sum1 += coin[m-1]
		fmt.Println(sum1 - sum2)
	}
}

package main

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

func pow2(n int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result *= 2
	}
	return result
}

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)
		result := pow2(n)
		for i := 1; i < n/2; i++ {
			result += pow2(i)
		}
		for i := n / 2; i < n; i++ {
			result -= pow2(i)
		}
		fmt.Println(result)
	}
}

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)
		fmt.Fprintln(out, 1<<(n/2+1)-2)
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	for t := 0; t < T; t++ {
		n := uint(NextInt())
		fmt.Fprintln(out, (1<<(n/2+1))-2)
	}
}

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

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n int
	fmt.Fscan(input, &n)

	a := 0
	for i := 0; i < n/2; i++ {
		a += 1 << i
	}

	fmt.Println(a * 2)
}

// https://codeforces.com/contest/1348/problem/0
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n int
	fmt.Fscan(input, &n)

	a := 0
	for i := 0; i < n/2; i++ {
		a += 1 << i
	}

	fmt.Println(a * 2)
}

package main

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

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

    var t, n int
    fmt.Fscan(in, &t)
    for ;t >0; t-- {
        fmt.Fscan(in, &n)
        fmt.Fprintln(out, (1 << (n / 2 + 1)) - 2)
    }
}

package main

import (
	"fmt"
	"math"
)

func powerSum(n int) int64 {

	var res int64
	res = 0
	halfN := n / 2

	for i := 0; i < halfN; i++ {
		res += int64(math.Pow(2, float64(i+1)))
	}

	return res

}

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

/*
URL:
https://codeforces.com/contest/1348/problem/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	A []int64
)

func main() {
	for i := int64(1); i <= 32; i++ {
		tmp := PowInt(2, i)
		A = append(A, tmp)
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt64()
		solve(n)
	}
}

func solve(n int64) {
	var a, b int64

	for i := int64(1); i <= n/2-1; i++ {
		a += PowInt(2, i)
	}
	a += PowInt(2, n)

	for i := int64(n / 2); i <= n-1; i++ {
		b += PowInt(2, i)
	}

	fmt.Println(AbsInt(a - b))
}

// func solve(n int64) {
// 	a, b := int64(0), int64(0)
// 	a += 2
// 	b += 4

// 	for i := int64(3); i <= n; i += 2 {
// 		small := PowInt(2, i)
// 		large := PowInt(2, i+1)

// 		if a < b {
// 			a += large
// 			b += small
// 		} else {
// 			a += small
// 			b += large
// 		}
// 	}

// 	fmt.Println(AbsInt(a - b))
// }

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

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
	"fmt"
	"math"
)

func main() {
	tot := 0
	n := 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		_, _ = fmt.Scanln(&n)
		ans := n / 2
		a := math.Pow(2, float64(n))
		for j := 1; j < ans; j++ {
			a = a + math.Pow(2, float64(j))
		}
		b := 0
		for j := ans; j < n; j++ {
			b = b + int(math.Pow(2, float64(j)))
		}
		ans = int(math.Abs(a - float64(b)))
		fmt.Println(ans)
	}
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		P(solve(n))
	}

	close(O)
	oWg.Wait()
}

func solve(n int) int64 {
	high := int64(0)
	low := int64(0)

	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = 2 << (i)
	}

	c := 0
	for i := n - 2; c < n/2; i-- {
		c++
		low += a[i]
	}
	high += a[n-1]
	for i := 0; i < (n/2)-1; i++ {
	    high += a[i]
	}

	return abs(high - low)
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

import "fmt"
import "math"

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

	var n []int = make([]int, t)
	for i:=0; i< t ; i++ {
		fmt.Scanln(&n[i])
	}

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

		fmt.Println(getMinDiff(n[i]))

	}
}

func getMinDiff(n int) int {

	total := 2*(math.Pow(2, (float64)(n))  - 1)

	partial := 2*(math.Pow(2, (float64)(n/2 -1)) - 1) + math.Pow(2, (float64)(n))

	return (int)(2*partial - total)
}

package main

import (
	"fmt"
	"math"
)

var pre = make([]int64,31)

func doPre(){
	pre[0] = 1
	for i :=1 ;i< 31;i++{
		pre[i] = pre[i-1] * 2
	}
}
func solve(n int) {
	var max,min int64 = 0,0
	max += pre[n]
	for i := 1;i < n;i++{
		if i <= n/2 -1 {
			max += pre[i]
		}else{
			min += pre[i]
		}
	}
	fmt.Println(math.Abs(float64(max) - float64(min)))
}

func main() {
	var n int
	doPre()
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		var x int
		fmt.Scanf("%d\n",&x)
		solve(x)
	}
}

package main

import (
	"fmt"
)

func solve(n int) {
	result := 0
	tmp := 2
	flag := true
	for i := 2;i<=n;i+=2{
		if flag {
			result += tmp
		}else{
			result -= tmp
		}
		flag = !flag
		tmp *= 4
	}
	if result < 0 {
		result = -result
	}
	fmt.Println(result)
}

func main() {
	var n int
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		var x int
		fmt.Scanf("%d\n",&x)
		solve(x)
	}
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx > 0; noEx-- {
		tot := 0
		fmt.Fscan(in, &tot)
		p1, p2 := 0, 0
		cur := 2
		for t:=0; t < tot/2; t++ {
			if t % 2 == 0 {
				p1 += cur
				cur *=2
				p2 += cur
				cur *= 2
			} else {
				p2 += cur
				cur *=2
				p1 += cur
				cur *= 2
			}
		}
		diff := p1 - p2
		if diff < 0 {diff *= -1}
		fmt.Fprint(out, diff)
		fmt.Fprint(out, "\n")
	}
}

package main

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

func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	var coin [30]int64
	w := int64(2)
	for i := 0; i < 30; i++ {
		coin[i] = w
		w = w * 2
	}

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &m)
		if m == 2 {
			fmt.Println(2)
			continue
		}
		sum1 := int64(0)
		sum2 := int64(0)
		for j := 0; j < m/2; j++ {
			if j%2 == 0 {
				sum1 += coin[j] + coin[m-j-1]
			} else {
				sum2 += coin[j] + coin[m-j-1]
			}
		}
		fmt.Println(sum1 - sum2)
	}
}

package main

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

func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	var coin [30]int64
	w := int64(2)
	for i := 0; i < 30; i++ {
		coin[i] = w
		w = w * 2
	}

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &m)
		if m == 2 {
			fmt.Println(2)
			continue
		}
		sum1 := int64(0)
		sum2 := int64(0)
		for j := 0; j < m/2; j++ {
			if j%2 == 0 {
				sum1 += coin[j] + coin[m-j-1]
			} else {
				sum2 += coin[j] + coin[m-j-1]
			}
		}
		fmt.Println(sum1, sum2)
		fmt.Println(sum1 - sum2)
	}
}

// http://codeforces.com/problemset/problem/706/A

package main

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

func main() {
	var x, y, n int

	fmt.Scanln(&x, &y)
	fmt.Scanln(&n)

	times := make([]float64, n)

	for i := 0; i < n; i++ {
		var x1, y1, v1 int
		fmt.Scanln(&x1, &y1, &v1)

		times[i] = math.Sqrt(float64((x - x1)*(x - x1) + (y - y1)*(y - y1))) / float64(v1)
	}

	sort.Float64s(times)
	fmt.Println(times[0])
}

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

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n int
	fmt.Fscan(input, &n)
	if n == 2 {
		fmt.Println(2)
		return
	}

	a := int64(1 << n /2 )
	b := int64(0)

	for i := 0; i < n/2 - 1; i++ {
		a++
		a <<= 1
	}
	a >>= 1
	for i := 0; i < n /2; i++ {
		b++
		b <<= 1

	}
	b >>= 1
	b <<= (n/2 - 1)
	a *= 2
	b *= 2

	fmt.Println(a - b)
}

package main

import (
	"fmt"
	"math"
)

func powerSum(n int) int64 {

	var res int64
	res = 0
	halfN := n / 2

	for i := 0; i < halfN; i++ {
		res += int64(math.Pow(2, float64(i+1)))
	}

	return res

}

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

/*
URL:
https://codeforces.com/contest/1348/problem/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	A []int64
)

func main() {
	for i := int64(1); i <= 32; i++ {
		tmp := PowInt(2, i)
		A = append(A, tmp)
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt64()
		solve(n)
	}
}

func solve(n int64) {
	a, b := int64(0), int64(0)
	a += 2
	b += 4

	for i := int64(3); i <= n; i += 2 {
		small := PowInt(2, i)
		large := PowInt(2, i+1)

		if a < b {
			a += large
			b += small
		} else {
			a += small
			b += large
		}
	}

	fmt.Println(AbsInt(a - b))
}

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

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import "fmt"

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

	var n []int = make([]int, t)
	for i:=0; i< t ; i++ {
		fmt.Scanln(&n[i])
	}

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

		fmt.Println(getMinDiff(n[i]))

	}
}

func getMinDiff(n int) int {
	dp := make([]int, n/2+1)

	dp[0] = 0
	dp[1] = 2
	first := 2
	sec := 4

	for i:=2; i<= n/2; i++ {
		first = first*4
		sec = sec*4

		if dp[i-1] + first-sec < 0 {
			dp[i] = -(dp[i-1] + first-sec)
		} else {
			dp[i] = (dp[i-1] + first-sec)
		}
	}

	return dp[n/2]
}


You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps:   choose two leaves;  add the length of the simple path between them to the answer;  remove one of the chosen leaves from the tree. Initial answer (before applying operations) is 0. Obviously after n - 1 such operations the tree will consist of a single vertex. Calculate the maximal possible answer you can achieve, and construct a sequence of operations that allows you to achieve this answer!

The first line contains one integer number n (2 ≤ n ≤ 2·105) — the number of vertices in the tree.  Next n - 1 lines describe the edges of the tree in form ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that given graph is a tree.

In the first line print one integer number — maximal possible answer.  In the next n - 1 lines print the operations in order of their applying in format ai, bi, ci, where ai, bi — pair of the leaves that are chosen in the current operation (1 ≤ ai, bi ≤ n), ci (1 ≤ ci ≤ n, ci = ai or ci = bi) — choosen leaf that is removed from the tree in the current operation.  See the examples for better understanding.

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var g [200001][]int
var p, dist_from_diameter, from [200001]int
var a [2]int
var d, max_dist int
var path, q, w, leaves []int
var used [200001]bool

func dfs(v, parent, dist int) {
	if dist > max_dist {
		max_dist = dist
		a[d] = v
	}
	for i := range g[v] {
		to := g[v][i]
		if to == parent {
			continue
		}
		p[to] = v
		dfs(to, v, dist + 1)
	}
}

func dfs1(v, parent, dist int) {
	if dist_from_diameter[v] <= dist {
		dist_from_diameter[v] = dist
		from[v] = a[d]
	}
	for i := range g[v] {
		to := g[v][i]
		if to == parent {
			continue
		}
		dfs1(to, v, dist + 1)
	}
	if d == 0 {
		leaves = append(leaves, v)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	for i := 1; i < n; i++ {
		var x,y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		g[x] = append(g[x], y)
		g[y] = append(g[y], x)
	}
	dfs(1, 0, 0)
	d++
	max_dist = 0
	dfs(a[0], 0, 0)
	for i := a[1]; i != a[0]; i = p[i] {
		path = append(path, i)
		used[i] = true
	}
	used[a[0]] = true
	path = append(path, a[0])
	d = 0
	dfs1(a[0], 0, 0)
	d++
	dfs1(a[1], 0, 0)
	var ans int64
	for j := range leaves {
		i := leaves[j]
		if used[i] {
			continue
		}
		q = append(q, i)
		w = append(w, from[i])
		ans += int64(dist_from_diameter[i])
	}
	d = len(path) - 1
	for i := 0; i < len(path) - 1; i++ {
		q = append(q, path[i])
		w = append(w, a[0])
		ans += int64(d)
		d--
	}
	fmt.Println(ans)
	for i := range q {
		fmt.Println(q[i], w[i], q[i])
	}
}

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var g [200001][]int
var p, dist_from_diameter, from [200001]int
var a [2]int
var d, max_dist int
var path, q, w []int
var used [200001]bool

func dfs(v, parent, dist int) {
	if dist > max_dist {
		max_dist = dist
		a[d] = v
	}
	for i := range g[v] {
		to := g[v][i]
		if to == parent {
			continue
		}
		p[to] = v
		dfs(to, v, dist + 1)
	}
}

func dfs1(v, parent, dist int) {
	if dist_from_diameter[v] <= dist {
		dist_from_diameter[v] = dist
		from[v] = a[d]
	}
	for i := range g[v] {
		to := g[v][i]
		if to == parent {
			continue
		}
		dfs1(to, v, dist + 1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	for i := 1; i < n; i++ {
		var x,y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		g[x] = append(g[x], y)
		g[y] = append(g[y], x)
	}
	dfs(1, 0, 0)
	d++
	max_dist = 0
	dfs(a[0], 0, 0)
	for i := a[1]; i != a[0]; i = p[i] {
		path = append(path, i)
		used[i] = true
	}
	used[a[0]] = true
	path = append(path, a[0])
	d = 0
	dfs1(a[0], 0, 0)
	d++
	dfs1(a[1], 0, 0)
	var ans int64
	for i := 1; i <= n; i++ {
		if used[i] {
			continue
		}
		q = append(q, i)
		w = append(w, from[i])
		ans += int64(dist_from_diameter[i])
	}
	d = len(path) - 1
	for i := 0; i < len(path) - 1; i++ {
		q = append(q, path[i])
		w = append(w, a[0])
		ans += int64(d)
		d--
	}
	fmt.Println(ans)
	for i := range q {
		fmt.Println(q[i], w[i], q[i])
	}
}


One important contest will take place on the most famous programming platform (Topforces) very soon!The authors have a pool of $$$n$$$ problems and should choose at most three of them into this contest. The prettiness of the $$$i$$$-th problem is $$$a_i$$$. The authors have to compose the most pretty contest (in other words, the cumulative prettinesses of chosen problems should be maximum possible).But there is one important thing in the contest preparation: because of some superstitions of authors, the prettinesses of problems cannot divide each other. In other words, if the prettinesses of chosen problems are $$$x, y, z$$$, then $$$x$$$ should be divisible by neither $$$y$$$, nor $$$z$$$, $$$y$$$ should be divisible by neither $$$x$$$, nor $$$z$$$ and $$$z$$$ should be divisible by neither $$$x$$$, nor $$$y$$$. If the prettinesses of chosen problems are $$$x$$$ and $$$y$$$ then neither $$$x$$$ should be divisible by $$$y$$$ nor $$$y$$$ should be divisible by $$$x$$$. Any contest composed from one problem is considered good.Your task is to find out the maximum possible total prettiness of the contest composed of at most three problems from the given pool.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the prettiness of the $$$i$$$-th problem. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print one integer — the maximum possible cumulative prettiness of the contest composed of at most three problems from the given pool of problems in the query.

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		sort.Ints(a)
		j := 0
		for i := 1; i < n; i++ {
			if a[j] != a[i] {
				j++
				a[j] = a[i]
			}
		}
		ans := a[j]
		n = j + 1
		a = a[:n]

		for i := n - 1; i >= 0; i-- {
			ai := a[i]
			cnt := 0
			for j := i - 1; j >= 0; j-- {
				aj := a[j]
				if ai%aj != 0 {
					ans = max(ans, ai+aj)
					cnt2 := 0
					for k := j - 1; k >= 0; k-- {
						ak := a[k]
						if ai%ak != 0 && aj%ak != 0 {
							ans = max(ans, ai+aj+ak)
							if cnt2++; cnt2 == 10 {
								break
							}
						}
					}
					if cnt++; cnt == 10 {
						break
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		j := 0
		for i := 1; i < n; i++ {
			if a[j] != a[i] {
				j++
				a[j] = a[i]
			}
		}
		ans := a[j]
		n = j + 1
		a = a[:n]
		for i := n - 1; i >= 0; i-- {
			v := a[i]
			cnt := 0
			for j := i - 1; j >= 0; j-- {
				w := a[j]
				if v%w != 0 {
					cnt++
					if v+w > ans {
						ans = v + w
					}
					cnt2 := 0
					for k := j - 1; k >= 0; k-- {
						u := a[k]
						if v%u != 0 && w%u != 0 {
							cnt2++
							if v+w+u > ans {
								ans = v + w + u
							}
							if cnt2 == 10 {
								break
							}
						}
					}
					if cnt == 10 {
						break
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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