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

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

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


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


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() {
	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 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"
	"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 (
	"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]
}


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

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"
	"os"
	"sort"
)

func solve(n int64, t int64, arr []int64) int64 {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := int64(0)

	for i := range arr {
		total += arr[i] * t
		if t > 1 {
			t--
		}
	}
	return total
}

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

	var n, t int64
	fmt.Fscanf(r, "%d %d\n", &n, &t)

	arr := make([]int64, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,x int
    fmt.Scan(&n,&x)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    var ans int64 = 0
    for i := 0; i < n; i++ {
        ans += int64(a[i])*int64(x)
        if x != 1 { x-- }
    }
    fmt.Println(ans)
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, x := nextInt(), nextInt()
	c := make([]int, n)

	for i:=0; i<n; i++ {
		c[i] = nextInt()
	}

	sort.Ints(c)

	totalHours := int64(0)

	for i:=0; i<n; i++ {
		totalHours += int64(c[i]) * int64(x)

		if x > 1 {
			x--
		}
	}

	println(totalHours)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

func solve(n int, t int, arr []int) int64 {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := int64(0)

	for i := range arr {
		total += int64(arr[i]) * int64(t)
		if t > 1 {
			t--
		}
	}
	return total
}

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

	var n, t int
	fmt.Fscanf(r, "%d %d\n", &n, &t)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n, x := reader.ReadInt(), reader.ReadInt()
	c := make([]int, n)
	for i := 0; i < n; i++ {
		c[i] = reader.ReadInt()
	}
	sort.Ints(c)

	time := int64(0)
	for i := 0; i < n; i++ {
		time += int64(x) * int64(c[i])
		if x > 1 {
			x--
		}
	}

	fmt.Print(time)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main

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

func main() {
	var n int
	var k int64
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
    	fmt.Scan(&n,&k)
	a:=make([]int,n)

	for i:=0;i<n;i++ {
		input.Scan()
       		aa, _ := strconv.Atoi(input.Text())
		a[i]=aa
	}
	sort.Ints(a)
	//for _,v =range a {
		//fmt.Println(v)
	//}
	var no,c int64
	no = k
	c=0
	for i:=0;i<n;i++ {
		if no<1 {
			no=1
		}
		c += no* int64(a[i])
		no--
	}
	fmt.Println(c)
}

package main

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

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

	//var n int64
	var x int64
	var c []int64

	inputLine1, _ := reader.ReadString('\n')
	tmp := strings.Split(strings.TrimSpace(inputLine1), " ")
	//n, _ = strconv.ParseInt(string(tmp[0]), 10, 64)
	x, _ = strconv.ParseInt(string(tmp[1]), 10, 64)

	inputLine2, _ := reader.ReadString('\n')
	tmpArray := strings.Split(strings.TrimSpace(inputLine2), " ")

	c = convertStringToInt64(tmpArray)

	sort.Slice(c, func(i, j int) bool {
		return c[i] < c[j]
	})

	var time int64 = 0
	for _, value := range c {
		time += value * x
		if x > 1 {
			x -= 1
		}
	}
	fmt.Println(time)
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

func main() {
	var n, x int
	if _, err := fmt.Scanf("%d %d\n", &n, &x); err != nil {
		return
	}

	c := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		c[i] = a
	}

	merge_sort(c, 0, n-1)

	time := int64(0)
	xx := int64(x)
	for i := 0; i < n; i++ {
		time += int64(c[i]) * xx
		if xx > 1 {
			xx -= 1
		}
	}
	fmt.Println(time)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"sort"
	"strconv"
	"time"
	"unicode/utf8"
)

// ******************************** CODE STARTS ********************************

var ()

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

	sort.Ints(mas)
	res := int64(0)
	for i := 0; i < n; i++ {
		res += int64(time) * int64(mas[i])
		if time > 1 {
			time--
		}
	}
	printInt64(res)
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	local := flag.Bool("local", false, "Equals true, if run is local.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *local {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFLoat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

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

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

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

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

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

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

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

func solve(n int, t int, arr []int) int64 {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := int64(0)

	for i := range arr {
		total += int64(arr[i] * t)
		if t > 1 {
			t--
		}
	}
	return total
}

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

	var n, t int
	fmt.Fscanf(r, "%d %d\n", &n, &t)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, x := nextInt(), nextInt()
	c := make([]int, n)

	for i:=0; i<n; i++ {
		c[i] = nextInt()
	}

	sort.Ints(c)

	totalHours := 0

	for i:=0; i<n; i++ {
		totalHours += c[i] * x

		if x > 1 {
			x--
		}
	}

	println(totalHours)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

func solve(n int, t int, arr []int) int {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := 0

	for i := range arr {
		total += arr[i] * t
		if t > 1 {
			t--
		}
	}
	return total
}

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

	var n, t int
	fmt.Fscanf(r, "%d %d\n", &n, &t)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}