Let's consider all integers in the range from $$$1$$$ to $$$n$$$ (inclusive).Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of $$$\mathrm{gcd}(a, b)$$$, where $$$1 \leq a < b \leq n$$$.The greatest common divisor, $$$\mathrm{gcd}(a, b)$$$, of two positive integers $$$a$$$ and $$$b$$$ is the biggest integer that is a divisor of both $$$a$$$ and $$$b$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^6$$$).

For each test case, output the maximum value of $$$\mathrm{gcd}(a, b)$$$ among all $$$1 \leq a < b \leq n$$$.

NoteIn the first test case, $$$\mathrm{gcd}(1, 2) = \mathrm{gcd}(2, 3) = \mathrm{gcd}(1, 3) = 1$$$.In the second test case, $$$2$$$ is the maximum possible value, corresponding to $$$\mathrm{gcd}(2, 4)$$$.

package main

import (
  . "fmt"
)

var t int
func main() {
  Scan(&t)
  for tc := 0; tc < t; tc++ {
    var n int
    Scan(&n)
    Println(n/2)
  }
}

package main

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

const delim = '\n'

func gcd(a, b int) int {
    if b == 0 {
        return a
    } else {
        return gcd(b, a % b)
    }
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    firstLine, _ := reader.ReadString(delim)
    t, _ := strconv.Atoi(strings.TrimSpace(firstLine))
    for c := 0; c < t; c++ {
        line, _ := reader.ReadString(delim)
        n, _ := strconv.Atoi(strings.TrimSpace(line))
        fmt.Println(n / 2)
    }
}

package main

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

func main(){
	var t,n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		fmt.Fscan(in,&n)
		fmt.Println(n/2)
	}
}

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 int64
		fmt.Fscan(in, &n)
		fmt.Fprintln(out, n/2)
	}
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		fmt.Println(solve(n))
	}
}

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

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

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

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

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

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

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

	return i
}

func solve(n int) int {
	if n < 4 {
		return 1
	}
	return n / 2
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	//var n, _ = strconv.Atoi(str)

	for i := 0; i < t; i++ {
		step()
	}
}

func step() {
	var n int
	fmt.Scan(&n)
	fmt.Println(n / 2)
}

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.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 & 1 == 1 {
		fmt.Println((n - 1) / 2)
	} else {
		fmt.Println(n  / 2)
	}

}

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

package main

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

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

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

	var t, n int
	t = input()

	for ; t > 0; t-- {
		n = input()

		if n%2 == 0 {
			fmt.Println(n / 2)
		} else {
			fmt.Println((n - 1) / 2)
		}
	}
}

package main

import "fmt"

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

package main

import (
	"fmt"
)

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

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a int
		fmt.Scanf("%d\n", &a)
		c := gcd(a)
		fmt.Println(c)
	}
}

func gcd(n int) int {
	if n % 2 == 0 {
		return n / 2
	}
	return (n-1) / 2
}

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

func main() {
	var t, n int32
	fmt.Scanln(&t)
	for t > 0 {
		t--
		fmt.Scanln(&n)
		if n%2 == 0 {
			fmt.Println(n / 2)
		} else {
			fmt.Println((n - 1) / 2)
		}
	}

}

package main

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

func main() {
	T := ReadInt()
	for t := 0; t < T; t++ {
		fmt.Println(solve(ReadInt()))
	}
}

func solve(a int) int {
	if a%2 == 0 {
		return a / 2
	}
	return solve(a - 1)
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	a, err := strconv.Atoi(Read())
	if err != nil {
		panic(err)
	}
	return a
}

package main

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

var nTest, n int

func gcd(x, y int) int {
	for y != 0 {
		t := y
		y = x % y
		x = t
	}

	return x
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

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

		fmt.Fprintln(out, gcd(n/2, n/2*2))
	}

	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1370A(in io.Reader, out io.Writer) {
	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		Fprintln(out, n/2)
	}
}

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

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)
var reader = bufio.NewReader(os.Stdin)

func readInt() int {
    text, _ := reader.ReadString('\n')
    n, _ := strconv.ParseInt(strings.TrimSpace(text), 0, 32)
    return int(n)
}

func main() {
    n := readInt()
    for i := 0; i < n; i++ {
        cur := readInt()
        fmt.Println(cur / 2)
    }
}

package main

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

func main() {
	maxN := int(1e6)
	g := make([]int, maxN+1)
	for i := 1; i <= maxN; i++ {
		for j := 2*i; j <= maxN; j += i {
			if i > g[j] {
				g[j] = i
			}
		}
	}

	for i := 2; i < maxN; i++ {
		if g[i-1] > g[i] {
			g[i] = g[i-1]
		}
	}

	t := NextInt()
	for t > 0 {
		t--
		n := NextInt()
		fmt.Println(g[n])
	}
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

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

package main

import "fmt"

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

package main

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

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

	var t, n int
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Println(n / 2)
	}
}

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		if n%2 != 0 {
			n--
		}
		if n == 0 {
			n = 2
		}
		con.Println(n / 2)
	}
	return nil
}

package main

import "fmt"

func solve (){
	var n int64
	fmt.Scan(&n)
	fmt.Println(n/2)
}

func main() {
	var tc int64
	fmt.Scan(&tc)
	for tc>0 {
		solve()
		tc--
	}
}

package main

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

const delim = '\n'

func gcd(a, b int) int {
    if b % a == 0 {
        return a
    } else {
        return gcd(b % a, b)
    }
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    firstLine, _ := reader.ReadString(delim)
    t, _ := strconv.Atoi(strings.TrimSpace(firstLine))
    var maxGCD int
    for c := 0; c < t; c++ {
        line, _ := reader.ReadString(delim)
        n, _ := strconv.Atoi(strings.TrimSpace(line))
        maxGCD = 1
        for i := 2; i <= n; i += 2 {
           for j := 2; j < i; j += 2 {
               maxGCD = int(math.Max(float64(maxGCD), float64(gcd(i, j))))
           }
        }
        fmt.Println(maxGCD)
    }
}

package main

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

const delim = '\n'

func gcd(a, b int) int {
    if a % b == 0 {
        return a
    } else {
        return gcd(a % b, b)
    }
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    firstLine, _ := reader.ReadString(delim)
    t, _ := strconv.Atoi(firstLine)
    var maxGCD int
    for c := 0; c < t; c++ {
        line, _ := reader.ReadString(delim)
        n, _ := strconv.Atoi(line)
        maxGCD = 1
        for i := 2; i <= n; i += 2 {
            for j := 2; j < i; j += 2 {
                maxGCD = int(math.Max(float64(maxGCD), float64(gcd(i, j))))
            }
        }
        fmt.Println(maxGCD)
    }
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		fmt.Println(solve(n))
	}
}

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

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

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

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

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

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

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

	return i
}

func solve(n int) int {
	if n < 4 {
		return 1
	}
	// gcd(a, b) <= a (a < b) to make answer max, make gcd(a, b) = a, then b % a == 0,
	var h int
	for 1<<(h+1) <= n {
		h++
	}
	h--
	return 1 << h
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &n)
		fmt.Println(n / 2)
	}
}

package main

import "fmt"

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

package main

import "fmt"

func solve (){
	var n int8
	fmt.Scan(&n)
	fmt.Println(n/2)
}

func main() {
	var tc int64
	fmt.Scan(&tc)
	for tc>0 {
		solve()
		tc--
	}
}

package main

import "fmt"

func solve (){
	var n int64
	fmt.Scan(&n)
	fmt.Println(n/2)
}

func main() {
	solve()
}


You are given $$$n$$$ positive integers $$$a_1, \ldots, a_n$$$, and an integer $$$k \geq 2$$$. Count the number of pairs $$$i, j$$$ such that $$$1 \leq i < j \leq n$$$, and there exists an integer $$$x$$$ such that $$$a_i \cdot a_j = x^k$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 10^5$$$, $$$2 \leq k \leq 100$$$). The second line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$).

Print a single integer — the number of suitable pairs.

package main

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

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

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

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &a[i])
	}

	tot := int64(0)
	mp := make(map[int]int)
	for _, x := range a {
		base := 1
		comp := 1
		for p, e := range factorise(x) {
			if (e % k) != 0 {
				base *= power(p, e%k)
				c := power(p, k-(e%k))
				if comp > inf/c {
					comp = inf
				} else {
					comp *= c
				}
			}
		}
		if comp < inf {
			tot += int64(mp[comp])
		}
		mp[base]++
	}

	fmt.Println(tot)
}

const inf = 1e9

func power(a, b int) int {
	ret := 1
	for i := 1; i <= b; i++ {
		if ret > inf/a {
			return inf
		}
		ret *= a
	}
	return ret
}

func factorise(num int) map[int]int {
	f := make(map[int]int)
	for p := 2; p*p <= num; p++ {
		if num%p != 0 {
			continue
		}
		for num%p == 0 {
			f[p]++
			num /= p
		}
	}
	if num > 1 {
		f[num] = 1
	}
	return f
}

package main

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

const (
	maxn = 100000 + 5
)

var (
	pvisit  = make([]bool, maxn)
	prime   []int
	scanner *bufio.Scanner
)

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

func lineprime() {
	pvisit[1] = true
	for i := 2; i < maxn; i++ {
		if pvisit[i] {
			continue
		}
		prime = append(prime, i)
		for j := 2; i*j < maxn; j++ {
			pvisit[i*j] = true
		}
	}
}

type Node struct {
	p, count int
}

func solve() {
	n := ScanInt()
	k := ScanInt()
	counter := map[int]int{}
	ans := int64(0)
	for i := 0; i < n; i++ {
		val := ScanInt()
		nodes := []Node{}
		for _, p := range prime {
			if p*p > val {
				nodes = append(nodes, Node{val, 1})
				break
			}
			count := 0
			for val%p == 0 {
				val /= p
				count++
			}
			nodes = append(nodes, Node{p, count})
		}
		need_val, true_val := 1, 1
		for _, node := range nodes {
			p, count := node.p, node.count
			if count%k == 0 {
				continue
			}
			for i := 0; i < k-(count%k) && need_val < maxn; i++ {
				need_val *= p
			}
			for i := 0; i < count%k; i++ {
				true_val *= p
			}
		}
		if need_val < maxn {
			ans += int64(counter[need_val])
		}
		if _, find := counter[true_val]; find {
			counter[true_val] += 1
		} else {
			counter[true_val] = 1
		}
	}
	fmt.Printf("%d\n", ans)
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	lineprime()
	solve()
}

package main

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

var p []int = make([]int, 0, 10000)

func prime(n int) {
	for i := 2; i <= n; i++ {
		yes := true
		for j := 0; j < len(p) && p[j]*p[j] <= i; j++ {
			if i%p[j] == 0 {
				yes = false
				break
			}
		}

		if yes {
			p = append(p, i)
		}
	}
}

func toString(n, k int) (string, string) {
	var s1, s2 bytes.Buffer

	for i := 0; p[i]*p[i] <= n; i++ {
		sum := 0
		for ; n%p[i] == 0; n = n / p[i] {
			sum++
		}

		sum = sum % k

		if sum == 0 {
			continue
		}

		s1.WriteString(fmt.Sprintf("%d:%d;", p[i], sum))
		s2.WriteString(fmt.Sprintf("%d:%d;", p[i], k-sum))
	}

	if s1.Len() == 0 && n == 1 {
		s1.WriteString(fmt.Sprintf("%d:%d;", n, 1))
		s2.WriteString(fmt.Sprintf("%d:%d;", n, 1))
	} else if n > 1 {
		s1.WriteString(fmt.Sprintf("%d:%d;", n, 1))
		s2.WriteString(fmt.Sprintf("%d:%d;", n, k-1))
	}

	return s1.String(), s2.String()
}

func main() {
	prime(100001)

	reader := bufio.NewReader(os.Stdin)
	var n, k, num int

	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	ans := int64(0)
	m := make(map[string]int, n)

	for i := 0; i < n; i++ {
		if i+1 != n {
			fmt.Fscanf(reader, "%d", &num)
		} else {
			fmt.Fscanf(reader, "%d\n", &num)
		}

		s1, s2 := toString(num, k)
		// fmt.Println(m)
		// fmt.Println(s1, s2, m[s2])

		ans += int64(m[s2])
		m[s1]++
	}

	fmt.Println(ans)
}

package main

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

const (
	maxn = 100000 + 5
)

var (
	pvisit  = make([]bool, maxn)
	prime   []int
	scanner *bufio.Scanner
)

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

func lineprime() {
	pvisit[1] = true
	for i := 2; i < maxn; i++ {
		if pvisit[i] {
			continue
		}
		prime = append(prime, i)
		for j := 2; i*j < maxn; j++ {
			pvisit[i*j] = true
		}
	}
}

type Node struct {
	p, count int
}

func solve() {
	n := ScanInt()
	k := ScanInt()
	counter := map[int]int{}
	ans := 0
	for i := 0; i < n; i++ {
		val := ScanInt()
		nodes := []Node{}
		for _, p := range prime {
			if p*p > val {
				nodes = append(nodes, Node{val, 1})
				break
			}
			count := 0
			for val%p == 0 {
				val /= p
				count++
			}
			nodes = append(nodes, Node{p, count})
		}
		need_val, true_val := 1, 1
		for _, node := range nodes {
			p, count := node.p, node.count
			if count%k == 0 {
				continue
			}
			for i := 0; i < k-(count%k) && need_val < maxn; i++ {
				need_val *= p
			}
			for i := 0; i < count%k; i++ {
				true_val *= p
			}
		}
		if need_val < maxn {
			ans += counter[need_val]
		}
		if _, find := counter[true_val]; find {
			counter[true_val] += 1
		} else {
			counter[true_val] = 1
		}
	}
	fmt.Printf("%d\n", ans)
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	lineprime()
	solve()
}

package main

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

const (
	maxn = 110000 + 5
)

var (
	scanner *bufio.Scanner
)

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

func pow(x, p int) int {
	result := 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return result
}

func solve() {
	n := ScanInt()
	k := ScanInt()
	pre_x := []int{}
	counter := map[int]int{}
	for i := 1; true; i++ {
		tmp := pow(i, k)
		pre_x = append(pre_x, tmp)
		if tmp >= maxn {
			break
		}
	}
	ans := 0
	for i := 0; i < n; i++ {
		val := ScanInt()
		for _, j := range pre_x {
			if j%val != 0 {
				continue
			}
			if num, find := counter[j/val]; find {
				ans += num
			}
		}
		if _, find := counter[val]; find {
			counter[val] += 1
		} else {
			counter[val] = 1
		}
	}
	fmt.Printf("%d\n", ans)
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	solve()
}

package main

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

const (
	maxn = 100000 + 5
)

var (
	pvisit  = make([]bool, maxn)
	prime   []int
	scanner *bufio.Scanner
)

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

func lineprime() {
	pvisit[1] = false
	for i := 2; i < maxn; i++ {
		if pvisit[i] {
			continue
		}
		prime = append(prime, i)
		for j := 2; i*j < maxn; j++ {
			pvisit[i*j] = true
		}
	}
}

type Node struct {
	p, count int
}

func solve() {
	n := ScanInt()
	k := ScanInt()
	counter := map[int]int{}
	ans := 0
	for i := 0; i < n; i++ {
		val := ScanInt()
		nodes := []Node{}
		for _, p := range prime {
			if p*p > val {
				nodes = append(nodes, Node{val, 1})
				break
			}
			count := 0
			for val%p == 0 {
				val /= p
				count++
			}
			nodes = append(nodes, Node{p, count})
		}
		need_val, true_val := 1, 1
		for _, node := range nodes {
			p, count := node.p, node.count
			if count%k == 0 {
				continue
			}
			for i := 0; i < k-(count%k); i++ {
				need_val *= p
			}
			for i := 0; i < count%k; i++ {
				true_val *= p
			}
		}
		ans += counter[need_val]
		if _, find := counter[true_val]; find {
			counter[true_val] += 1
		} else {
			counter[true_val] = 1
		}
	}
	fmt.Printf("%d\n", ans)
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	lineprime()
	solve()
}

package main

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

var p []int = make([]int, 0, 10000)

func prime(n int) {
	for i := 2; i <= n; i++ {
		yes := true
		for j := 0; j < len(p) && p[j]*p[j] <= i; j++ {
			if i%p[j] == 0 {
				yes = false
				break
			}
		}

		if yes {
			p = append(p, i)
		}
	}
}

func toString(n, k int) (string, string) {
	var s1, s2 bytes.Buffer

	for i := 0; p[i]*p[i] <= n; i++ {
		sum := 0
		for ; n%p[i] == 0; n = n / p[i] {
			sum++
		}

		sum = sum % k

		if sum == 0 {
			continue
		}

		s1.WriteString(fmt.Sprintf("%d:%d;", p[i], sum))
		s2.WriteString(fmt.Sprintf("%d:%d;", p[i], k-sum))
	}

	if s1.Len() == 0 && n == 1 {
		s1.WriteString(fmt.Sprintf("%d:%d;", n, 1))
		s2.WriteString(fmt.Sprintf("%d:%d;", n, 1))
	} else if n > 1 {
		s1.WriteString(fmt.Sprintf("%d:%d;", n, 1))
		s2.WriteString(fmt.Sprintf("%d:%d;", n, k-1))
	}

	return s1.String(), s2.String()
}

func main() {
	prime(100001)

	reader := bufio.NewReader(os.Stdin)
	var n, k, num int

	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	ans := 0
	m := make(map[string]int, n)

	for i := 0; i < n; i++ {
		if i+1 != n {
			fmt.Fscanf(reader, "%d", &num)
		} else {
			fmt.Fscanf(reader, "%d\n", &num)
		}

		s1, s2 := toString(num, k)
		// fmt.Println(m)
		// fmt.Println(s1, s2, m[s2])

		ans += m[s2]
		m[s1]++
	}

	fmt.Println(ans)
}

package main

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

var p []int = make([]int, 0, 1000)

func prime(n int) {
	for i := 2; i <= n; i++ {
		yes := true
		for j := 0; j < len(p) && p[j]*p[j] <= i; j++ {
			if i%p[j] != 0 {
				yes = false
				break
			}
		}

		if yes {
			p = append(p, i)
		}
	}
}

func toString(n, k int) (string, string) {
	var s1, s2 bytes.Buffer

	for i := 0; p[i]*p[i] <= n; i++ {
		sum := 0
		for ; n%p[i] == 0; n = n / p[i] {
			sum++
		}

		sum = sum % k

		if sum == 0 {
			continue
		}

		s1.WriteString(fmt.Sprintf("%d:%d;", p[i], sum))
		s2.WriteString(fmt.Sprintf("%d:%d;", p[i], k-sum))
	}

	if s1.Len() == 0 && n == 1 {
		s1.WriteString(fmt.Sprintf("%d:%d;", n, 1))
		s2.WriteString(fmt.Sprintf("%d:%d;", n, 1))
	} else if n > 1 {
		s1.WriteString(fmt.Sprintf("%d:%d;", n, 1))
		s2.WriteString(fmt.Sprintf("%d:%d;", n, k-1))
	}

	return s1.String(), s2.String()
}

func main() {
	prime(100000)
	reader := bufio.NewReader(os.Stdin)
	var n, k, num int

	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	ans := 0
	m := make(map[string]int, n)

	for i := 0; i < n; i++ {
		if i+1 != n {
			fmt.Fscanf(reader, "%d", &num)
		} else {
			fmt.Fscanf(reader, "%d\n", &num)
		}

		s1, s2 := toString(num, k)
		//fmt.Println(m)
		//fmt.Println(s1, s2, m[s2])
		ans += m[s2]
		m[s1]++
	}

	fmt.Println(ans)
}


You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n integers a0, a1, ..., an - 1 (1 ≤ ai ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

Print the only number — distance between two nearest minimums in the array.

package main

import (
    "fmt"
)

func main() {
    var n, a, mi, i, ans int64
    var arr[100009] int64
    fmt.Scan(&n)
    mi = 10000000000
    a = 0
    ans = 10000000000
    for i = 0; i < n; i++ {
      fmt.Scan(&arr[i])
      if mi > arr[i] {
        mi = arr[i]
      }
    }
    //fmt.Println("min: ", mi)
    // for i = 0; i < n; i++ {
    //   fmt.Print(arr[i], " ")
    // }
    found := false
    for i = 0; i < n; i++ {
      if mi == arr[i] {
        //fmt.Println("Here", i)
        if ans > i-a && found == true {
          ans = i-a
        //  fmt.Println("ans on :", i)
        }
        a = i
        found = true
      }
    }
    fmt.Println(ans)
}

package main

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

func solve() {
	n := readInt()
	m := make(map[int][]int)
	xmin := -1
	for i := 0; i < n; i++ {
		a := readInt()
		if i == 0 {
			xmin = a
		} else {
			if a < xmin {
				xmin = a
			}
		}

		m[a] = append(m[a], i)
	}

	xxmin := 0
	for i := 1; i < len(m[xmin]); i++ {
		d := m[xmin][i] - m[xmin][i-1]
		if i == 1 {
			xxmin = d
		} else if d < xxmin {
			xxmin = d
		}
	}
	fmt.Println(xxmin)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

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

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscanf(in, "%d\n", &n)
	a := make([]uint, n)
	m := uint(math.MaxInt32)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
		if a[i] < m {
			m = a[i]
		}
	}
	d := math.MaxInt32
	lastMin := -1
	for i := 0; i < n; i++ {
		if a[i] == m {
			if lastMin >= 0 && i-lastMin < d {
				d = i - lastMin
			}
			lastMin = i
		}
	}
	fmt.Print(d)
}

package main

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

func main() {
	var n, min, min_i, min_j, latest_i int
	stdin := bufio.NewReader(os.Stdin)

	fmt.Fscan(stdin, &n)
	arr := make([]int, n)
	fmt.Fscan(stdin, &arr[0])
	min = arr[0]
	for i := 1; i < n; i++ {
		fmt.Fscan(stdin, &arr[i])
		if arr[i] < min {
			min = arr[i]
			min_i = i
			min_j = i
			latest_i = i
		} else if arr[i] == min {
			if min_i == latest_i {
				min_j = i
			} else if min_j-min_i > i-latest_i {
				min_i, min_j = latest_i, i
			}
			latest_i = i
		}
	}
	fmt.Println(min_j - min_i)
}

package main

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

func main() {
	var n, x int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscan(stdin, &n)

	distances := make(map[int]int)
	lastIndexes := make(map[int]int)
	minNum := math.MaxInt32

	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &x)
		// update distance
		if lastIdx, ok := lastIndexes[x]; ok {
			distance := i - lastIdx
			if lastDistance, ok := distances[x]; ok {
				if distance < lastDistance {
					distances[x] = distance
				}
			} else {
				distances[x] = distance
			}
		}
		// update last seen indexes
		lastIndexes[x] = i
		// update min num
		if x < minNum {
			minNum = x
		}
	}
	fmt.Println(distances[minNum])
}

package main

import (
	"fmt"
	"math"
)

func main() {
	distances := make(map[int]int)
	lastIndexes := make(map[int]int)
	minNum := math.MaxInt32
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		// update distance
		if lastIdx, ok := lastIndexes[x]; ok {
			distance := i - lastIdx
			if lastDistance, ok := distances[x]; ok {
				if distance < lastDistance {
					distances[x] = distance
				}
			} else {
				distances[x] = distance
			}
		}
		// update last seen indexes
		lastIndexes[x] = i
		// update min num
		if x < minNum {
			minNum = x
		}
	}
	fmt.Println(distances[minNum])
}

package main

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

const max = 1000000000

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

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

	var (
		min = max + 1
		ans = n
		pos = 0
	)

	for i := 0; i < n; i++ {
		var v int
		fmt.Fscan(r, &v)
		if v > min {
			continue
		}
		if v < min {
			min = v
			ans = n
			pos = i
			continue
		}
		if d := i - pos; ans > d {
			ans = d
		}
		pos = i
	}
	fmt.Println(ans)
}

//	URL: http://codeforces.com/contest/911/problem/A
//	PROBLEM RESTATEMENT
//		Given an array of n integers.
//		The minimum element is guaranteed to occur twice.
//		Find the distance between the minimum elements.
//	APPROACH
//		Naive implementation problem - O(n) time.
//	NOTE
//		Scan is bad - too slow! Use bufio instead.

package main

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

func solve(n int, a []int) int {
	minElem := a[0]
	left := 0
	minDistance := 1000000
	for i := 1; i < n; i++ {
		if minElem == a[i] {
			if (i - left) < minDistance {
				minDistance = i - left
			}
			left = i
		} else if a[i] < minElem {
			minElem = a[i]
			left = i
			minDistance = 1000000
		}
	}
	return minDistance
}

func main() {
	var n int
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := range a {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fprintf(writer, "%d\n", solve(n, a))
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextInt64Array()

	dist := map[int]int{}
	lastIndex := map[int]int{}

	mnA := A[0]
	for i := 1; i < N; i++ {
		if mnA > A[i] {
			mnA = A[i]
		}
	}

	mn := N
	for i := 0; i < N; i++ {
		if A[i] != mnA {
			continue
		}
		a := int(A[i])
		if last, ok := lastIndex[a]; ok {
			v, ok2 := dist[a]
			d := i - last
			if !ok2 || d < v {
				dist[a] = d
				if dist[a] < mn {
					mn = dist[a]
				}
			}
		}
		lastIndex[a] = i
	}

	fmt.Println(mn)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import (
	"fmt"
	"os"
)

const max = 100000

func main() {
	var n int
	fmt.Fscan(os.Stdin, &n)

	var (
		min = max + 1
		ans = n
		pos = 0
	)

	for i := 0; i < n; i++ {
		var v int
		fmt.Fscan(os.Stdin, &v)
		if v > min {
			continue
		}
		if v < min {
			min = v
			ans = n
			pos = i
			continue
		}
		if d := i - pos; ans > d {
			ans = d
		}
		pos = i
	}
	fmt.Println(ans)
}

//	URL: http://codeforces.com/contest/911/problem/A
//	PROBLEM RESTATEMENT
//		Given an array of n integers.
//		The minimum element is guaranteed to occur twice.
//		Find the distance between the minimum elements.
//	APPROACH
//		Naive implementation problem - O(n) time.

package main

import "fmt"

func solve(n int, a []int) int {
	minElem := a[0]
	left := 0
	minDistance := 1000000
	for i := 1; i < n; i++ {
		if minElem == a[i] {
			if (i - left) < minDistance {
				minDistance = i - left
			}
			left = i
		} else if a[i] < minElem {
			minElem = a[i]
			left = i
		}
	}
	return minDistance
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	fmt.Println(solve(n, a))
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	dist := map[int]int{}
	lastIndex := map[int]int{}
	mn := N
	for i := 0; i < N; i++ {
		a := A[i]
		if last, ok := lastIndex[a]; ok {
			v, ok2 := dist[a]
			if !ok2 || last-i < v {
				dist[a] = i - last
				if dist[a] < mn {
					mn = dist[a]
				}
			}
		}
		lastIndex[a] = i
	}

	fmt.Println(mn)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	dist := map[int]int{}
	lastIndex := map[int]int{}
	mn := N
	for i := 0; i < N; i++ {
		a := A[i]
		if last, ok := lastIndex[a]; ok {
			v, ok2 := dist[a]
			d := i - last
			if !ok2 || d < v {
				dist[a] = d
				if dist[a] < mn {
					mn = dist[a]
				}
			}
		}
		lastIndex[a] = i
	}

	fmt.Println(mn)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextInt64Array()

	dist := map[int]int{}
	lastIndex := map[int]int{}
	mn := N
	for i := 0; i < N; i++ {
		a := int(A[i])
		if last, ok := lastIndex[a]; ok {
			v, ok2 := dist[a]
			d := i - last
			if !ok2 || d < v {
				dist[a] = d
				if dist[a] < mn {
					mn = dist[a]
				}
			}
		}
		lastIndex[a] = i
	}

	fmt.Println(mn)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers from the set Ui = (ui, 1, ui, 2, ..., ui, |Ui|). Here and below we'll presuppose that the set elements are written in the increasing order.We'll say that the secret is safe if the following conditions are hold:  for any two indexes i, j (1 ≤ i < j ≤ k) the intersection of sets Ui and Uj is an empty set;  the union of sets U1, U2, ..., Uk is set (1, 2, ..., n);  in each set Ui, its elements ui, 1, ui, 2, ..., ui, |Ui| do not form an arithmetic progression (in particular, |Ui| ≥ 3 should hold). Let us remind you that the elements of set (u1, u2, ..., us) form an arithmetic progression if there is such number d, that for all i (1 ≤ i < s) fulfills ui + d = ui + 1. For example, the elements of sets (5), (1, 10) and (1, 5, 9) form arithmetic progressions and the elements of sets (1, 2, 4) and (3, 6, 8) don't.Your task is to find any partition of the set of words into subsets U1, U2, ..., Uk so that the secret is safe. Otherwise indicate that there's no such partition.

The input consists of a single line which contains two integers n and k (2 ≤ k ≤ n ≤ 106) — the number of words in the secret and the number of the Keepers. The numbers are separated by a single space.

If there is no way to keep the secret safe, print a single integer "-1" (without the quotes). Otherwise, print n integers, the i-th of them representing the number of the Keeper who's got the i-th word of the secret. If there are multiple solutions, print any of them.

package main
import (
	"bufio"
	"fmt"
	"os"
)

func main(){
	var n, k, i int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	j:= 1
	fmt.Fscan(in, &n, &k)
	if n<3*k {
		fmt.Print(-1)
		return
	}else{
		for i =1; i<=2*k; i+=2{
			fmt.Fprint(out, j, j, " ")
			j++
		}
		j = 1
		for ;i<=3*k;i++{
			fmt.Fprint(out, j, " ")
			j++
		}
		for ; i<=n;i++{
			fmt.Fprint(out, 1, " ")
		}
	}
		out.Flush()
	// your code goes here
}

// 271C
package main

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

func main() {
	var n, k int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &k)
	if n < k*3 {
		fmt.Print(-1)
		return
	}
	for i := 0; i < k; i++ {
		fmt.Fprintf(out, "%d %d ", i+1, i+1)
	}
	a := 0
	for i := k * 2; i < n; i++ {
		fmt.Fprintf(out, "%d ", a+1)
		a++
		a %= k
	}
	out.Flush()
}

// 271C
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	if n < k*3 {
		fmt.Print(-1)
	} else {
		for ; n > 0; n-- {
			fmt.Printf("%d ", ((n/k)%2+n)%k+1)
		}
	}
}

// 271C
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	if n < k*3 {
		fmt.Print(-1)
	} else {
		for ; n > 0; n-- {
			fmt.Print(((n/k)%2+n)%k + 1)
		}
	}
}

// 271C
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	if n < k*3 {
		fmt.Print(-1)
	} else {
		for ; n >= 0; n-- {
			fmt.Printf("%d ", ((n/k)%2+n)%k+1)
		}
	}
}

// 271C
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	if n < k*3 {
		fmt.Print(-1)
	} else {
		for ; n < 0; n++ {
			fmt.Printf("%d ", ((n/k)%2+n)%k+1)
		}
	}
}


You are given two arrays $$$a$$$ and $$$b$$$, both of length $$$n$$$.You can perform the following operation any number of times (possibly zero): select an index $$$i$$$ ($$$1 \leq i \leq n$$$) and swap $$$a_i$$$ and $$$b_i$$$.Let's define the cost of the array $$$a$$$ as $$$\sum_{i=1}^{n} \sum_{j=i + 1}^{n} (a_i + a_j)^2$$$. Similarly, the cost of the array $$$b$$$ is $$$\sum_{i=1}^{n} \sum_{j=i + 1}^{n} (b_i + b_j)^2$$$.Your task is to minimize the total cost of two arrays.

Each test case consists of several test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 40$$$) — the number of test cases. The following is a description of the input data sets. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the length of both arrays. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$) — elements of the first array. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \leq b_i \leq 100$$$) — elements of the second array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$.

For each test case, print the minimum possible total cost.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		ans, maxW := 0, 0
		a := make([][2]int, n)
		for i := range a {
			Fscan(in, &a[i][0])
			ans += a[i][0] * a[i][0]
			maxW += a[i][0]
		}
		for i := range a {
			Fscan(in, &a[i][1])
			ans += a[i][1] * a[i][1]
			maxW += a[i][1]
		}
		if n == 1 {
			Fprintln(out, 0)
			continue
		}
		dp := make([]bool, maxW+1)
		dp[0] = true
		for _, g := range a {
		next:
			for j := maxW; j >= 0; j-- {
				for _, w := range g {
					if w <= j && dp[j-w] {
						dp[j] = true
						continue next
					}
				}
				dp[j] = false
			}
		}
		ans *= n - 2
		mi, miv := int(1e9), 0
		for v, b := range dp {
			if b {
				d := abs(maxW - 2*v)
				if d < mi {
					mi, miv = d, v
				}
			}
		}
		Fprintln(out, ans+miv*miv+(maxW-miv)*(maxW-miv))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637D(_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)
		ans, maxW := 0, 0
		a := make([][2]int, n)
		for i := range a {
			Fscan(in, &a[i][0])
			ans += a[i][0] * a[i][0]
			maxW += a[i][0]
		}
		for i := range a {
			Fscan(in, &a[i][1])
			ans += a[i][1] * a[i][1]
			maxW += a[i][1]
		}
		if n == 1 {
			Fprintln(out, 0)
			continue
		}
		dp := make([]bool, maxW+1)
		dp[0] = true
		for _, g := range a {
		next:
			for j := maxW; j >= 0; j-- {
				for _, w := range g {
					if w <= j && dp[j-w] {
						dp[j] = true
						continue next
					}
				}
				dp[j] = false
			}
		}
		ans *= n - 2
		mi, miv := int(1e9), 0
		for v, b := range dp {
			if b {
				d := abs(maxW - 2*v)
				if d < mi {
					mi, miv = d, v
				}
			}
		}
		Fprintln(out, ans+miv*miv+(maxW-miv)*(maxW-miv))
	}
}

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

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

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

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

package main

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

var (

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

func abs(a, b int) int {

	if a < b {

		return b - a
	}
	return a - b
}

func min(a, b int) int {

	if a < b {

		return a
	}

	return b
}

func solve(n int) {

	var (

		a []int
		b []int
		c = make([]bool, 10001)
		sumSquare = 0
		sum = 0
		sumAbs = 0
		absMin = 0
	)

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

		var x int
		fmt.Fscan(in, &x)
		a = append(a, x)
		sum += x
		sumSquare += x * x
	}

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

		var x int
		fmt.Fscan(in, &x)
		b = append(b, abs(x, a[i]))
		sum += x
		sumSquare += x * x
		sumAbs += b[i]
		absMin = sumAbs
	}

	if n <= 1 {

		fmt.Fprintln(out, 0)
		return
	}

	sort.Slice(b, func(i, j int) bool {

		return b[i] < b[j]
	})

	c[0] = true
	for i := 0; i < n; i++ {

		for j := 10000; j > 0; j-- {

			if j >= b[i] && c[j - b[i]] {

				c[j] = true
				absMin = min(absMin, abs(sumAbs, 2 * j))
			}
		}
	}

	fmt.Fprintln(out, sumSquare * (n - 2) + (sum * sum + absMin * absMin) / 2)
}

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"
	"io"
	"math"
	"os"
)

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

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

	casecnt, n := 0, 0
	Fscan(in, &casecnt)
	for ; casecnt > 0; casecnt-- {
		var ans uint64
		Fscan(in, &n)
		a, b, suf := make([]uint64, n), make([]uint64, n), make([]uint64, n+1)
		for i := range a {
			Fscan(in, &a[i])
			ans += uint64((n - 1)) * (a[i] * a[i])
		}
		for i := range b {
			Fscan(in, &b[i])
			ans += uint64((n - 1)) * (b[i] * b[i])
		}
		for i := n - 1; i >= 0; i-- { //求后缀和(a，b数组)
			suf[n-i] = suf[n-i-1] + a[i] + b[i]
		}
		//(ai+aj)^2 = ai^2+2aiaj+aj^2
		//ai^2 + aj^2固定的，无论是否交换都是不变的
		//我们只要对2(ai)*(aj)求最小值即可，先求一半也就是(ai)*(aj)

		//dp数组dp[i][j]表示 数组前i个数(倒数)的后缀和为j时(指的是数组a的后缀和)，可以形成的最小权重和是多少(a+b的权重和)
		dp := [101][11000]uint64{}
		for i := range dp {
			for j := range dp[i] {
				dp[i][j] = math.MaxUint32
			}
		}
		dp[0][0] = 0
		for i := 1; i <= n; i++ {
			na, nb := uint64(a[n-i]), uint64(b[n-i])
			for j := uint64(0); j <= 10000; j++ {
				//对于一个元素要么调换位置要么不调换位置
				//不调换位置
				if j >= na {
					dp[i][j] = min(dp[i][j], dp[i-1][j-na]+na*(j-na)+nb*(suf[i-1]-(j-na)))
				}
				//调换位置
				if j >= nb {
					dp[i][j] = min(dp[i][j], dp[i-1][j-nb]+nb*(j-nb)+na*(suf[i-1]-(j-nb)))
				}
			}
		}
		tmp := uint64(math.MaxUint32)
		for i := range dp[n] {
			tmp = min(tmp, dp[n][i])
		}
		ans += 2 * tmp
		//计算结果
		Println(ans)
	}
}

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

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

func sq(a int) int {
	return a * a
}

// ----------------------------- TEMPLATE END ----------------------------------

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		scan(&n)
		a := make([]int, n)
		b := make([]int, n)
		totalSum := 0
		for i := 0; i < n; i++ {
			scan(&a[i])
			totalSum += a[i]
		}
		for i := 0; i < n; i++ {
			scan(&b[i])
			totalSum += b[i]
		}

		dp := make([][]byte, n+1)
		for i := 0; i <= n; i++ {
			dp[i] = make([]byte, totalSum+1)
		}
		dp[n][0] = 1
		for i := n - 1; i >= 0; i-- {
			for j := totalSum; j >= 0; j-- {
				if dp[i+1][j] != 0 {
					dp[i][j+a[i]] = 'A'
					dp[i][j+b[i]] = 'B'
				}
			}
		}
		sumA := totalSum / 2
		for dp[0][sumA] == 0 {
			sumA--
		}
		for i := 0; i < n; i++ {
			if dp[i][sumA] == 'A' {
				sumA -= a[i]
			} else {
				sumA -= b[i]
				a[i], b[i] = b[i], a[i]
			}
		}

		ans := 0
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				ans += sq(a[i]+a[j]) + sq(b[i]+b[j])
			}
		}
		printf("%d\n", ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637D(_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)
		ans, maxW := 0, 0
		a := make([][2]int, n)
		for i := range a {
			Fscan(in, &a[i][0])
			ans += a[i][0] * a[i][0]
			maxW += a[i][0]
		}
		for i := range a {
			Fscan(in, &a[i][1])
			ans += a[i][1] * a[i][1]
			maxW += a[i][1]
		}
		if n == 1 {
			Fprintln(out, 0)
			continue
		}
		dp := make([]int, maxW+1)
		for _, g := range a {
			for j := maxW; j > 0; j-- {
				for _, v := range g {
					if v <= j {
						dp[j] = max(dp[j], dp[j-v]+1)
					}
				}
			}
		}
		ans *= n - 2
		mi, miv := int(1e9), 0
		for v, c := range dp {
			if c == n {
				d := abs(maxW - 2*v)
				if d < mi {
					mi, miv = d, v
				}
			}
		}
		Fprintln(out, ans+miv*miv+(maxW-miv)*(maxW-miv))
	}
}

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

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1637D(_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)
		sa, sb := 0, 0
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			sa += a[i]
		}
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
			sb += b[i]
		}
		for {
			minD := int(1e9)
			p := -1
			for i, v := range a {
				w := b[i]
				if v == w {
					continue
				}
				if v > w {
					if sa-v > sb-w {
						d := abs(sa - sb - (v-w)*2)
						if d < minD {
							minD, p = d, i
						}
					}
				} else {
					if sa-v < sb-w {
						d := abs(sb - sa - (w-v)*2)
						if d < minD {
							minD, p = d, i
						}
					}
				}
			}
			if p < 0 {
				break
			}
			v, w := a[p], b[p]
			sa += w - v
			sb += v - w
			a[p], b[p] = w, v
		}

		ans := 0
		for i, v := range a {
			for j, w := range a[:i] {
				ans += (v+w)*(v+w) + (b[i]+b[j])*(b[i]+b[j])
			}
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

var (

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

func abs(a, b int) int {

	if a < b {

		return b - a
	}
	return a - b
}

func min(a, b int) int {

	if a < b {

		return a
	}

	return b
}

func solve(n int) {

	var (

		a []int
		b []int
		c = make([][]bool, n + 1)
		sumSquare = 0
		sum = 0
		sumAbs = 0
		absMin = 0
	)
	c[0] = make([]bool, 10001)
	for i := 0; i < n; i++ {

		var x int
		fmt.Fscan(in, &x)
		a = append(a, x)
		sum += x
		sumSquare += x * x
		c[i + 1] = make([]bool, 10001)
	}

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

		var x int
		fmt.Fscan(in, &x)
		b = append(b, abs(x, a[i]))
		sum += x
		sumSquare += x * x
		sumAbs += b[i]
		absMin = sumAbs
	}

	if n <= 1 {

		fmt.Fprintln(out, 0)
		return
	}

	sort.Slice(b, func(i, j int) bool {

		return b[i] < b[j]
	})

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

		c[i][0] = true
	}

	for i := 1; i < 10001; i++ {

		for j := 0; j < n; j++ {

			if i >= b[j] && c[j][i - b[j]] {

				c[j + 1][i] = true
				absMin = min(absMin, abs(sumAbs, 2 * i))
			}
		}
	}

	fmt.Fprintln(out, sumSquare * (n - 2) + (sum * sum + absMin * absMin) / 2)
}

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

var (

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

func abs(a, b int) int {

	if a < b {

		return b - a
	}
	return a - b
}

func min(a, b int) int {

	if a < b {

		return a
	}

	return b
}

func solve(n int) {

	var (

		a []int
		b []int
		c = make([]bool, 10001)
		sumSquare = 0
		sum = 0
		sumAbs = 0
		absMin = 0
	)

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

		var x int
		fmt.Fscan(in, &x)
		a = append(a, x)
		sum += x
		sumSquare += x * x
	}

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

		var x int
		fmt.Fscan(in, &x)
		b = append(b, abs(x, a[i]))
		sum += x
		sumSquare += x * x
		sumAbs += b[i]
		absMin = sumAbs
	}

	if n <= 1 {

		fmt.Fprintln(out, 0)
		return
	}

	sort.Slice(b, func(i, j int) bool {

		return b[i] < b[j]
	})

	c[0] = true
	for i := 1; i < 10001; i++ {

		c[i] = false
		for j := 0; j < n; j++ {

			if i >= b[j] && c[i - b[j]] {

				c[i] = true
				absMin = min(absMin, abs(sumAbs, 2 * i))
			}
		}
	}

	fmt.Fprintln(out, sumSquare * (n - 2) + (sum * sum + absMin * absMin) / 2)
}

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


Nauuo is a girl who loves playing chess.One day she invented a game by herself which needs $$$n$$$ chess pieces to play on a $$$m\times m$$$ chessboard. The rows and columns are numbered from $$$1$$$ to $$$m$$$. We denote a cell on the intersection of the $$$r$$$-th row and $$$c$$$-th column as $$$(r,c)$$$.The game's goal is to place $$$n$$$ chess pieces numbered from $$$1$$$ to $$$n$$$ on the chessboard, the $$$i$$$-th piece lies on $$$(r_i,\,c_i)$$$, while the following rule is satisfied: for all pairs of pieces $$$i$$$ and $$$j$$$, $$$|r_i-r_j|+|c_i-c_j|\ge|i-j|$$$. Here $$$|x|$$$ means the absolute value of $$$x$$$.However, Nauuo discovered that sometimes she couldn't find a solution because the chessboard was too small.She wants to find the smallest chessboard on which she can put $$$n$$$ pieces according to the rules.She also wonders how to place the pieces on such a chessboard. Can you help her?

The only line contains a single integer $$$n$$$ ($$$1\le n\le 1000$$$) — the number of chess pieces for the game.

The first line contains a single integer — the minimum value of $$$m$$$, where $$$m$$$ is the length of sides of the suitable chessboard. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$r_i$$$ and $$$c_i$$$ ($$$1\le r_i,c_i\le m$$$) — the coordinates of the $$$i$$$-th chess piece. If there are multiple answers, print any.

NoteIn the first example, you can't place the two pieces on a $$$1\times1$$$ chessboard without breaking the rule. But you can place two pieces on a $$$2\times2$$$ chessboard like this:In the second example, you can't place four pieces on a $$$2\times2$$$ chessboard without breaking the rule. For example, if you place the pieces like this:then $$$|r_1-r_3|+|c_1-c_3|=|1-2|+|1-1|=1$$$, $$$|1-3|=2$$$, $$$1<2$$$; and $$$|r_1-r_4|+|c_1-c_4|=|1-2|+|1-2|=2$$$, $$$|1-4|=3$$$, $$$2<3$$$. It doesn't satisfy the rule.However, on a $$$3\times3$$$ chessboard, you can place four pieces like this:

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	m := n/2 + 1
	fmt.Println(m)
	for i := 0; i < n; i++ {
		fmt.Println(i/2+1, i/2+1+i%2)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	m := 2*((n-1)/2) + 1
	if n == 2 {
		m = 1
	}
	fmt.Println(m)
	for i := 0; i < n; i++ {
		fmt.Println(2*(i/2)+1, (i%2)+1)
		// fmt.Println(check(i, 2*(i/2), (i % 2)))
	}
}

func check(i, r, c int) bool {
	return r+c >= i
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	m := 2*((n-1)/2) + 1
	fmt.Println(m)
	for i := 0; i < n; i++ {
		fmt.Println(2*(i/2)+1, (i%2)+1)
		// fmt.Println(check(i, 2*(i/2), (i % 2)))
	}
}

func check(i, r, c int) bool {
	return r+c >= i
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	m := 2*((n-1)/2) + 1
	if n == 2 {
		m = 2
	}
	fmt.Println(m)
	for i := 0; i < n; i++ {
		fmt.Println(2*(i/2)+1, (i%2)+1)
		// fmt.Println(check(i, 2*(i/2), (i % 2)))
	}
}

func check(i, r, c int) bool {
	return r+c >= i
}


In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.Sticks with lengths a1, a2, a3 and a4 can make a rectangle if the following properties are observed:  a1 ≤ a2 ≤ a3 ≤ a4  a1 = a2  a3 = a4 A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7.Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?

The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks. The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks.

The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.

package main

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

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

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

	n := nextInt()
	sticks := make([]int64, 1000001)
	var area, last int64 = 0, -1

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

	for i := int64(len(sticks)-1); i > 0; i-- {
		if sticks[i] == 0 {
			continue
		} else if sticks[i]%2 != 0 {
			sticks[i]--

			if sticks[i-1] > 0 {
				sticks[i-1]++
			}
		}

		// println(i, sticks[i], area, last)
		if sticks[i] >= 2 && last != -1 {
			area += i*last
			last = -1
			sticks[i] -= 2
		}

		area += sticks[i]/4*i*i
		sticks[i] %= 4

		if sticks[i] > 0 {
			last = i
		}
		// println(i, sticks[i], area, last)
	}

	println(area)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

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

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

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
    "sort"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = nextInt()
    }
    sort.Ints(a)
    var sum int64
    var l int64
    for i := n - 1; i > 0; i-- {
        if l == 0 && a[i] - a[i - 1] < 2 {
            l = int64(a[i - 1])
            i--
        } else if l != 0 && a[i] - a[i - 1] < 2 {
            sum += l * int64(a[i - 1])
            i--
            l = 0
        }
    }
    fmt.Fprintln(out, sum)
}


Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary. Help Vasya find a point that would meet the described limits.

The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). It is guaranteed that all given squares are distinct.

In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.  If there is no answer, print "-1" (without the quotes).

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
	"sort"
)

func main() {
	var n,k int
	fmt.Scan(&n,&k)
	a := make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	if k>n {
		fmt.Println("-1")
	} else {
		fmt.Printf("%d 0",a[n-k])
	}
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var n,k int
    fmt.Scan(&n,&k)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    if k > n {
        fmt.Println(-1)
    } else {
        fmt.Println(a[len(a)-k],a[len(a)-k])
    }
}

// 263B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	a := make([]int, 55)
	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	x := len(a)
	if k <= n {
		fmt.Printf("%d %d\n", a[x-k], a[x-k])
	} else {
		fmt.Println(-1)
	}
}

// 263B-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, k int
    fmt.Scan(&n, &k)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Sort(sort.IntSlice(a))
    var idx int
    idx = n - k
    if idx >= 0 {
        fmt.Print(a[idx])
        fmt.Print(" ")
        fmt.Print(a[idx])
        fmt.Println()
    } else {
        fmt.Println("-1")
    }
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var n,z int
    fmt.Scan(&n,&z)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    if z > n {
        fmt.Println(-1)
    } else {
        y:=a[len(a)-z]
        x:=a[len(a)-z]
        fmt.Println(y,x)

    }
}

// 263B-mic
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.IntSlice(a))
	fmt.Println(a)
	var idx int
	idx = n - k
	fmt.Println(idx)
	if idx >= 0 {
		fmt.Print(a[idx])
		fmt.Print(" ")
		fmt.Print(a[idx])
		fmt.Println()
	} else {
		fmt.Println("-1")
	}
}

// 263B-mic
package main

import (
    "fmt"
    "sort"
)

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

    var idx int
    idx = n - k
    if idx >= 0 {
        fmt.Print(a[idx])
        fmt.Print(" ")
        fmt.Print(a[idx])
        fmt.Println()
    } else {
        fmt.Println("-1")
    }
}


Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).  The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points. The techniques are given in chronological order.

If the first wrestler wins, print string "first", otherwise print "second"

NoteSequence x  =  x1x2... x|x| is lexicographically larger than sequence y  =  y1y2... y|y|, if either |x|  >  |y| and x1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r (r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr and xr  +  1  >  yr  +  1.We use notation |a| to denote length of sequence a.

package main

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

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

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

	n := nextInt()
	isFirstWin, isSecondPerform := true, false
	var point1, point2, a int64 = 0, 0, 0
	// seq1, seq2 := make([]rune,0), make([]rune, 0)
	v1, v2 := make([]int64, 0), make([]int64, 0)
	for i := 0; i < n; i++ {
		a = nextInt64()

		if i == n - 1 && a < 0 {
			 isSecondPerform = true
		}

		if a > 0 {
			point1 += a
			v1 = append(v1, a)
			// seq1 = append(seq1, []rune(strconv.FormatInt(a, 10))...)
		} else {
			a = -a
			point2 += a
			v2 = append(v2, a)
			// seq2 = append(seq2, []rune(strconv.FormatInt(a, 10))...)
		}
	}

	if point1 < point2 {
		isFirstWin = false
	} else if point1 == point2 {
		// if string(seq1) < string(seq2) {
		// 	isFirstWin = false
		// } else if string(seq1) == string(seq2) && isSecondPerform {
		// 	isFirstWin = false
		// }
		minLen := len(v1)

		if len(v1) > len(v2) {
			minLen = len(v2)
		}

		i := 0

		for ; i < minLen; i++ {
			if v1[i] < v2[i] {
				isFirstWin = false
				break
			} else if v1[i] > v2[i] {
				isFirstWin = true
				break
			}
		}

		if i == minLen {
			if len(v1) < len(v2) {
				isFirstWin = false
			} else if len(v1) == len(v2) {
				if isSecondPerform {
					isFirstWin = false
				}
			}
		}
	}
	// println(string(seq1) < string(seq2))
	if isFirstWin {
		println("first")
	} else {
		println("second")
	}

	// println(point1, point2)
	// println(string(seq1), string(seq2))
}

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 nextInt64() int64 {
	n, err := strconv.ParseInt(next(), 0, 64)
	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...)
}

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n                                       int
	p1                                      []int64
	p2                                      []int64
	len1                                    int
	len2                                    int
	score_winner, order_winner, last_winner int
	result                                  int
)

func in() {
	fmt.Fscan(input, &n)
	p1 = make([]int64, n)
	p2 = make([]int64, n)
	len1, len2 = 0, 0
	var s int64
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s)
		var p *[]int64
		var l *int
		if i == n-1 { // last point
			if s > 0 {
				last_winner = 1
			} else {
				last_winner = 2
			}
		}
		if s > 0 {
			p = &p1
			l = &len1
		} else {
			p = &p2
			l = &len2
			s *= -1
		}
		(*p)[*l] = s
		*l += 1
	}
}

func out() {
	var winner int
	if score_winner > 0 {
		winner = score_winner
	} else if order_winner > 0 {
		winner = order_winner
	} else {
		winner = last_winner
	}
	if winner == 1 {
		fmt.Fprintln(output, "first")
	} else {
		fmt.Fprintln(output, "second")
	}
	defer output.Flush()
}

func run() {
	var l int
	if len1 > len2 {
		l = len1
	} else {
		l = len2
	}
	var s1, s2 int64 = 0, 0
	for i := 0; i < l; i++ {
		s1 += p1[i]
		s2 += p2[i]
		if order_winner == 0 && p1[i] > p2[i] {
			order_winner = 1
		} else if order_winner == 0 && p2[i] > p1[i] {
			order_winner = 2
		}
	}
	if s1 > s2 {
		score_winner = 1
	} else if s2 > s1 {
		score_winner = 2
	}
}

func main() {
	in()
	run()
	out()
}

package main

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

var readWriter = bufio.NewReadWriter(
	bufio.NewReader(os.Stdin),
	bufio.NewWriter(os.Stdout))

func sum(a []int64) (b int64) {
	for i := 0; i < len(a); i++ {
		b += a[i]
	}
	return
}

func lexicographyCompare(a, b []int64) int {
	var n int

	if len(a) > len(b) {
		n = len(b)
	} else {
		n = len(a)
	}

	for i := 0; i < n; i++ {
		if a[i] > b[i] {
			return 1
		} else if a[i] < b[i] {
			return -1
		}
	}

	return 0
}

func main() {
	defer readWriter.Flush()

	var n int
	var a int64
	var xs, ys []int64
	var last string

	const FIRST, SECOND string = "first", "second"

	fmt.Fscan(readWriter, &n)

	for i := 0; i < n; i++ {
		fmt.Fscan(readWriter, &a)

		if a > 0 {
			xs = append(xs, a)
		} else {
			ys = append(ys, -a)
		}
	}

	if a > 0 {
		last = FIRST
	} else {
		last = SECOND
	}

	if sum(xs) > sum(ys) {
		fmt.Fprintln(readWriter, FIRST)
	} else if sum(xs) < sum(ys) {
		fmt.Fprintln(readWriter, SECOND)
	} else {
		result := lexicographyCompare(xs, ys)
		if result > 0 {
			fmt.Fprintln(readWriter, FIRST)
		} else if result < 0 {
			fmt.Fprintln(readWriter, SECOND)
		} else {
			fmt.Fprintln(readWriter, last)
		}
	}
}

package main

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

var readWriter = bufio.NewReadWriter(
	bufio.NewReader(os.Stdin),
	bufio.NewWriter(os.Stdout))

func sum(a []int64) (b int64) {
	for i := 0; i < len(a); i++ {
		b += a[i]
	}
	return
}

func lexicographyCompare(a, b []int64) int {
	var n int

	if len(a) > len(b) {
		n = len(b)
	} else {
		n = len(a)
	}

	for i := 0; i < n; i++ {
		if a[i] > b[i] {
			return 1
		} else if a[i] < b[i] {
			return -1
		}
	}

	return 0
}

func main() {
	defer readWriter.Flush()

	var n int
	var a int64
	var xs, ys []int64
	var last string

	const FIRST, SECOND string = "first", "second"

	fmt.Fscan(readWriter, &n)

	for i := 0; i < n; i++ {
		fmt.Fscan(readWriter, &a)

		if a > 0 {
			xs = append(xs, a)
		} else {
			ys = append(ys, -a)
		}
	}

	if a > 0 {
		last = FIRST
	} else {
		last = SECOND
	}

	var sumOfXs, sumOfYs int64 = sum(xs), sum(ys)

	if sumOfXs > sumOfYs {
		fmt.Fprintln(readWriter, FIRST)
	} else if sumOfXs < sumOfYs {
		fmt.Fprintln(readWriter, SECOND)
	} else {
		result := lexicographyCompare(xs, ys)
		if result > 0 {
			fmt.Fprintln(readWriter, FIRST)
		} else if result < 0 {
			fmt.Fprintln(readWriter, SECOND)
		} else {
			fmt.Fprintln(readWriter, last)
		}
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n := nextInt()
	var t [200010]int64 // techniques
	for i := 0; i < n; i++ {
		t[i] = nextLong()
	}

	a, b := make([]int64, 0, 200010), make([]int64, 0, 200010)
	for i := 0; i < n; i++ {
		if t[i] > 0 {
			a = append(a, t[i])
		} else {
			b = append(b, -t[i])
		}
	}

	sameSequence := func(x, y []int64) bool {
		n := len(x)
		if n != len(y) {
			return false
		}
		for i := 0; i < n; i++ {
			if x[i] != y[i] {
				return false
			}
		}
		return true
	}

	if sameSequence(a, b) {
		if t[n-1] > 0 {
			fmt.Println("first")
		} else {
			fmt.Println("second")
		}
		return
	}

	sum := func(x []int64) (z int64) {
		n := len(x)
		for i := 0; i < n; i++ {
			z += x[i]
		}
		return
	}

	if sum(a) == sum(b) {
		i, n, m := 0, len(a), len(b)
		for {
			switch {
			case i >= m:
				fmt.Println("first")
				return
			case i >= n:
				fmt.Println("second")
				return
			case a[i] > b[i]:
				fmt.Println("first")
				return
			case a[i] < b[i]:
				fmt.Println("second")
				return
			default:
				i++
			}
		}
	}

	if sum(a) > sum(b) {
		fmt.Println("first")
	} else {
		fmt.Println("second")
	}
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, 0)
    b := make([]int, 0)
    var suma int64
    var sumb int64
    latest := 0
    for i := 0; i < n; i++ {
        x := nextInt()
        if (x > 0) {
            a = append(a, x)
            suma += int64(x)
            latest = 1
        } else {
            b = append(b, -x)
            sumb += int64(-x)
            latest = 2
        }
    }

    if suma > sumb {
        fmt.Fprintln(out, "first")
    } else if suma < sumb {
        fmt.Fprintln(out, "second")
    } else {
        n = len(a)
        if n > len(b) {
            n = len(b)
        }
        for i := 0; i < n; i++ {
            if a[i] > b[i] {
                fmt.Fprintln(out, "first")
                return
            } else if a[i] < b[i] {
                fmt.Fprintln(out, "second")
                return
            }
        }
        if latest == 1 {
            fmt.Fprintln(out, "first")
        } else {
            fmt.Fprintln(out, "second")
        }
    }
}

package main

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

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

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

	n := nextInt()
	isFirstWin, isSecondPerform := true, false
	var point1, point2, a int64 = 0, 0, 0
	seq1, seq2 := make([]rune,0), make([]rune, 0)

	for i := 0; i < n; i++ {
		a = nextInt64()

		if i == n - 1 && a < 0 {
			 isSecondPerform = true
		}

		if a > 0 {
			point1 += a

			seq1 = append(seq1, []rune(strconv.FormatInt(a, 10))...)
		} else {
			a = -a

			point2 += a
			seq2 = append(seq2, []rune(strconv.FormatInt(a, 10))...)
		}
	}

	if point1 < point2 {
		isFirstWin = false
	} else if point1 == point2 {
		if string(seq1) < string(seq2) {
			isFirstWin = false
		} else if string(seq1) == string(seq2) && isSecondPerform {
			isFirstWin = false
		}
	}

	if isFirstWin {
		println("first")
	} else {
		println("second")
	}

	// println(point1, point2)
	// println(string(seq1), string(seq2))
}

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 nextInt64() int64 {
	n, err := strconv.ParseInt(next(), 0, 64)
	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...)
}

package main

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

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

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

	n := nextInt()
	isFirstWin, isSecondPerform := true, false
	var point1, point2, a int64 = 0, 0, 0
	seq1, seq2 := make([]rune,0), make([]rune, 0)

	for i := 0; i < n; i++ {
		a = nextInt64()

		if i == n - 1 && a < 0 {
			 isSecondPerform = true
		}

		if a > 0 {
			point1 += a

			seq1 = append(seq1, []rune(strconv.FormatInt(a, 10))...)
		} else {
			a = -a

			point2 += a
			seq2 = append(seq2, []rune(strconv.FormatInt(a, 10))...)
		}
	}

	if point1 < point2 {
		isFirstWin = false
	} else if point1 == point2 {
		if string(seq1) > string(seq2) {
			isFirstWin = false
		} else if string(seq1) == string(seq2) && isSecondPerform {
			isFirstWin = false
		}
	}
	// println(string(seq1) > string(seq2))
	if isFirstWin {
		println("first")
	} else {
		println("second")
	}

	// println(point1, point2)
	// println(string(seq1), string(seq2))
}

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 nextInt64() int64 {
	n, err := strconv.ParseInt(next(), 0, 64)
	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...)
}

package main

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

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

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

	n := nextInt()
	isFirstWin, isSecondPerform := true, false
	var point1, point2, a int64 = 0, 0, 0
	seq1, seq2 := make([]rune,0), make([]rune, 0)

	for i := 0; i < n; i++ {
		a = nextInt64()

		if i == n - 1 && a < 0 {
			 isSecondPerform = true
		}

		if a > 0 {
			point1 += a

			seq1 = append(seq1, []rune(strconv.FormatInt(a, 10))...)
		} else {
			a = -a

			point2 += a
			seq2 = append(seq2, []rune(strconv.FormatInt(a, 10))...)
		}
	}

	if point1 < point2 {
		isFirstWin = false
	} else if point1 == point2 {
		if string(seq1) < string(seq2) {
			isFirstWin = false
		} else if string(seq1) == string(seq2) && isSecondPerform {
			isFirstWin = false
		}
	}
	// println(string(seq1) > string(seq2))
	if isFirstWin {
		println("first")
	} else {
		println("second")
	}

	// println(point1, point2)
	// println(string(seq1), string(seq2))
}

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 nextInt64() int64 {
	n, err := strconv.ParseInt(next(), 0, 64)
	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...)
}

package main

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

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

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

	n := nextInt()
	isFirstWin := true
	var point1, point2, a int64 = 0, 0, 0
	seq1, seq2 := make([]rune,0), make([]rune, 0)

	for i := 0; i < n; i++ {
		a = nextInt64()

		if i == n - 1 && a < 0 {
			 isFirstWin = false
		}

		if a > 0 {
			point1 += a

			seq1 = append(seq1, []rune(strconv.FormatInt(a, 10))...)
		} else {
			a = -a

			point2 += a
			seq2 = append(seq2, []rune(strconv.FormatInt(a, 10))...)
		}
	}

	if point1 < point2 {
		isFirstWin = false
	} else if point1 == point2 {
		if string(seq1) < string(seq2) {
			isFirstWin = false
		}
	}

	if isFirstWin {
		println("first")
	} else {
		println("second")
	}

	// println(point1, point2)
	// println(string(seq1), string(seq2))
}

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 nextInt64() int64 {
	n, err := strconv.ParseInt(next(), 0, 64)
	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...)
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func next() string {
	scanOne()
	return sc.Text()
}

func main() {
	scInit()
	n := nextInt()
	var t [200010]int // techniques
	for i := 0; i < n; i++ {
		t[i] = nextInt()
	}

	a, b := make([]int, 0, 200010), make([]int, 0, 200010)
	for i := 0; i < n; i++ {
		if t[i] > 0 {
			a = append(a, t[i])
		} else {
			b = append(b, -t[i])
		}
	}

	sameSequence := func(x, y []int) bool {
		n := len(x)
		if n != len(y) {
			return false
		}
		for i := 0; i < n; i++ {
			if x[i] != y[i] {
				return false
			}
		}
		return true
	}

	if sameSequence(a, b) {
		if t[n-1] > 0 {
			fmt.Println("first")
		} else {
			fmt.Println("second")
		}
		return
	}

	sum := func(x []int) (z int) {
		n := len(x)
		for i := 0; i < n; i++ {
			z += x[i]
		}
		return
	}

	if sum(a) == sum(b) {
		i, n, m := 0, len(a), len(b)
		for {
			switch {
			case i >= m:
				fmt.Println("first")
				return
			case i >= n:
				fmt.Println("second")
				return
			case a[i] > b[i]:
				fmt.Println("first")
				return
			case a[i] < b[i]:
				fmt.Println("second")
				return
			default:
				i++
			}
		}
	}

	if sum(a) > sum(b) {
		fmt.Println("first")
	} else {
		fmt.Println("second")
	}
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, 0)
    b := make([]int, 0)
    suma := 0
    sumb := 0
    latest := 0
    for i := 0; i < n; i++ {
        x := nextInt()
        if (x > 0) {
            a = append(a, x)
            suma += x
            latest = 1
        } else {
            b = append(b, -x)
            sumb += -x
            latest = 2
        }
    }

    if suma > sumb {
        fmt.Fprintln(out, "first")
    } else if suma < sumb {
        fmt.Fprintln(out, "second")
    } else {
        n = len(a)
        if n > len(b) {
            n = len(b)
        }
        for i := 0; i < n; i++ {
            if a[i] > b[i] {
                fmt.Fprintln(out, "first")
                return
            } else if a[i] < b[i] {
                fmt.Fprintln(out, "second")
                return
            }
        }
        if latest == 1 {
            fmt.Fprintln(out, "first")
        } else {
            fmt.Fprintln(out, "second")
        }
    }
}