Ehab has an array $$$a$$$ of length $$$n$$$. He has just enough free time to make a new array consisting of $$$n$$$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.

The first line contains an integer $$$t$$$ — the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.

For each testcase, output the length of the longest increasing subsequence of $$$a$$$ if you concatenate it to itself $$$n$$$ times.

NoteIn the first sample, the new array is $$$[3,2,\textbf{1},3,\textbf{2},1,\textbf{3},2,1]$$$. The longest increasing subsequence is marked in bold.In the second sample, the longest increasing subsequence will be $$$[1,3,4,5,9]$$$.

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		set := make(map[int]bool, 0)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			set[a] = true
		}
		fmt.Println(len(set))
	}
}

package main

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

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

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

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

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

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

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

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

	return i
}

func fillNNums(bs []byte, n int, res []int) {
	x := 0
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
}

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

	for tc > 0 {
		tc--
		n := readNum(reader)

		P := readNNums(reader, n)

		fmt.Println(solve(n, P))
	}
}

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

	var cnt int
	for i := 1; i <= n; i++ {
		if i == n || P[i] > P[i-1] {
			cnt++
		}
	}

	return cnt
}

package main

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

func main() {

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

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

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

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

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

		sort.Ints(arr)

		prev := 0
		cnt := 0
		for i := 0; i < n; i++ {
			if prev != arr[i] {
				cnt++
				prev = arr[i]
			}
		}
		fmt.Fprintln(out, cnt)
	}

}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"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 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()
	a := make([]int, 100000)
	for t := 0; t < T; t++ {
		n := NextInt()
		for i := 0; i < n; i++ {
			a[i] = NextInt()
		}
		sort.Ints(a[:n])
		newLen := unique(a[:n])
		fmt.Fprintln(out, newLen)
	}

}

package main

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

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

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

		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &e);
			_, ok := m[e]
			if ok == false {
				cnt = cnt + 1
				m[e] = true
			}
		}
		fmt.Fprint(w, cnt, "\n")
	}
}

package main

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

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

func main(){

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

		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &e);
			_, ok := m[e]
			if ok == false {
				cnt = cnt + 1
				m[e] = true
			}
		}
		print(cnt, "\n")
	}
	writer.Flush()
}

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

package main

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

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

func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func nextInt() int64 {
	in.Scan()
	n, _ := strconv.ParseInt(in.Text(), 10, 64)
	return n
}

func main() {
	in.Split(bufio.ScanWords)
	defer out.Flush()
	for t := nextInt(); t > 0; t-- {
		n := nextInt()
		set := map[int64]struct{}{}
		for i := 0; i < int(n); i++ {
			set[nextInt()] = struct{}{}
		}
		printf("%d\n", len(set))
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		line = readLine(reader)
		ans := strings.Split(string(line), " ")
		m := make(map[int64]struct{})
		for i:=0;i<len(ans);i++ {
			x,_ := strconv.ParseInt(ans[i], 10, 64)
			m[x] = struct{}{}
		}
		fmt.Println(len(m))
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

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

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

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

	for t := 0; t < ts; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)

		mp := make(map[int]bool)
		cc := 0
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscanf(r, "%d", &x)
			if !mp[x] {
				cc++
				mp[x] = true
			}
		}
		fmt.Fscanf(r, "\n")

		fmt.Fprintf(w, "%d\n", cc)
	}
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		c := map[int]bool{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			c[v] = true
		}
		Fprintln(out, len(c))
	}
}

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

package main

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

func main() {
	var t int
	fmt.Fscan(reader, &t)
	for t > 0 {
		var n int
		fmt.Fscan(reader, &n)
		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(reader, &a)
			m[a] = true
		}
		print(len(m), "\n")
		t--
	}
	writer.Flush()
}

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

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

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

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

func main() {
	t := nextInt()
	for t > 0 {
		n := nextInt()
		m := make(map[int]int)
		for i := 0; i < n; i++ {
			m[nextInt()]++
		}
		print(len(m), "\n")
		t--
	}
	writer.Flush()
}

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

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

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

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

func main() {
	t := nextInt()
	for t > 0 {
		n := nextInt()
		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			m[nextInt()] = true
		}
		print(len(m), "\n")
		t--
	}
	writer.Flush()
}

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

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

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		m := make(map[int]int)
		for j := 0; j < n; j++ {
			var inp int
			fmt.Fscan(in, &inp)
			m[inp] = inp
		}
		fmt.Println(len(m))
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt() int {
	if sc.Scan() {
		t := sc.Text()
		if v, err := strconv.Atoi(t); err == nil {
			return v
		}
		panic(fmt.Sprintln("Could't scan int from input", t))
	}
	panic(sc.Err())
}

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

var sc *bufio.Scanner = newScanner()

func solve() {
	n := scanInt()
	x := make(map[int]int)

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

	res := 0
	for range x {
		res++
	}
	fmt.Println(res)
}

func main() {
	t := scanInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"math"
	"os"
	"runtime"
	"runtime/pprof"
	"strconv"
	"strings"
)

func Memset(array []byte, value byte) {
	for i := 0; i < len(array); i++ {
		array[i] = value
	}
}

type Bitmap struct {
	size  int64
	array []byte
}

func NewBitmap(size int64) *Bitmap {
	size = int64(math.Ceil(float64(size) / 8.0))
	return &Bitmap{array: make([]byte, size), size: size}
}

func (b *Bitmap) Get(position int64) byte {
	x := position / 8
	y := 1 << (position % 8)
	return b.array[x] & byte(y)
}

func (b *Bitmap) Set(position int64) {
	x := position / 8
	y := 1 << (position % 8)
	b.array[x] |= byte(y)
}

func (b *Bitmap) Reset() {
	b.array = []byte{}
	runtime.GC()
	b.array = make([]byte, b.size)
}

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	//maxValue := int64(math.Pow10(9))
	var n, i, j int64
	var size int64
	var counter int64
	//bitmap := NewBitmap(maxValue)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		counter = 0
		dict := map[int64]struct{}{}
		//if i > 0 {
		//	bitmap.Rejset()
		//}
		str, _ := reader.ReadString('\n')
		size, err = strconv.ParseInt(strings.TrimSpace(str), 10, 64)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}
		for j = 0; j < size; j++ {
			delim := byte(' ')
			if j == size-1 {
				delim = byte('\n')
			}
			str1, _ := reader.ReadString(delim)
			item, err := strconv.ParseInt(strings.TrimSpace(str1), 10, 64)
			if err != nil {
				fmt.Printf("err2: %v", err.Error())
				os.Exit(1)
			}
			if _, ok := dict[item]; ok == true {
				continue
			}
			dict[item] = struct{}{}
			//bitmap.Set(item - 1)
			counter++
		}
		writer.WriteString(strconv.FormatInt(counter, 10))
		writer.WriteString("\n")
	}
	writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    scanner.Scan()
    t, _ := strconv.Atoi(scanner.Text())

    for i := 0; i < t; i++ {
        scanner.Scan()
        n, _ := strconv.Atoi(scanner.Text())
        ar := make([]int, n, n)
        for j := range ar {
            scanner.Scan()
            ar[j], _ = strconv.Atoi(scanner.Text())
        }

        sort.Ints(ar)

        result := 0
        for i := range ar {
            if i > 0 && ar[i] > ar[i-1] {
                result++
            }
        }
        fmt.Fprintf(writer, "%d\n", result+1)
    }

}

package main

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

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)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	i, _ := strconv.Atoi(impl.NextString())
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	i, _ := strconv.ParseInt(impl.NextString(), 10, 64)
	return i
}

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	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()
}

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		n := reader.NextInt()
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[reader.NextInt64()] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

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)
	s.Buffer([]byte{}, math.MaxInt32)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	i, _ := strconv.Atoi(impl.NextString())
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	i, _ := strconv.ParseInt(impl.NextString(), 10, 64)
	return i
}

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	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()
}

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		n := reader.NextInt()
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[reader.NextInt64()] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Scanf(format string, a ...interface{})
	Int() int
	Int64() int64
	String() string
	IntStream(size int) <-chan int
	Int64Stream(size int) <-chan int64
	StringStream(size int) <-chan string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

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

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.Scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
	c := make(chan int)
	go func() {
        defer close(c)
		for i := 0; i < size-1; i++ {
			var v int
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
	c := make(chan int64)
	go func() {
        defer close(c)
		for i := 0; i < size-1; i++ {
			var v int64
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int64
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
	c := make(chan string)
	go func() {
		for i := 0; i < size-1; i++ {
			var v string
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v string
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%s ", &ret[i])
	}
	impl.Scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

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

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

func main() {
	defer writer.Flush()
	t := reader.Int()
	for ; t > 0; t-- {
		n := reader.Int()
		c := reader.Int64Stream(n)
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[<-c] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Scanf(format string, a ...interface{})
	Int() int
	Int64() int64
	String() string
	IntStream(size int) <-chan int
	Int64Stream(size int) <-chan int64
	StringStream(size int) <-chan string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

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

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.Scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
	c := make(chan int)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
	c := make(chan int64)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int64
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int64
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
	c := make(chan string)
	go func() {
		for i := 0; i < size-1; i++ {
			var v string
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v string
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%s ", &ret[i])
	}
	impl.Scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

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

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

func main() {
	defer writer.Flush()
	t := reader.Int()
	for ; t > 0; t-- {
		n := reader.Int()
		c := reader.Int64Stream(n)
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[<-c] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

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)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	i, _ := strconv.Atoi(impl.NextString())
	return i
}

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

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	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()
}

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		n := reader.NextInt()
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[reader.NextInt64()] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

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

func scanf(format string, a ...interface{})  { fmt.Fscanf(in, format, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }

func main() {
	defer out.Flush()
	var t int
	for scanf("%d\n", &t); t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		set := map[int64]struct{}{}
		for i := 0; i < n; i++ {
			var ai int64
			scanf("%d ", &ai)
			set[ai] = struct{}{}
		}
		printf("%d\n", len(set))
	}
}

package main

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

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

func scanf(format string, a ...interface{})  { fmt.Fscanf(in, format, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }

func main() {
	defer out.Flush()
	var t int
	for scanf("%d\n", &t); t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		set := map[int]struct{}{}
		for i := 0; i < n; i++ {
			var ai int
			scanf("%d ", &ai)
			set[ai] = struct{}{}
		}
		printf("%d\n", len(set))
	}
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		m := make(map[int]int)
		for j := 0; j < n; j++ {
			var inp int
			fmt.Fscan(in, &inp)
			m[inp] = inp
		}
		fmt.Println(len(m))
	}
}

package main

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

func Memset(array []byte, value byte) {
	for i := 0; i < len(array); i++ {
		array[i] = value
	}
}

type Bitmap struct {
	array []byte
}

func NewBitmap(size int64) *Bitmap {
	return &Bitmap{array: make([]byte, int64(math.Ceil(float64(size) / 8.0)))}
}

func (b *Bitmap) Get(position int64) byte {
	x := position / 8
	y := 1 << (position % 8)
	return b.array[x] & byte(y)
}

func (b *Bitmap) Set(position int64) {
	x := position / 8
	y := 1 << (position % 8)
	b.array[x] |= byte(y)
}

func (b *Bitmap) Reset() {
	Memset(b.array, 0)
}

func main() {
	maxValue := int64(math.Pow10(9))
	var n, i, j int64
	var size int64
	var counter int64
	bitmap := NewBitmap(maxValue)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		if i > 0 {
			bitmap.Reset()
			counter = 0
		}
		str, _ := reader.ReadString('\n')
		size, err = strconv.ParseInt(strings.TrimSpace(str), 10, 64)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}
		for j = 0; j < size; j++ {
			delim := byte(' ')
			if j == size - 1 {
				delim = byte('\n')
			}
			str1, _ := reader.ReadString(delim)
			item, err := strconv.ParseInt(strings.TrimSpace(str1), 10, 64)
			if err != nil {
				fmt.Printf("err2: %v", err.Error())
				os.Exit(1)
			}
			if bitmap.Get(item - 1) != 0 {
				continue
			}
			bitmap.Set(item)
			counter++
		}
		writer.WriteString(strconv.FormatInt(counter, 10))
		writer.WriteString("\n")
	}
	writer.Flush()
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Scanf(format string, a ...interface{})
	Int() int
	Int64() int64
	String() string
	IntStream(size int) <-chan int
	Int64Stream(size int) <-chan int64
	StringStream(size int) <-chan string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

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

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	fmt.Fscan(impl.Reader, &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.Scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
	c := make(chan int)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
	c := make(chan int64)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int64
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int64
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
	c := make(chan string)
	go func() {
		for i := 0; i < size-1; i++ {
			var v string
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v string
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%s ", &ret[i])
	}
	impl.Scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

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

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

func main() {
	defer writer.Flush()
	t := reader.Int()
	for ; t > 0; t-- {
		n := reader.Int()
		c := reader.Int64Stream(n)
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[<-c] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}


You have a bag of size $$$n$$$. Also you have $$$m$$$ boxes. The size of $$$i$$$-th box is $$$a_i$$$, where each $$$a_i$$$ is an integer non-negative power of two.You can divide boxes into two parts of equal size. Your goal is to fill the bag completely.For example, if $$$n = 10$$$ and $$$a = [1, 1, 32]$$$ then you have to divide the box of size $$$32$$$ into two parts of size $$$16$$$, and then divide the box of size $$$16$$$. So you can fill the bag with boxes of size $$$1$$$, $$$1$$$ and $$$8$$$.Calculate the minimum number of divisions required to fill the bag of size $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^{18}, 1 \le m \le 10^5$$$) — the size of bag and the number of boxes, respectively. The second line of each test case contains $$$m$$$ integers $$$a_1, a_2, \dots , a_m$$$ ($$$1 \le a_i \le 10^9$$$) — the sizes of boxes. It is guaranteed that each $$$a_i$$$ is a power of two. It is also guaranteed that sum of all $$$m$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the minimum number of divisions required to fill the bag of size $$$n$$$ (or $$$-1$$$, if it is impossible).

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, m := int64(0), int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([]int64, 63)
		weight := make([]int64, 63)
		weight[0] = 1
		for i := 1; i < 63; i++ {
			weight[i] = weight[i-1] * 2
		}
		//fmt.Println(weight)
		b := make([]int64, 0)
		sum := int64(0)
		cur := int64(0)
		for i := int64(0); i < m; i++ {
			tmp := int64(0)
			fmt.Fscanf(in, "%d", &tmp)
			a[getMi(tmp)]++
			sum += tmp
		}
		fmt.Fscanf(in, "\n")
		if sum < n {
			fmt.Fprintf(out, "%d\n", -1)
			continue
		}
		for n > 0 {
			b = append(b, n%2)
			n /= 2
		}
		ans := 0
		//fmt.Println(a)
		//fmt.Println(b)
		for i := 0; i < len(b); i++ {
			if b[i] == 1 {
				if cur >= weight[i] {
					cur -= weight[i]
				} else {
					for j := i; j < 63; j++ {
						if a[j] > 0 {
							ans += j - i
							a[j]--
							for k := i; k < j; k++ {
								a[k]++
							}
							break
						}
					}
				}
			}
			if i < 63 {
				cur += a[i] * weight[i]
				a[i] = 0
			}
		}
		//fmt.Println(a)
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func getMi(a int64) int64 {
	if a == 1 {
		return 0
	}
	return 1 + getMi(a/2)
}

package main

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

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

	solve := func() (ans int) {
		var n int64
		var m int
		Fscan(in, &n, &m)
		a := make([]int, m)
		sum := int64(0)
		cnts := map[int64]int{}
		for i := range a {
			Fscan(in, &a[i])
			sum += int64(a[i])
			cnts[int64(a[i])]++
		}
		if sum < n {
			return -1
		}
		//sort.Ints(a)

		n1 := n
		cnt := uint(0)
		for n1 > 0 {
			cur := int64(1) << cnt
			if n1&1 == 1 {
				if cnts[cur] > 0 {
					cnts[cur]--
				} else {
					i := cur << 1
					for ; cnts[i] == 0; i <<= 1 {
					}
					for ;i > cur;i>>=1 {
						cnts[i]--
						cnts[i>>1]+=2
						ans++
					}
					cnts[cur]-- // got it
				}
			}

			cnts[cur<<1] += cnts[cur] / 2
			cnts[cur] &= 1

			n1 >>= 1
			cnt++
		}

		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve())
	}
}

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

package main

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

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

	solve := func() (ans int) {
		var n, v int64
		var m int
		Fscan(in, &n, &m)
		sum := int64(0)
		cnts := map[int64]int{}
		for i := 0; i < m; i++ {
			Fscan(in, &v)
			sum += v
			cnts[v]++
		}
		if sum < n {
			return -1
		}

		for i := int64(1); i <= n; i <<= 1 {
			if n&i > 0 {
				if cnts[i] == 0 {
					j := i << 1
					for ; cnts[j] == 0; j <<= 1 {
					}
					for ; j > i; j >>= 1 {
						cnts[j]--
						cnts[j>>1] += 2
						ans++
					}
				}
				cnts[i]--
			}
			cnts[i<<1] += cnts[i] >> 1
			cnts[i] &= 1
		}
		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve())
	}
}

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


Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.

On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.

NoteIn the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	card := make([]int, n);

	for i:=0; i<n; i++ {
		fmt.Scanf("%d", &card[i])
	}

	sereja, dima := 0, 0

	for i, j:=0, n; i<j; {
		if card[i]>card[j-1] {
			sereja+=card[i]
			i++
		} else {
			sereja+=card[j-1]
			j--
		}

		if i<j {
			if card[i]>card[j-1] {
				dima+=card[i]
				i++
			} else {
				dima+=card[j-1]
				j--
			}
		}
	}

	fmt.Println(sereja, dima)
}

package main
import (
	"fmt"
)
func main() {
	var n int
	m:=make([]int,1005)
	fmt.Scan(&n)
	for i:=0;i<n;i++ {
		fmt.Scan(&m[i])
	}
	cnt,x,y,p,q:=0,0,0,0,n-1
	for p<=q {
		if (cnt & 1)==1 {
			if m[p]>m[q] {
				y += m[p]
				p++
			} else {
				y += m[q]
				q--
			}
		} else {
			if m[p]>m[q] {
				x += m[p]
				p++
			} else {
				x += m[q]
				q--
			}
		}
		cnt++
	}
	fmt.Println(x,y)

}

package main

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

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

	var n int64
	var i int64 = 0
	var j int64 = 0

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

	j = n - 1

	cardsString := make([]string, n)
	inputLine2, _ := reader.ReadString('\n')
	cardsString = strings.Split(strings.TrimSpace(inputLine2), " ")
	cards := convertStringToInt64(cardsString)

	var turn int64 = 0
	var sereja int64 = 0
	var dima int64 = 0

	for i = 0; i <= j; i++ {

		for cards[j] > cards[i] {
			if turn % 2 == 0 {
				sereja += cards[j]
			} else {
				dima += cards[j]
			}
			j--
			turn++
		}

		if turn % 2 == 0 {
			sereja += cards[i]
		} else {
			dima += cards[i]
		}

		turn++
	}

	fmt.Println(sereja, dima)
}

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

func quicksort(nums []int, start int, end int) {
	var pivot, swapIndex int

	if end-start <= 1 {
		return
	}
	pivot = nums[start]
	swapIndex = start + 1
	for i := start + 1; i < end; i++ {
		if nums[i] < pivot {
			nums[i], nums[swapIndex] = nums[swapIndex], nums[i]
			swapIndex++
		}
	}
	swapIndex--
	nums[start], nums[swapIndex] = nums[swapIndex], nums[start]
	quicksort(nums, start, swapIndex)
	quicksort(nums, swapIndex+1, end)
}

func main() {
	var nums []int
	var n int
	var scanner *bufio.Scanner
	var e error
	var numsString []string
	var sereja, dima int
	var flag int

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, e = strconv.Atoi(strings.TrimSpace(scanner.Text()))
	if e != nil {
		panic(e)
	}
	scanner.Scan()
	numsString = strings.Split(scanner.Text(), " ")
	nums = make([]int, n)
	for i := 0; i < n; i++ {
		nums[i], e = strconv.Atoi(numsString[i])
		if e != nil {
			panic(e)
		}
	}
	// quicksort(nums, 0, n)
	flag = 1
	for i := n - 1; i > -1; i-- {
		if flag == 1 {
			if nums[0] >= nums[len(nums)-1] {
				sereja = sereja + nums[0]
				nums = nums[1:]
			} else {
				sereja = sereja + nums[len(nums)-1]
				nums = nums[:len(nums)-1]
			}
			flag = 2
		} else {
			if nums[0] >= nums[len(nums)-1] {
				dima = dima + nums[0]
				nums = nums[1:]
			} else {
				dima = dima + nums[len(nums)-1]
				nums = nums[:len(nums)-1]
			}
			flag = 1
		}
	}

	fmt.Printf("%d %d\n", sereja, dima)
}

// 42
// 15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13

package main

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

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

	array := 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
		}
		array[i] = a
	}

	var sereja_dima [2]int
	var i int = 0 // Sereja first
	var head int = 0
	var tail int = n - 1
	for head <= tail {
		if array[head] > array[tail] {
			sereja_dima[i] += array[head]
			head++
		} else {
			sereja_dima[i] += array[tail]
			tail--
		}
		i = (i + 1) % 2
	}

	fmt.Printf("%d %d\n", sereja_dima[0], sereja_dima[1])
}

package main

import "fmt"

func main() {
    var n int
    var a [1005]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    l, r := 0, n-1
    score := [2]int{0,0}
    for i := 0; i < n; i++ {
        if a[l] > a[r] {
            score[i%2] += a[l]
            l++
        } else {
            score[i%2] += a[r]
            r--
        }
    }
    fmt.Println(score[0],score[1])
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	cards := make([]int, n)
	// fmt.Println(n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &cards[i])
	}
	// fmt.Println(cards)
	j := n - 1
	i := 0
	var count int
	var s int
	var d int
	for i <= j {
		// fmt.Println(count, i, j, cards[i], cards[j])
		if cards[i] > cards[j] {
			if count%2 == 0 {
				s += cards[i]
				i++
				count++
			} else {
				d += cards[i]
				i++
				count++
			}
		} else {
			if count%2 == 0 {
				s += cards[j]
				j--
				count++
			} else {
				d += cards[j]
				j--
				count++
			}

		}
	}
	fmt.Println(s, d)
}

package main

import "fmt"

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

	var s, d int
	var start, end int = 0, n - 1
	var i int = 2
	for {
		if start > end {
			break
		}
		if i%2 == 0 {
			if input[start] > input[end] {
				s += input[start]
				start++
			} else {
				s += input[end]
				end--
			}
		} else {
			if input[start] > input[end] {
				d += input[start]
				start++
			} else {
				d += input[end]
				end--
			}
		}
		i++
	}
	fmt.Printf("%d %d\n", s, d)
}

package main

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

func solve(n int, arr []int) {
	seraja, dima, left, right, turn := 0, 0, 0, n-1, 0

	for left <= right {
		if turn%2 == 0 {
			if arr[left] > arr[right] {
				seraja += arr[left]
				left++
			} else {
				seraja += arr[right]
				right--
			}
		} else {
			if arr[left] > arr[right] {
				dima += arr[left]
				left++
			} else {
				dima += arr[right]
				right--
			}
		}
		turn++
	}

	fmt.Println(seraja, dima)
}

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

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

	arr := make([]int, n)

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

	solve(n, arr)
}

package main

import (
    "fmt"
)

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

    sum := make([]int, 2)
    head, tail := 0, n - 1
    for i := 0; i < n; i++ {
        var bigger int
        if card[head] > card[tail] {
            bigger = card[head]
            head++
        } else {
            bigger = card[tail]
            tail --
        }
        sum[i % 2] += bigger
    }
    fmt.Println(sum[0], sum[1])
}

package main

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

func main() {
	var n, inp uint32
	var s, d uint32
	var h []uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint32(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	if n == 1 {
		fmt.Println(inp, 0)
		return
	}
	l := uint32(n - 1)
	i := uint32(0)

	for i <= l && l >= 0 && l < 1001 {
		if h[i] > h[l] {
			s += uint32(h[i])
			i++
		} else {
			s += uint32(h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			i++
		} else {
			d += uint32(h[l])
			l--
		}
		if i == l {
			s += uint32(h[i])
			i++
			break
		}
	}
	fmt.Println(s, d)
}

package main

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

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

	var line string
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")
	list := make([]int, n)

	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
	}

	sereja := 0
	dima := 0
	i := 0
	j := len(list) - 1
	for {
		if list[i] >= list[j] {
			sereja += list[i]
			i++
		} else {
			sereja += list[j]
			j--
		}

		if i > j {
			break
		}

		if list[i] >= list[j] {
			dima += list[i]
			i++
		} else {
			dima += list[j]
			j--
		}

		if i > j {
			break
		}
	}

	fmt.Printf("%d %d\n", sereja, dima)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var cards []int = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}
	i := 0
	j := len(cards) - 1
	turn := true //sereja
	var serejaScore, dimaScore int = 0, 0
	for j >= i {
		if cards[j] > cards[i] {
			if turn {
				serejaScore += cards[j]
			} else {
				dimaScore += cards[j]
			}
			j--
		} else {
			if turn {
				serejaScore += cards[i]
			} else {
				dimaScore += cards[i]
			}
			i++
		}
		turn = !turn
	}
	fmt.Println(serejaScore, dimaScore)
}

package main

import (
	"fmt"
)

func solve(n int, numbers []int) (a, b int) {
	left := 0
	right := n - 1
	a = 0
	b = 0
	for left <= right {
		if numbers[left] > numbers[right] {
			a += numbers[left]
			left++
		} else {
			a += numbers[right]
			right--
		}

		if left > right {
			break
		}

		if numbers[left] > numbers[right] {
			b += numbers[left]
			left++
		} else {
			b += numbers[right]
			right--
		}
	}

	return a, b
}

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

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

	fmt.Println(solve(n, numbers))
}

package main

import (
	"fmt"
)

func main() {
	var numberOfCards int
	var serejaPoints, dimaPoints int
	fmt.Scan(&numberOfCards)
	cardsInt := make([]int, numberOfCards)
	var myInt int
	for index := 0; index < numberOfCards; index++ {
		fmt.Scan(&myInt)
		cardsInt[index] = myInt
	}
	i := 0
	j := numberOfCards - 1
	turns := 1
	for numberOfCards != turns-1 {
		toAdd := 0
		if int(cardsInt[i]) > int(cardsInt[j]) {
			toAdd = cardsInt[i]
			i++
		} else {
			toAdd = cardsInt[j]
			j--
		}
		if turns%2 == 0 {
			dimaPoints += toAdd
		} else {
			serejaPoints += toAdd
		}
		turns++
	}
	fmt.Println(serejaPoints, " ", dimaPoints)
}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var a, b, d, r int
	c := []int{}
	scanf("%d %d\n", &a, &b)
	for i := 0; i < a; i++ {
		scanf("%d", &b)
		c = append(c, b)
	}
	isA := false

	for len(c) > 0 {
		greatest := 0
		if len(c) < 2 {
			greatest = c[0]
			c = []int{}
		} else {
			if c[0] > c[len(c)-1] {
				greatest = c[0]
				c = c[1:len(c)]
			} else {
				greatest = c[len(c)-1]
				c = c[:len(c)-1]
			}
		}

		if !isA {
			d += greatest
			isA = true
		} else {
			r += greatest
			isA = false
		}
	}
	//CODE HERE
	printf("%d %d\n", d, r)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	card := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &card[i])
	}
	var l, r int = 0, n - 1
	var a, b int = 0, 0
	for i := 0; i < n; i++ {
		var temp int = 0
		if card[l] > card[r] {
			temp = card[l]
			l++
		} else {
			temp = card[r]
			r--
		}
		if i&1 == 1 {
			b += temp
		} else {
			a += temp
		}
	}
	fmt.Println(a, b)
}

package main

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

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

	var n int16
	var i int16 = 0
	var j int16 = 0

	inputLine1, _, _ := reader.ReadLine()
	tmp, err := strconv.ParseInt(string(inputLine1[0]), 10, 64)
	if err != nil {
		panic(err)
	}

	n = int16(tmp)

	j = n - 1

	cardsString := make([]string, n)
	inputLine2, _ := reader.ReadString('\n')
	cardsString = strings.Split(strings.TrimSpace(inputLine2), " ")
	cards := convertStringToInt16(cardsString)

	var turn int16 = 0
	var sereja int16 = 0
	var dima int16 = 0

	for i = 0; i <= j; i++ {

		for cards[j] > cards[i] {
			if turn % 2 == 0 {
				sereja += cards[j]
			} else {
				dima += cards[j]
			}
			j--
			turn++
		}

		if turn % 2 == 0 {
			sereja += cards[i]
		} else {
			dima += cards[i]
		}
		turn++
	}

	fmt.Println(sereja, dima)
}

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

package main

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

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

	var n int16
	var i int16 = 0
	var j int16 = 0

	inputLine1, _, _ := reader.ReadLine()
	tmp, err := strconv.ParseInt(string(inputLine1[0]), 10, 64)
	if err != nil {
		panic(err)
	}

	n = int16(tmp)

	j = n - 1

	cardsString := make([]string, n)
	inputLine2, _ := reader.ReadString('\n')
	cardsString = strings.Split(strings.TrimSpace(inputLine2), " ")
	cards := convertStringToInt16(cardsString)

	var turn int16 = 0
	var sereja int16 = 0
	var dima int16 = 0

	fmt.Println(i, j, n)
	for i = 0; i <= j; i++ {

		fmt.Println(cards[j], cards[i])
		for cards[j] > cards[i] {
			if turn % 2 == 0 {
				sereja += cards[j]
			} else {
				dima += cards[j]
			}
			j--
			turn++
		}

		if turn % 2 == 0 {
			sereja += cards[i]
		} else {
			dima += cards[i]
		}
		turn++
	}

	fmt.Println(sereja, dima)
}

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

package main

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

func quicksort(nums []int, start int, end int) {
	var pivot, swapIndex int

	if end-start <= 1 {
		return
	}
	pivot = nums[start]
	swapIndex = start + 1
	for i := start + 1; i < end; i++ {
		if nums[i] < pivot {
			nums[i], nums[swapIndex] = nums[swapIndex], nums[i]
			swapIndex++
		}
	}
	swapIndex--
	nums[start], nums[swapIndex] = nums[swapIndex], nums[start]
	quicksort(nums, start, swapIndex)
	quicksort(nums, swapIndex+1, end)
}

func main() {
	var nums []int
	var n int
	var scanner *bufio.Scanner
	var e error
	var numsString []string
	var sereja, dima int
	var flag int

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, e = strconv.Atoi(strings.TrimSpace(scanner.Text()))
	if e != nil {
		panic(e)
	}
	scanner.Scan()
	numsString = strings.Split(scanner.Text(), " ")
	nums = make([]int, n)
	for i := 0; i < n; i++ {
		nums[i], e = strconv.Atoi(numsString[i])
		if e != nil {
			panic(e)
		}
	}
	quicksort(nums, 0, n)
	// fmt.Println(nums)
	flag = 1
	for i := n - 1; i > -1; i-- {
		if flag == 1 {
			sereja = sereja + nums[i]
			flag = 2
		} else {
			dima = dima + nums[i]
			flag = 1
		}
	}

	fmt.Printf("%d %d\n", sereja, dima)
}

package main

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

func main() {
	var n, inp uint16
	var s, d uint32
	var h []uint16
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	l := n - 1
	i := uint16(0)
	for i <= l {
		if h[i] > h[l] {
			s += uint32(h[i])
			fmt.Println("seroja ", h[i])
			i++
		} else {
			s += uint32(h[l])
			fmt.Println("seroja ", h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			fmt.Println("dima ", h[i])
			i++
		} else {
			d += uint32(h[l])
			fmt.Println("dima ", h[l])
			l--
		}
		if i == l {
			fmt.Println("tentsesen seroja ", h[i])
			s += uint32(h[i])
			i++
		}
	}
	fmt.Println(s, d)
}

package main

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

func main() {
	var n, inp uint16
	var s, d uint32
	var h []uint16
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	if n == 1 {
		return
	}
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	l := n - 1
	i := uint16(0)
	for i <= l {
		if h[i] > h[l] {
			s += uint32(h[i])
			i++
		} else {
			s += uint32(h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			i++
		} else {
			d += uint32(h[l])
			l--
		}
		if i == l {
			s += uint32(h[i])
			i++
		}
	}
	fmt.Println(s, d)
}

package main

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

func main() {
	var n, inp uint16
	var s, d uint32
	var h []uint16
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	l := int16(n - 1)
	i := int16(0)
	for i < int16(n) && l > 0 {
		if h[i] > h[l] {
			s += uint32(h[i])
			i++
		} else {
			s += uint32(h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			i++
		} else {
			d += uint32(h[l])
			l--
		}
		if i == l {
			s += uint32(h[i])
			i++
		}
	}
	fmt.Println(s, d)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	card := make([]int, n + 5)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &card[i])
	}

	sum := make([]int, 2)
	head, tail := 0, n - 1
	for i := 0; i < n; i++ {
		var bigger int
		if card[head] > card[tail] {
			bigger = card[head]
			head++
		} else {
			bigger = card[tail]
			tail --
		}
		sum[i % 2] += bigger
	}
	fmt.Println(sum[0], sum[1])
}


You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according  (for every natural number i). Here point B is symmetric to A according M, if M is the center of the line segment AB. Given index j find the point Mj.

On the first line you will be given an integer n (1 ≤ n ≤ 105), which will be odd, and j (1 ≤ j ≤ 1018), where j is the index of the desired point. The next line contains two space separated integers, the coordinates of M0. After that n lines follow, where the i-th line contain the space separated integer coordinates of the point Ai - 1. The absolute values of all input coordinates will not be greater then 1000.

On a single line output the coordinates of Mj, space separated.

package main

import (
	"fmt"
	"io/ioutil"
	"bytes"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var N, J uint64
	var mx, my int
	fmt.Fscanf(reader, "%d %d\n", &N, &J)
	fmt.Fscanf(reader, "%d %d\n", &mx, &my)
	x := make([]int, N, N)
	y := make([]int, N, N)
	for i := uint64(0);i < N;i ++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}
	for i := uint64(0);i < (J % (2 * N));i ++ {
		mx, my = (2 * x[i % N] - mx), (2 * y[i % N] - my)
	}
	fmt.Printf("%d %d", mx, my)
}

package main

import (
	"fmt"
	"io/ioutil"
	"bytes"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var N, J int
	var mx, my int
	fmt.Fscanf(reader, "%d %d\n", &N, &J)
	fmt.Fscanf(reader, "%d %d\n", &mx, &my)
	x := make([]int, N, N)
	y := make([]int, N, N)
	for i := 0;i < N;i ++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}
	for i := 0;i < (J % (2 * N));i ++ {
		mx, my = (2 * x[i % N] - mx), (2 * y[i % N] - my)
	}
	fmt.Printf("%d %d", mx, my)
}