In an ICPC contest, balloons are distributed as follows:   Whenever a team solves a problem, that team gets a balloon.  The first team to solve a problem gets an additional balloon.  A contest has 26 problems, labelled $$$\textsf{A}$$$, $$$\textsf{B}$$$, $$$\textsf{C}$$$, ..., $$$\textsf{Z}$$$. You are given the order of solved problems in the contest, denoted as a string $$$s$$$, where the $$$i$$$-th character indicates that the problem $$$s_i$$$ has been solved by some team. No team will solve the same problem twice.Determine the total number of balloons that the teams received. Note that some problems may be solved by none of the teams.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of testcases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the length of the string. The second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of uppercase English letters, denoting the order of solved problems.

6

3

ABA

1

A

3

ORZ

5

BAAAA

4

BKPT

10

CODEFORCES

NoteIn the first test case, $$$5$$$ balloons are given out:   Problem $$$\textsf{A}$$$ is solved. That team receives $$$2$$$ balloons: one because they solved the problem, an an additional one because they are the first team to solve problem $$$\textsf{A}$$$.  Problem $$$\textsf{B}$$$ is solved. That team receives $$$2$$$ balloons: one because they solved the problem, an an additional one because they are the first team to solve problem $$$\textsf{B}$$$.  Problem $$$\textsf{A}$$$ is solved. That team receives only $$$1$$$ balloon, because they solved the problem. Note that they don't get an additional balloon because they are not the first team to solve problem $$$\textsf{A}$$$.  The total number of balloons given out is $$$2+2+1=5$$$.In the second test case, there is only one problem solved. The team who solved it receives $$$2$$$ balloons: one because they solved the problem, an an additional one because they are the first team to solve problem $$$\textsf{A}$$$.

package main

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

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

func ReadInt() int{
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadIntArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		fmt.Fscan(in, &ans[i])
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func ReadStringArray(N int) []string{
	ans := make([]string, N)
	for i := 0; i < N; i++{
		fmt.Fscan(in, &ans[i])
	}
	return ans
}

func main(){
	defer out.Flush()
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		S := ReadString()
		who := make([]bool, 26)
		tot := N
		for i := 0; i < N; i++{
			if !who[S[i] - 'A']{
				who[S[i] - 'A'] = true
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import "fmt"

func ReadInt() int{
	var i int
	fmt.Scanf("%d\n", &i)
	return i
}

func ReadArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		ans[i] = ReadInt()
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Scanf("%s\n", &s)
	return s
}

func main(){
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		S := ReadString()
		who := make([]bool, 26)
		tot := N
		for i := 0; i < N; i++{
			if !who[S[i] - 'A']{
				who[S[i] - 'A'] = true
				tot++
			}
		}
		fmt.Println(tot)
	}
}

package main

import (
    "fmt"

)

func main() {
    tt := 0
    fmt.Scan(&tt)
    var s string
    for i := 1; i <= tt; i++ {
        sz := 0
        fmt.Scan(&sz)

        fmt.Scan(&s)
        arr := [26]int{0,}
        for j := range s {
            arr[s[j] - 'A']++
        }
        ans := 0
        for j := 0; j < 26; j++ {
            if arr[j] > 0 {
                ans += 2
                arr[j]--
                ans += arr[j]
            }
        }

        fmt.Println(ans)
    }

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var n int
		var s string
		m := make(map[byte]struct{})
		var cnt int
		fmt.Scanf("%d\n", &n)
		fmt.Scanf("%s\n", &s)
		for j := 0; j < n; j++ {
			if _, exist := m[s[j]]; !exist {
			    m[s[j]] = struct{}{}
				cnt += 2
			} else {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

package main

import . "fmt"

func main() {
	var (
		t, n, cnt int
		s, chr    string
	)
	Scan(&t)
	for i := 0; i < t; i++ {
		cnt = 0
		m := make(map[string]int)
		Scan(&n)
		Scan(&s)
		for j := 0; j < n; j++ {
			chr = string(s[j])
			if m[chr] == 0 {
				m[chr] = 1
				cnt += 2
			} else {
				cnt += 1
			}
		}
		Println(cnt)
	}
}

package main

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

func main() {
	var (
		t   int
		n   int
		sln []int
	)
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		sln = nil
		scanner.Scan()
		n, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		for _, runeValue := range scanner.Text() {
			sln = append(sln, int(runeValue))
		}
		su := CountValue(sln)
		fmt.Println(n + len(su))
	}
}

func CountValue(arr []int) (res map[int]int) {
	dict := make(map[int]int)
	for _, num := range arr {
		dict[num] = dict[num] + 1
	}
	res = dict
	return
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var s string
		var r int
		fmt.Scan(&n)
		m := make(map[rune]int)
		fmt.Scan(&s)
		for _, c := range s {
			m[c]++
			r++
		}
		r += len(m)
		fmt.Println(r)
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var word string
		fmt.Scan(&word)
		var list []byte
		for j:=0;j<len(word);j++{
			tally:=0
			for k:=0;k<len(list);k++{
				if list[k] == word[j] {
					tally++
				}
			}
			if tally == 0 {
				list = append(list,word[j])
			}
		}
		// x:= distinct characters in word
		fmt.Println(n+len(list))
	}
}

package main

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

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

func solve() {
	var let [26]rune
	_ = _readInt()
	s := _readStr()
	cnt := 0
	for _, r := range s {
		r -= 'A'
		if let[r] == 0 {
			let[r]++
			cnt++
		}
	}
	_print(len(s) + cnt)
}

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

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr() (int, []int) {
	var n int
	fmt.Fscan(in, &n)
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func _min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}

package main

import (
	"fmt"
)

func main() {
	var str string
	var T int
	fmt.Scan(&T)
	for Case := 1; Case <= T; Case++ {
		var n int
		fmt.Scan(&n)
		fmt.Scan(&str)
		var table[256] int
		var ans int = 0
		for i := 0; i < n; i++ {
			id := int(str[i])
			if table[id] == 0 {
				ans += 2
			} else {
				ans += 1
			}
			table[id]++
		}
		fmt.Println(ans)
	}
}

// https://codeforces.com/problemset/problem/1703/B

// 1703B - ICPC Balloons

// In an ICPC contest, balloons are distributed as follows:
//  • Whenever a team solves a problem, that team gets a balloon.
//  • The first team to solve a problem gets an additional balloon.
// A contest has 26 problems, labelled A, B, C, ..., Z. You are given the order of solved problems in the contest, denoted as a string s, where the i-th character indicates that the problem si has been solved by some team. No team will solve the same problem twice.
// Determine the total number of balloons that the teams received. Note that some problems may be solved by none of the teams.

// Input
// The first line of the input contains an integer t (1≤t≤100) — the number of testcases.
// The first line of each test case contains an integer n (1≤n≤50) — the length of the string.
// The second line of each test case contains a string s of length n consisting of uppercase English letters, denoting the order of solved problems.

// Output
// For each test case, output a single integer — the total number of balloons that the teams received.

// Example
// input
// 6
// 3
// ABA
// 1
// A
// 3
// ORZ
// 5
// BAAAA
// 4
// BKPT
// 10
// CODEFORCES
// output
// 5
// 2
// 6
// 7
// 8
// 17

// Note

// In the first test case, 5 balloons are given out:
//  • Problem A is solved. That team receives 2 balloons: one because they solved the problem, an an additional one because they are the first team to solve problem A.
//  • Problem B is solved. That team receives 2 balloons: one because they solved the problem, an an additional one because they are the first team to solve problem B.
//  • Problem A is solved. That team receives only 1 balloon, because they solved the problem. Note that they don't get an additional balloon because they are not the first team to solve problem A.
// The total number of balloons given out is 2+2+1=5.
// In the second test case, there is only one problem solved. The team who solved it receives 2 balloons: one because they solved the problem, an an additional one because they are the first team to solve problem A.

// Tutorial

// Let's keep an array a of booleans, ai denoting whether or not some team has solved the ith problem already. Now we can iterate through the string from left to right and keep a running total tot. If ai is true (the i-th problem has already been solved), increase tot by 1; otherwise, increase tot by 2 and set ai to true.
// The time complexity is O(n).
// Bonus: the answer is always n+number of distinct characters in s. Can you see why?

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, tot, i uint
	var s string
	var a [26]bool

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &s)
			tot = 0

			for i = 0; i < 26; i++ {
				a[i] = false
			}

			for i = 0; i < n; i++ {
				if a[s[i]-'A'] {
					tot++
				} else {
					tot += 2
					a[s[i]-'A'] = true
				}
			}

			fmt.Fprintln(writer, tot)
		}
	}

	writer.Flush()
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		readNum(reader)
		word := readString(reader)
		res := solve(word)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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(s string) int {
	first := make([]bool, 26)
	var res int
	for i := 0; i < len(s); i++ {
		x := int(s[i] - 'A')
		res++
		if !first[x] {
			res++
			first[x] = true
		}
	}

	return res
}

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 i := 0; i < t; i++ {
		var n, cnt int
		var s string
		var arr [26]bool
		cnt = 0
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		for i := 0; i < n; i++ {
			if arr[s[i]-65] {
				cnt++
			} else {
				arr[s[i]-65] = true
				cnt += 2
			}
		}
		fmt.Fprintln(out, cnt)
	}

}

package main

import "fmt"

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

	for ; t > 0; t-- {
		var n int
		fmt.Scanln(&n)
		var s string
		fmt.Scanln(&s)

		var m = make(map[rune]int)
		for _, v := range s {
			m[v]++
		}

		var sum = len(m)
		for _, v := range m {
			sum += v
		}

		fmt.Println(sum)
	}
}

package main

import (
	"fmt"
)

func main() {
	var s string
	var n, m int
	fmt.Scan(&n)
	for n>0 {
		fmt.Scan(&m,&s)
		var t [128]int
		sum:=0
		for _,c:=range s{
			// fmt.Print(c,' ')
			if t[c]==0 {sum++}
			t[c]=1
		}
		fmt.Println(sum+len(s))
		n--
	}

}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
	s      string
)

func solve(n int, s string) int {
	var solved = make(map[byte]int)
	for i := 0; i < n; i++ {
		solved[s[i]] = solved[s[i]] + 1
	}
	var result int
	for _, x := range solved {
		result += x + 1
	}
	return result
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &s)
		fmt.Println(solve(n, s))
	}
}

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	var s string
	fmt.Fscan(in, &s)
	arr := make([]int, 26)
	for i := 0; i < n; i++ {
		idx := s[i] - 'A'
		if arr[idx] == 0 {
			arr[idx] += 2
		} else {
			arr[idx]++
		}
	}
	sum := 0
	for _, v := range arr {
		sum += v
	}
	fmt.Fprintln(out, sum)
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	// 读入一行数据
	// s, _ := in.ReadString('\n')
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		var s string
		fmt.Fscan(in, &s)
		mp := make(map[byte]int)
		byteStr := []byte(s)
		var res int
		for i := 0; i < len(byteStr); i++ {
			if _, ok := mp[byteStr[i]]; ok {
				res += 1
			}else{
				res += 2
			}
			mp[byteStr[i]]++
		}
		fmt.Fprintln(out, res)
	}

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		solve()
	}
}
func main() {
	run(os.Stdin, os.Stdout)
}

package main

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

type CF1703B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1703B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1703B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1703B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1703B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1703B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1703B
Date: 14/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1703/B
Problem: CF1703B
**/
func (in *CF1703B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		mapa := make(map[uint8]bool)

		str := in.NextString()
		ans := 0
		for i := 0; i < n; i++ {
			_, e := mapa[str[i]]

			if !e {
				mapa[str[i]] =true
				ans++
			}
			ans++
		}
		fmt.Println(ans)
	}

}

func NewCF1703B(r *bufio.Reader) *CF1703B {
	return &CF1703B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1703B(bufio.NewReader(os.Stdin)).Run()
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	var s string
	fmt.Fscan(rr, &s)
	cnt := map[byte]bool{}
	ans := 0
	for i := range s {
		if cnt[s[i]] {
			ans++
		} else {
			ans+=2
		}
		cnt[s[i]] = true
	}
	fmt.Fprintln(ww, ans)
}

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

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &s)
		cnt := map[rune]int{}
		for _, v := range s {
			cnt[v]++
		}
		Fprintln(out, n+len(cnt))
	}
}

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

package main

import (
	"fmt"
	"os"
)

func setOs() {
	//os.Stdin, err = os.OpenFile("input.txt", os.RDONLY|os.O_CREATE, 0666)
	//os.Stdout, err = os.OpenFile("output.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	_, err := os.Stat("input.txt")
	if err == nil {
		os.Stdin, _ = os.OpenFile("input.txt", os.O_RDWR|os.O_CREATE, 0666)
	}
}

func main() {
	setOs()
	var t int
	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		var n int
		var s string
		res := 0
		fmt.Scan(&n)
		fmt.Scan(&s)
		m := make(map[byte]bool)
		for i := 0; i < len(s); i++ {
			if m[s[i]] == true {
				res++
			} else {
				res += 2
			}
			m[s[i]] = true
		}

		fmt.Println(res)

	}
}

package main

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

func main() {
	var (
		t     int
		n     int
		input string
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanf(reader, "%d\n", &t)

	for i := 0; i < t; i++ {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fscanf(reader, "%s\n", &input)
		distinct := solve(input, n)
		fmt.Println(2*distinct + (n - distinct))
	}
}

func solve(str string, n int) (count int) {
	temp := strings.Split(str, "")
	sort.Strings(temp)

	for i := 0; i < n; i++ {
		for i < n-1 && temp[i] == temp[i+1] {
			i++
		}
		count++
	}
	return
}

package main

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

func check(s string) int {
	set := map[rune]struct{}{}
	c := 0
	for _, ch := range s {
		if _, ok := set[ch]; !ok {
			c+=1
			set[ch] = struct{}{}
		}
		c++
	}
	return c
}

func main() {
	// f, _ := os.Open("input.txt")
	t := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(t, &n)
	for i := 0; i < n; i++ {
		var m int
		fmt.Fscan(t, &m)
		var s string
		fmt.Fscan(t, &s)
		fmt.Println(check(s))
	}
}

package main

import "fmt"

func main() {
    t := 0;
    fmt.Scanf("%d\n", &t);

    for i := 0; i < t; i++ {
        balloons := 0;
        solved := map[byte]bool{};

        n := 0;
        s := "";
        fmt.Scanf("%d\n%s\n", &n, &s);

        for j := 0; j < len(s); j++ {
            problem := s[j];
            balloons++;
            if _, ok := solved[problem]; !ok {
                balloons++;
                solved[problem] = true;
            }
        }

        fmt.Printf("%d\n", balloons);
    }
}

//package main
//
//import (
//	"context"
//	"gerRpc"
//	"gerRpc/xclient"
//	"log"
//	"sync"
//
//	"net"
//	"time"
//)
//
////
////func startServer(addr chan string)  {
////	l, err := net.Listen("tcp", ":0")
////	if err != nil{
////		log.Fatal("network error:", err)
////	}
////	log.Println("start rpc server on:", l.Addr())
////	addr <- l.Addr().String()
////	gerRpc.Accept(l)
////}
////
////func main()  {
////
////	//addr := make(chan string)
////	//go startServer(addr)
////	//client, _ := gerRpc.Dial("tcp", <-addr)
////	//defer func() {_ = client.Close()}()
////
////	//time.Sleep(time.Second)
////	//var wg sync.WaitGroup
////	//for i := 0; i < 5; i ++{
////	//	wg.Add(1)
////	//	go func(i int) {
////	//		defer wg.Done()
////	//		args := fmt.Sprintf("geerpc req %d", i)
////	//		var reply string
////	//		if err := client.Call("Foo.sum", args, &reply); err != nil{
////	//			log.Fatal("call Foo.Sum error:", err)
////	//		}
////	//		log.Println("reply")
////	//	}(i)
////	//}
////	//wg.Wait()
////}
//
////
////func main() {
////	addr := make(chan string)
////	go startServer(addr)
////
////	// in fact, following code is like a simple geerpc client
////	conn, _ := net.Dial("tcp", <-addr)
////	defer func() { _ = conn.Close() }()
////
////	time.Sleep(time.Second)
////	// send options
////	_ = json.NewEncoder(conn).Encode(gerRpc.DefaultOption)
////	cc := codec.NewGobCodec(conn)
////	// send request & receive response
////	for i := 0; i < 5; i++ {
////		h := &codec.Header{
////			ServiceMethod: "Foo.Sum",
////			Seq:           uint64(i),
////		}
////		_ = cc.Write(h, fmt.Sprintf("geerpc req %d", h.Seq))
////		_ = cc.ReadHeader(h)
////		var reply string
////		_ = cc.ReadBody(&reply)
////		log.Println("reply:", reply)
////	}
////}
////
////
////type Foo int
////
////type Args struct {
////	Num1, Num2 int
////}
////
////func (f Foo)Sum(args Args, reply *int)error  {
////	*reply = args.Num1 + args.Num2
////	return nil
////}
////func startServer(addr chan string) {
////	var foo Foo
////	if err := gerRpc.Register(&foo); err != nil {
////		log.Fatal("register error:", err)
////	}
////	// pick a free port
////	l, err := net.Listen("tcp", ":0")
////	if err != nil {
////		log.Fatal("network error:", err)
////	}
////	log.Println("start rpc server on", l.Addr())
////	addr <- l.Addr().String()
////	gerRpc.Accept(l)
////}
////
////func main()  {
////	log.SetFlags(0)
////	addr := make(chan string)
////	go startServer(addr)
////	client, _ := gerRpc.Dial("tcp", <-addr)
////	defer func() {_ = client.Close()}()
////
////	time.Sleep(time.Second)
////	var wg sync.WaitGroup
////	for i := 0; i < 5; i ++{
////		wg.Add(1)
////		go func(i int) {
////			defer wg.Done()
////			args := &Args{
////				Num1: i,
////				Num2: i * i,
////			}
////			ctx, _ := context.WithTimeout(context.Background(), time.Second)
////			var reply int
////			if err := client.Call(ctx,"Foo.Sum", args, &reply); err != nil{
////				log.Fatal("call Foo.Sum error:", err)
////			}
////			log.Printf("%d + %d = %d", args.Num1, args.Num2, reply)
////		}(i)
////	}
////	wg.Wait()
////}
//type Foo int
//
//type Args struct{ Num1, Num2 int }
//
//func (f Foo) Sum(args Args, reply *int) error {
//	*reply = args.Num1 + args.Num2
//	return nil
//}
//
//func (f Foo) Sleep(args Args, reply *int) error {
//	time.Sleep(time.Second * time.Duration(args.Num1))
//	*reply = args.Num1 + args.Num2
//	return nil
//}
//
//func startServer(addrCh chan string) {
//	var foo Foo
//	l, _ := net.Listen("tcp", ":0")
//	server := gerRpc.NewServer()
//	_ = server.Register(&foo)
//	addrCh <- l.Addr().String()
//	server.Accept(l)
//}
//
//func foo(xc *xclient.Xclient, ctx context.Context, typ, serviceMethod string, args *Args)  {
//	var reply int
//	var err error
//	switch typ {
//	case "call":
//		err = xc.Call(ctx, serviceMethod, args, &reply)
//	case "broadcast":
//		err = xc.Broadcast(ctx, serviceMethod, args, &reply)
//	}
//	if err != nil{
//		log.Printf("%s %s error: %v", typ, serviceMethod, err)
//	}else{
//		log.Printf("%s %s success: %d + %d = %d", typ, serviceMethod, args.Num1, args.Num2, reply)
//	}
//}
//
//func call(addr1, addr2 string)  {
//	d := xclient.NewMultiServerDiscovery([]string{"tcp@"+addr1, "tcp@"+addr2})
//	xc := xclient.NewXClient(d, xclient.RandomSelect, nil)
//	defer func() {_ = xc.Close()}()
//
//	var wg sync.WaitGroup
//	for i := 0; i < 5; i ++{
//		wg.Add(1)
//		go func(i int) {
//			defer wg.Done()
//			foo(xc, context.Background(), "call", "Foo.Sum", &Args{
//				Num1: i,
//				Num2: i * i,
//			})
//		}(i)
//	}
//	wg.Wait()
//}
//
//func broadcast(addr1, addr2 string) {
//	d := xclient.NewMultiServerDiscovery([]string{"tcp@" + addr1, "tcp@" + addr2})
//	xc := xclient.NewXClient(d, xclient.RandomSelect, nil)
//	defer func() { _ = xc.Close() }()
//	var wg sync.WaitGroup
//	for i := 0; i < 5; i++ {
//		wg.Add(1)
//		go func(i int) {
//			defer wg.Done()
//			foo(xc, context.Background(), "broadcast", "Foo.Sum", &Args{Num1: i, Num2: i * i})
//			// expect 2 - 5 timeout
//			ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
//			foo(xc, ctx, "broadcast", "Foo.Sleep", &Args{Num1: i, Num2: i * i})
//		}(i)
//	}
//	wg.Wait()
//}
//
//
//func main() {
//	log.SetFlags(0)
//	ch1 := make(chan string)
//	ch2 := make(chan string)
//	// start two servers
//	go startServer(ch1)
//	go startServer(ch2)
//
//	addr1 := <-ch1
//	addr2 := <-ch2
//
//	time.Sleep(time.Second)
//	call(addr1, addr2)
//	broadcast(addr1, addr2)
//}
//
//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"strings"
//)
//
//var in = bufio.NewReader(os.Stdin)
//
//func main()  {
//	var T int
//	fmt.Fscan(in, &T)
//	for ;T > 0; T--{
//		var str string
//		fmt.Fscan(in, &str)
//
//		if strings.EqualFold(strings.ToLower(str), "yes"){
//			fmt.Println("YES")
//		}else{
//			fmt.Println("NO")
//		}
//	}
//}

package main

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

var in = bufio.NewReader(os.Stdin)

func main()  {
	var T int
	fmt.Fscan(in, &T)
	for ;T > 0; T--{
		var n int
		fmt.Fscan(in, &n)
		var str string
		fmt.Fscan(in, &str)
		mp := make(map[byte]bool)
		cnt := 0
		for i := 0; i < n; i ++{
			if !mp[str[i]] {
				cnt += 2
				mp[str[i]] = true
			}else{
				cnt ++
			}
		}
		fmt.Println(cnt)
	}
}

package main

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

func calcScore(str string) int {
	problems := make(map[byte]bool)
	score := 0
	for i := 0; i < len(str); i++ {
		if problems[str[i]] {
			score++
		} else {
			score += 2
			problems[str[i]] = true
		}
	}
	return score
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 16*1024*1024)
	T, err := strconv.Atoi(strings.TrimSpace(readLine(reader)))
	checkError(err)
	var results = make([]int, T)
	for i := 0; i < T; i++ {
		_, err := strconv.Atoi(strings.TrimSpace(readLine(reader)))
		checkError(err)
		str := strings.TrimSpace(readLine(reader))
		results[i] = calcScore(str)
	}
	for _, result := range results {
		fmt.Println(result)
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err != nil {
		return ""
	}
	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

// 1703B. ICPC Balloons
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s string
		fmt.Fscan(reader, &n, &s)
		m := make(map[byte]bool)
		ans := 0
		for i := 0; i < n; i++ {
			if !m[s[i]] {
				m[s[i]] = true
				ans += 2
			} else {
				ans++
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

	var T int
	for fmt.Fscan(in, &T); T > 0; T-- {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)
		cnt := make([]bool, 26)
		ans := 0
		for i := 0;i < n; i++ {
			if cnt[s[i] - 'A'] {
				ans ++
			} else {
				cnt[s[i] - 'A'] = true
				ans += 2
			}
		}
		fmt.Fprintln(out, ans)
	}
}

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

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		var tot int
		m := make([]bool, 26)
		for _, ch := range s {
			if !m[ch-'A'] {
				tot += 2
				m[ch-'A'] = true
			} else {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		var s string
		fmt.Fscan(r, &n, &s)
		w1 := do(s)
		fmt.Fprintln(w, w1)
	}
}

func do(m string) int {
	x := make([]int, 26)
	ans := 0
	for _, c := range m {
		y := c - 'A'
		if x[y] == 0 {
			ans++
		}
		ans++
		x[y]++
	}
	return ans
}

package main

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

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

func ReadInt() int{
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadIntArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		fmt.Fscan(in, &ans[i])
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func ReadStringArray(N int) []string{
	ans := make([]string, N)
	for i := 0; i < N; i++{
		fmt.Fscan(in, &ans[i])
	}
	return ans
}

func main(){
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		S := ReadString()
		who := make([]bool, 26)
		tot := N
		for i := 0; i < N; i++{
			if !who[S[i] - 'A']{
				who[S[i] - 'A'] = true
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import "fmt"

func ReadInt() int{
	var i int
	fmt.Scanf("%d", &i)
	return i
}

func ReadArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		ans[i] = ReadInt()
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Scanf("%s", &s)
	return s
}

func main(){
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		S := ReadString()
		who := make([]bool, 26)
		tot := N
		for i := 0; i < N; i++{
			if !who[S[i] - 'A']{
				who[S[i] - 'A'] = true
				tot++
			}
		}
		fmt.Println(tot)
	}
}

package main

import (
    "fmt"
    "strings"
)

func main() {
    tt := 0
    fmt.Scan(&tt)
    var str string
    for i := 1; i <= tt; i++ {
        fmt.Scan(&str)
        str = strings.ToLower(str)
        if str == "yes" {
            println("YES")
        } else {
            println("NO")
        }
    }

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var n int
		var s string
		m := make(map[byte]struct{})
		var cnt int
		fmt.Scanf("%d\n", &n)
		fmt.Scanf("%s\n", &s)
		for j := 0; j < n; j++ {
			if _, exist := m[s[j]]; !exist {
				cnt += 2
			} else {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

package main

import . "fmt"

func main() {
	var (
		t, n, cnt int
		s, chr    string
	)
	Scan(&t)
	for i := 0; i < t; i++ {
		cnt = 0
		m := make(map[string]int)
		Scan(&n)
		Scan(&s)
		for j := 0; j < n; j++ {
			chr = string(s[j])
			if m[chr] == 0 {
				m[chr] = 1
				cnt += 2
			} else {
				cnt += 1
			}
		}
		Print(cnt)
	}
}


A big football championship will occur soon! $$$n$$$ teams will compete in it, and each pair of teams will play exactly one game against each other.There are two possible outcomes of a game:  the game may result in a tie, then both teams get $$$1$$$ point;  one team might win in a game, then the winning team gets $$$3$$$ points and the losing team gets $$$0$$$ points. The score of a team is the number of points it gained during all games that it played.You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well.Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of teams.

For each test case, print $$$\frac{n(n - 1)}{2}$$$ integers describing the results of the games in the following order: the first integer should correspond to the match between team $$$1$$$ and team $$$2$$$, the second — between team $$$1$$$ and team $$$3$$$, then $$$1$$$ and $$$4$$$, ..., $$$1$$$ and $$$n$$$, $$$2$$$ and $$$3$$$, $$$2$$$ and $$$4$$$, ..., $$$2$$$ and $$$n$$$, and so on, until the game between the team $$$n - 1$$$ and the team $$$n$$$. The integer corresponding to the game between the team $$$x$$$ and the team $$$y$$$ should be $$$1$$$ if $$$x$$$ wins, $$$-1$$$ if $$$y$$$ wins, or $$$0$$$ if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score.

NoteIn the first test case of the example, both teams get $$$1$$$ point since the game between them is a tie.In the second test case of the example, team $$$1$$$ defeats team $$$2$$$ (team $$$1$$$ gets $$$3$$$ points), team $$$1$$$ loses to team $$$3$$$ (team $$$3$$$ gets $$$3$$$ points), and team $$$2$$$ wins against team $$$3$$$ (team $$$2$$$ gets $$$3$$$ points).

package main

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

func MIN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			if n%4 == 1 {
				for i := 1; i < n*(n-1)/4+1; i++ {
					fmt.Println("1 -1 ")
				}

			} else {
				for i := 1; i < (n+2)*(n-3)/4+2; i++ {
					fmt.Println("1 -1 ")
				}
				fmt.Println(1)
			}
		} else {
			ARRAY := make([]int, 0)
			ARRAB := make([]int, 0)
			ARRAY = append(ARRAY, 1)
			ARRAY = append(ARRAY, 1)
			ARRAY = append(ARRAY, 1)
			ARRAY = append(ARRAY, 1)
			ARRAB = append(ARRAB, -1)
			ARRAB = append(ARRAB, -1)
			ARRAB = append(ARRAB, -1)
			ARRAB = append(ARRAB, -1)

			t := int(n / 2)
			oo := (t - 1) * t / 2
			for i := 0; i < t*t; i++ {
				ARRAY = append(ARRAY, 1)
				ARRAB = append(ARRAB, -1)
			}
			for k := t - 1; k > -1; k-- {
				q := ARRAY[:t-1]
				qq := fmt.Sprint(q)
				fmt.Println(qq[1 : len(qq)-1])
				fmt.Println(0)
				q1 := ARRAB[:k]
				qq1 := fmt.Sprint(q1)
				fmt.Println(qq1[1 : len(qq1)-1])
			}
			q := ARRAY[:oo]
			qq := fmt.Sprint(q)
			fmt.Println(qq[1 : len(qq)-1])

		}

	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

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

		for i := 0; i < len(res); i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int) (res []int) {
	res = make([]int, 0, n*(n-1)/2)
	mat := make([][]int, n)

	if n&1 == 1 {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := i + 1; j < n; j++ {
				if j-i <= n/2 {
					mat[i][j] = 1
				} else {
					mat[i][j] = -1
				}
			}

		}
	} else {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := i + 1; j < n; j++ {
				if j-i < n/2 {
					mat[i][j] = 1
				} else if j-i == n/2 {
					mat[i][j] = 0
				} else {
					mat[i][j] = -1
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			res = append(res, mat[i][j])
		}
	}
	return
}

package main

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

var out *bufio.Writer

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

	for i := 0; i < n-1; i++ {
		for j := 0; j < n-1-i; j++ {
			if n%2 == 0 && n/2-1 == j {
				fmt.Fprint(out, "0 ")
				continue
			}
			if j < n/2 {
				fmt.Fprint(out, "1 ")
			} else {
				fmt.Fprint(out, "-1 ")
			}
		}
	}
	fmt.Fprintln(out)
}

func main() {
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Scan(&t)

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type nb struct{ to, i int }

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]nb, n)
		m := 0
		for i := 0; i < n; i++ {
			j := i + 1
			if n&1 == 0 && i&1 == 0 {
				j++
				m++
			}
			for ; j < n; j++ {
				g[i] = append(g[i], nb{j, m})
				g[j] = append(g[j], nb{i, m})
				m++
			}
		}

		ans := make([]int, m)
		vis := make([]bool, m)
		pre := 0
		var f func(int)
		f = func(v int) {
			for len(g[v]) > 0 {
				e := g[v][0]
				g[v] = g[v][1:]
				if w, i := e.to, e.i; !vis[i] {
					vis[i] = true
					f(w)
					v := v
					if w == pre {
						v, w = w, v
					}
					if v < w {
						ans[i] = 1
					} else {
						ans[i] = -1
					}
					pre = w
				}
			}
		}
		f(0)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

import (
	"fmt"
	"log"
	"os"
	"strings"
)

type bufferedReader struct {
	buf     [4096]byte
	ptr, sz int
	eof     bool
	ended   bool
	in      *os.File
}

func newReader(in *os.File) bufferedReader {
	var tmp [4096]byte
	return bufferedReader{tmp, 0, 0, false, false, in}
}

func (r *bufferedReader) isEof() bool {
	return r.eof
}

func (r *bufferedReader) load() {
	if r.ended {
		r.eof = true
		return
	}
	sz, err := r.in.Read(r.buf[:])
	r.sz = sz
	if sz < 4096 {
		r.ended = true
	}
	if err != nil {
		log.Fatal(err)
	}
	r.ptr = 0
}

func (r *bufferedReader) getChar() byte {
	if r.ptr == r.sz && !r.eof {
		r.load()
	}
	if r.ptr == r.sz || r.eof {
		r.eof = true
		return 0
	}
	r.ptr += 1
	return r.buf[r.ptr-1]
}

func (r *bufferedReader) skipNonIntChars() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if (c >= 48 && c <= 57) || (c == 45) {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) skipWhitespace() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c != ' ' && c != '\n' && c != '\t' && c != '\r' {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) readInt() int {
	r.skipNonIntChars()
	var ans int = 0
	var neg bool = false
	fst := r.getChar()
	if fst == 45 {
		neg = true
	} else {
		ans = int(fst) - 48
	}
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c >= 48 && c <= 57 {
			ans = ans*10 + int(c-48)
		} else {
			r.ptr -= 1
			break
		}
	}
	if neg {
		ans = -ans
	}
	return ans
}

func (r *bufferedReader) readString() string {
	r.skipWhitespace()
	sz := 0
	capacity := 2
	s := make([]byte, 2)
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c == ' ' || c == '\n' || c == '\t' || c == '\r' {
			r.ptr--
			break
		}
		if sz == capacity {
			capacity <<= 1
			s1 := make([]byte, capacity)
			for i := 0; i < sz; i++ {
				s1[i] = s[i]
			}
			s = s1
		}
		s[sz] = c
		sz++
	}
	return string(s[:sz])
}

func main() {
	var in bufferedReader
	hostname, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}
	if strings.HasSuffix(hostname, "lenovo") {
		file, _ := os.Open("input.txt")
		in = newReader(file)
	} else {
		in = newReader(os.Stdin)
	}
	T := in.readInt()
	siegheil := make([]byte, 0)
	for t := 0; t < T; t++ {
		n := in.readInt()
		b := make([][]int, n)
		for i := 0; i < n; i++ {
			b[i] = make([]int, n)
			for j := 0; j < n; j++ {
				b[i][j] = -1
			}
		}
		if n%2 == 1 {
			for i := 0; i < n; i++ {
				j := (i + 1) % n
				for k := 0; k < n/2; k++ {
					b[i][j] = 1
					j = j + 1
					if j == n {
						j = 0
					}
				}
			}
		} else {
			for i := 0; i < n; i++ {
				mid := (i + n/2) % n
				b[i][mid] = 0
				j := (i + 1) % n
				for j != mid {
					b[i][j] = 1
					j = j + 1
					if j == n {
						j = 0
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				s := make([]byte, 0)
				if b[i][j] < 0 {
					siegheil = append(siegheil, '-')
					b[i][j] = -b[i][j]
				}
				for b[i][j] > 0 {
					s = append(s, byte(48+b[i][j]%10))
					b[i][j] /= 10
				}
				if len(s) == 0 {
					s = append(s, '0')
				}
				for k := len(s) - 1; k >= 0; k-- {
					siegheil = append(siegheil, s[k])
				}
				siegheil = append(siegheil, ' ')
			}
		}
		siegheil = append(siegheil, '\n')
	}
	fmt.Printf("%s", siegheil)
}

package main

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

func solveC(n int) {
	const (
		uninited int = iota
		lose
		draw
		win
	)

	edges := make([][]int, n)
	for i := range edges {
		edges[i] = make([]int, n)
	}

	if n%2 == 0 {
		for i := 0; i+1 < n; i += 2 {
			edges[i][i+1] = draw
			edges[i+1][i] = draw
		}
	}

	var walk func(int)
	walk = func(node int) {
		for nextNode := 0; nextNode < n; nextNode++ {
			if edges[node][nextNode] == uninited {
				edges[node][nextNode] = win
				edges[nextNode][node] = lose
				walk(nextNode)
			}
		}
	}

	walk(0)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			printf("%d ", edges[i][j]-2)
		}
	}
	printf("\n")
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)

	for t := 0; t < T; t++ {
		n := 0
		scan(&n)
		solveC(n)
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func gcdExt(a, b int) (int, int, int) {
	if b == 0 {
		return 1, 0, a
	}
	y, x, g := gcdExt(b, a%b)
	return x, y - a/b*x, g
}

func sieve() {
	const maxn = 1e7
	var lp [maxn + 1]int64
	var pr []int64

	for i := int64(2); i <= maxn; i++ {
		if lp[i] == 0 {
			lp[i] = i
			pr = append(pr, i)
		}
		for j := 0; j < len(pr) && pr[j] <= lp[i] && i*pr[j] <= maxn; j++ {
			lp[i*pr[j]] = pr[j]
		}
	}
}

package main

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

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

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

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

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

func sol(n int64) []int64 {
	ret := []int64{}
	if n&1 == 1 {
		for i := n - 1; i >= 1; i-- {
			curr := int64(1)
			for j := i; j >= 1; j-- {
				ret = append(ret, curr)
				curr *= -1
			}
		}
		return ret
	}
	for i := n - 1; i >= 1; i-- {
		curr := int64(1)
		if i&1 == 0 {
			curr *= -1
		}
		for j := i; j >= 1; j-- {
			if i&1 == 1 && j == i {
				ret = append(ret, 0)
				continue
			}
			ret = append(ret, curr)
			curr *= -1
		}
	}
	return ret
}

package main

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

func MIN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			for i := 1; i < n*(n-1)/2+1; i++ {
				if i%2 == 1 {
					fmt.Println(1)
				} else {
					fmt.Println(-1)
				}
			}
		} else {
			t := int(n / 2)
			for k := t - 1; k > -1; k-- {
				for j := 1; j < t; j++ {
					fmt.Println(1)
				}
				fmt.Println(0)
				for m := 1; m < k+1; m++ {
					fmt.Println(-1)
				}
			}
			for l := 1; l < 2*t-2; l++ {
				fmt.Println(1)
			}
		}

	}

}

package main

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

func MIN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			for i := 1; i < n*(n-1)/2+1; i++ {
				if i%2 == 1 {
					fmt.Println(1)
				} else {
					fmt.Println(-1)
				}
			}
		} else {
			t := int(n / 2)
			for k := t - 1; k > -1; k-- {
				for j := 1; j < t; j++ {
					fmt.Println(1)
				}
				fmt.Println(0)
				for m := 1; m < k+1; m++ {
					fmt.Println(-1)
				}
			}
			for l := 1; l < 2*t-1; l++ {
				fmt.Println(1)
			}
		}

	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

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

		for i := 0; i < len(res); i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int) (res []int) {
	res = make([]int, 0, n*(n-1)/2)
	mat := make([][]int, n)

	if n&1 == 1 {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := 1; j < n; j++ {
				k := (i + j) % n
				if j <= n/2 {
					mat[i][k] = 1
				} else {
					mat[i][k] = -1
				}
			}

		}
	} else {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := 0; j < (n-2)/2; j++ {
				k := (i + j + 1) % n
				mat[i][k] = 1
			}
			for j := (n - 2) / 2; j < n-2; j++ {
				k := (i + j + 1) % n
				mat[i][k] = -1
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			res = append(res, mat[i][j])
		}
	}
	return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type nb struct{ to, i int }

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]nb, n)
		m := 0
		for i := 0; i < n; i++ {
			j := i + 1
			if n&1 == 0 && i&1 == 0 {
				j++
				m++
			}
			for ; j < n; j++ {
				g[i] = append(g[i], nb{j, m})
				g[j] = append(g[j], nb{i, m})
				m++
			}
		}

		ans := make([]int, m)
		vis := make([]bool, m)
		pre := 0
		var f func(int)
		f = func(v int) {
			for len(g[v]) > 0 {
				e := g[v][0]
				g[v] = g[v][1:]
				if w, i := e.to, e.i; !vis[i] {
					vis[i] = true
					f(w)
					if w == pre {
						v, w = w, v
					}
					if v < w {
						ans[i] = 1
					} else {
						ans[i] = -1
					}
					pre = w
				}
			}
		}
		f(0)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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


It is the hard version of the problem. The only difference is that in this version $$$1 \le n \le 300$$$.In the cinema seats can be represented as the table with $$$n$$$ rows and $$$m$$$ columns. The rows are numbered with integers from $$$1$$$ to $$$n$$$. The seats in each row are numbered with consecutive integers from left to right: in the $$$k$$$-th row from $$$m (k - 1) + 1$$$ to $$$m k$$$ for all rows $$$1 \le k \le n$$$. $$$1$$$$$$2$$$$$$\cdots$$$$$$m - 1$$$$$$m$$$$$$m + 1$$$$$$m + 2$$$$$$\cdots$$$$$$2 m - 1$$$$$$2 m$$$$$$2m + 1$$$$$$2m + 2$$$$$$\cdots$$$$$$3 m - 1$$$$$$3 m$$$$$$\vdots$$$$$$\vdots$$$$$$\ddots$$$$$$\vdots$$$$$$\vdots$$$$$$m (n - 1) + 1$$$$$$m (n - 1) + 2$$$$$$\cdots$$$$$$n m - 1$$$$$$n m$$$ The table with seats indices There are $$$nm$$$ people who want to go to the cinema to watch a new film. They are numbered with integers from $$$1$$$ to $$$nm$$$. You should give exactly one seat to each person.It is known, that in this cinema as lower seat index you have as better you can see everything happening on the screen. $$$i$$$-th person has the level of sight $$$a_i$$$. Let's define $$$s_i$$$ as the seat index, that will be given to $$$i$$$-th person. You want to give better places for people with lower sight levels, so for any two people $$$i$$$, $$$j$$$ such that $$$a_i < a_j$$$ it should be satisfied that $$$s_i < s_j$$$.After you will give seats to all people they will start coming to their seats. In the order from $$$1$$$ to $$$nm$$$, each person will enter the hall and sit in their seat. To get to their place, the person will go to their seat's row and start moving from the first seat in this row to theirs from left to right. While moving some places will be free, some will be occupied with people already seated. The inconvenience of the person is equal to the number of occupied seats he or she will go through.Let's consider an example: $$$m = 5$$$, the person has the seat $$$4$$$ in the first row, the seats $$$1$$$, $$$3$$$, $$$5$$$ in the first row are already occupied, the seats $$$2$$$ and $$$4$$$ are free. The inconvenience of this person will be $$$2$$$, because he will go through occupied seats $$$1$$$ and $$$3$$$.Find the minimal total inconvenience (the sum of inconveniences of all people), that is possible to have by giving places for all people (all conditions should be satisfied).

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 300$$$) — the number of rows and places in each row respectively. The second line of each test case contains $$$n \cdot m$$$ integers $$$a_1, a_2, \ldots, a_{n \cdot m}$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the sight level of $$$i$$$-th person. It's guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print a single integer — the minimal total inconvenience that can be achieved.

NoteIn the first test case, there is a single way to give seats: the first person sits in the first place and the second person — in the second. The total inconvenience is $$$1$$$.In the second test case the optimal seating looks like this:   In the third test case the optimal seating looks like this:   The number in a cell is the person's index that sits on this place.

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n, m int
		fmt.Fscan(input, &n, &m)
		q := n * m
		type test struct {
			Id    int
			Value int
			QQ    int
		}

		var B []test

		ARRAY := make([]int, q)
		for i := 0; i < q; i++ {
			fmt.Fscan(input, &ARRAY[i])
			var s test
			s.Id = i
			s.Value = ARRAY[i]
			B = append(B, s)

		}
		sort.Slice(B, func(i, j int) bool {
			return (B[i].Value < B[j].Value) || (B[i].Value == B[j].Value && B[i].Id < B[j].Id)
		})

		for i := 0; i < q; i++ {
			B[i].QQ = i / m
		}
		var Ans int

		for l := 0; l < n; l++ {
			for s := l*m + 1; s < (l+1)*m; s++ {
				for p := l * m; p < s; p++ {
					if B[s].Value > B[p].Value && B[s].Id > B[p].Id {
						Ans++
					}
				}
			}
		}

		fmt.Println(Ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
type Node struct{
	av int
	t int
}
type Nodes []Node
func (a Nodes)Len()int{
	return len(a)
}
func (a Nodes)Less(i, j int)bool{
	if a[i].av<a[j].av{
		return true
	}
	if a[i].av==a[j].av{
		return a[i].t<a[j].t
	}
	return false
}
func (a Nodes)Swap(i, j int){
	a[i],a[j]=a[j],a[i]
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		a := make([]int,n*m)
		l := Nodes{}
		for i:=0;i<n*m;i++{
			fmt.Fscan(in,&a[i])
			l = append(l,Node{a[i],i})
		}
		sort.Sort(l)
		//fmt.Println(l)
		ans := 0
		for i:=0;i<n;i++{
			for j:=0;j<m;j++{
				for k:=0;k<j;k++{
					if l[i*m+j].t>l[i*m+k].t&&l[i*m+j].av!=l[i*m+k].av{
						ans++
					}
				}
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Fenwick struct {
	v []int64
}

func NewFenwick(n int) *Fenwick {
	return &Fenwick{v: make([]int64, n+4)}
}

func (f *Fenwick) Add(pos int) {
	pos++
	for pos < len(f.v) {
		f.v[pos]++
		pos += lsb(pos)
	}
}

func (f *Fenwick) Get(pos int) int64 {
	pos++

	res := int64(0)
	for pos > 0 {
		res += f.v[pos]
		pos -= lsb(pos)
	}
	return res
}

func lsb(num int) int {
	return num & -num
}

type Placer struct {
	row, col  int
	left      int
	leftInRow int
	cols      int
}

func NewPlacer(row, col int, left int, cols int) *Placer {
	leftInRow := cols - col
	if leftInRow > left {
		leftInRow = left
	}

	return &Placer{
		row:       row,
		col:       col,
		left:      left,
		leftInRow: leftInRow,
		cols:      cols,
	}
}

func (p *Placer) Row() int {
	return p.row
}

func (p *Placer) Col() int {
	return p.col + p.leftInRow - 1
}

func (p *Placer) Shift() {
	p.leftInRow -= 1
	p.left -= 1

	if p.leftInRow <= 0 {
		p.row += 1
		p.col = 0
		p.leftInRow = p.left
		if p.leftInRow > p.cols {
			p.leftInRow = p.cols
		}
	}
}

func solve(a []int, rows, cols int) int64 {
	sorted := make([]int, len(a))
	copy(sorted, a)
	sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] })

	count := make(map[int]int)
	for _, x := range a {
		count[x]++
	}

	placers := make(map[int]*Placer)
	row, col := 0, 0
	for i := 0; i < len(a); i++ {
		if i == 0 || sorted[i] != sorted[i-1] {
			placers[sorted[i]] = NewPlacer(row, col, count[sorted[i]], cols)
		}

		col += 1
		if col >= cols {
			row++
			col = 0
		}
	}

	occupied := make([]*Fenwick, rows)
	for i := range occupied {
		occupied[i] = NewFenwick(cols + 1)
	}

	res := int64(0)
	for _, x := range a {
		row := placers[x].Row()
		col := placers[x].Col()
		placers[x].Shift()

		res += occupied[row].Get(col)
		occupied[row].Add(col)
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		n, m := stdin.Int(), stdin.Int()
		a := stdin.Ints(n * m)
		fmt.Println(solve(a, n, m))
	}
}

package main

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

type IndexTree struct {
	n            int
	arr          []int
	f            func(i, j int) int
	defaultValue int
}

type Aggregation interface {
	DefaultValue() int
	Aggregate(left, right int) int
}

type MinIndex struct{}

func (m MinIndex) DefaultValue() int { return math.MaxInt32 }
func (m MinIndex) Aggregate(left, right int) int {
	if left < right {
		return left
	} else {
		return right
	}
}

type MaxIndex struct{}

func (m MaxIndex) DefaultValue() int { return math.MinInt32 }
func (m MaxIndex) Aggregate(left, right int) int {
	if left > right {
		return left
	} else {
		return right
	}
}

type SumIndex struct{}

func (m SumIndex) DefaultValue() int             { return 0 }
func (m SumIndex) Aggregate(left, right int) int { return left + right }

func NewIndexTree(n int, a Aggregation) *IndexTree {
	arr := make([]int, n*4)
	for i := 0; i < len(arr); i++ {
		arr[i] = a.DefaultValue()
	}

	return &IndexTree{n, arr, a.Aggregate, a.DefaultValue()}
}

func (i *IndexTree) Add(k, v int) {
	i.traverse(1, 0, i.n, func(node, b, e int) bool {
		if b <= k && e >= k {
			i.arr[node] = i.f(i.arr[node], v)
			return true
		}
		return false
	})
}

func (i *IndexTree) Get(qb, qe int) int {
	res := i.defaultValue
	i.traverse(1, 0, i.n, func(node, b, e int) bool {
		if b >= qb && e <= qe {
			res = i.f(res, i.arr[node])
			return false
		}
		return !(qe < b || qb > e)
	})
	return res
}

func (i *IndexTree) traverse(node int, b, e int, do func(node, b, e int) bool) {
	if !do(node, b, e) {
		return
	}
	m := (b + e) / 2
	if b != e {
		i.traverse(node*2, b, m, do)
		i.traverse(node*2+1, m+1, e, do)
	}
}

type pair struct {
	a, i int
}

func reverse(arr []pair) {
	n := len(arr)
	for i := 0; i < n/2; i++ {
		arr[i], arr[n-i-1] = arr[n-i-1], arr[i]
	}
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

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

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscanf(r, "%d %d\n", &n, &m)
		arr := make([]pair, n*m)
		for i := 0; i < len(arr); i++ {
			arr[i].i = i
			fmt.Fscanf(r, "%d", &arr[i].a)
		}
		fmt.Fscanf(r, "\n")

		sort.Slice(arr, func(i, j int) bool {
			if arr[i].a != arr[j].a {
				return arr[i].a < arr[j].a
			}
			return arr[i].i < arr[j].i
		})

		b := 0
		for i := 0; i < len(arr); i++ {
			if i == 0 || arr[i].a != arr[i-1].a {
				reverse(arr[b:i])
				b = i
			}
			if i%m == 0 {
				reverse(arr[b:i])
				b = i
			}
		}
		reverse(arr[b : n*m])

		idx := NewIndexTree(n*m+1, SumIndex{})

		res := 0
		//fmt.Println(arr)
		for i, v := range arr {
			if i%m == 0 {
				idx = NewIndexTree(n*m+1, SumIndex{})
			}
			res += idx.Get(0, v.i)
			idx.Add(v.i, 1)
		}

		fmt.Println(res)
	}
}


Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.Fangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the following action: if x is odd, then he adds 1 to it, otherwise he divides x by 2. Fangy knows that for any positive integer number the process ends in finite time.How many actions should Fangy perform to get a number one from number x?

The first line contains a positive integer x in a binary system. It is guaranteed that the first digit of x is different from a zero and the number of its digits does not exceed 106.

NoteLet's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1.

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  count := len(s)-1
  for i := len(s)-1; i > 0; i-- {
    if s[i] == '1' {
      count += 2;
      for seek := i-1; seek > 0; seek-- {
        if s[seek] == '0' {
          count++
        }
      }
      break
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", count))
}


And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following:   during one run the minibus makes n stops, the i-th stop is in point (xi, 0)  coordinates of all the stops are different  the minibus drives at a constant speed, equal to vb  it can be assumed the passengers get on and off the minibus at a bus stop momentarily  Student can get off the minibus only at a bus stop  Student will have to get off the minibus at a terminal stop, if he does not get off earlier  the University, where the exam will be held, is in point (xu, yu)  Student can run from a bus stop to the University at a constant speed vs as long as needed  a distance between two points can be calculated according to the following formula:   Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.

The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.

In the only line output the answer to the problem — index of the optimum bus stop.

NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	var vb, vs, xu, yu float64

	fmt.Fscanf(reader, "%d %f %f\n", &n, &vb, &vs)
	stop := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%f", &stop[i])
		if i != n-1 {
			fmt.Fscanf(reader, " ")
		} else {
			fmt.Fscanf(reader, "\n")
		}
	}
	fmt.Fscanf(reader, "%f %f", &xu, &yu)
	min := 99999999999.0
	var minStop int
	for i := 1; i < n; i++ {
		t := stop[i]/vb + math.Sqrt((xu-stop[i])*(xu-stop[i])+yu*yu)/vs
		if t < min {
			minStop = i
			min = t
		} else if t == min {
			if math.Abs(xu-stop[minStop]) > math.Abs(xu-stop[i]) {
				minStop = i
				min = t
			}
		}
	}
	fmt.Printf("%d", minStop+1)
}

package main

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

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

	n, vb, vs := readThreeNums(reader)
	X := readNNums(reader, n)
	room := readNNums(reader, 2)

	fmt.Println(solve(n, vb, vs, X, room))
}

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 solve(n int, vb int, vs int, X []int, exam []int) int {
	time := make([]float64, n)
	v1 := float64(vs)
	v2 := float64(vb)
	var best = math.MaxFloat64
	for i := 0; i < n; i++ {
		t1 := float64(X[i]) / v2
		t2 := distance(exam[0], exam[1], X[i], 0) / v1
		time[i] = t1 + t2
		if i > 0 && time[i] < best {
			best = time[i]
		}
	}
	var pos int

	var dist = math.MaxFloat64
	for i := 0; i < n; i++ {
		if math.Abs(time[i]-best) < 1e-9 {
			tmp := distance(exam[0], exam[1], X[i], 0)
			if tmp < dist {
				dist = tmp
				pos = i
			}
		}
	}

	return pos + 1
}

func distance(a, b, c, d int) float64 {
	dx := float64(c - a)
	dy := float64(d - b)
	return math.Sqrt(dx*dx + dy*dy)
}

package main

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime, bestDist := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t, d := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if t < bestTime || (t == bestTime && d < bestDist) {
			bestTime = t
			bestIndex = i
			bestDist = d
		}
	}
	fmt.Println(bestIndex + 1)
}

func closeEnough(x, y float64) bool {
	return math.Abs(x-y) < 1e6
}

func time_for(ivb, ivs, ix, iux, iuy int) (t, d float64) {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t = x / vb

	// distance to school
	d = math.Sqrt((ux-x)*(ux-x) + uy*uy)

	// time running
	t += d / vs
	return

}

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

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		if i+1 == n {
			fmt.Scanf("%f\n", &stops[i])
		} else {
			fmt.Scanf("%f", &stops[i])
		}
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0

	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

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

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

	input1, _, _ := reader.ReadLine()
	inputList1 := strings.Split(string(input1), " ")
	input2, _, _ := reader.ReadLine()
	inputList2 := strings.Split(string(input2), " ")
	input3, _, _ := reader.ReadLine()
	inputList3 := strings.Split(string(input3), " ")

	busStopCount, _ := strconv.Atoi(string(inputList1[0]))
	vB, _ := strconv.ParseFloat(string(inputList1[1]), 64)
	vS, _ := strconv.ParseFloat(string(inputList1[2]), 64)

	busStops := make([]float64, 0)

	for i := 0; i < len(inputList2); i++ {
		value, _ := strconv.ParseFloat(string(inputList2[i]), 64)

		busStops = append(busStops, value)
	}

	uX, _ := strconv.ParseFloat(string(inputList3[0]), 64)
	uY, _ := strconv.ParseFloat(string(inputList3[1]), 64)

	var busStopValue1,busStopValue2 float64
	busStopNumber := -1
	busStopValue1 = -1
	busStopValue2 = -1

	for i := 0; i < busStopCount; i++ {
		if busStops[i] == 0 {
			continue
		}

		time1 := float64( busStops[i] / vB)
		time2 := math.Sqrt(float64(math.Pow(float64(uX - busStops[i]), 2) + float64(uY * uY))) / vS

		if busStopValue1 == -1 {
			busStopValue1 = time1
			busStopValue2 = time2
			busStopNumber = i
		} else if time1 + time2 < busStopValue1 + busStopValue2 {
			busStopValue1 = time1
			busStopValue2 = time2
			busStopNumber = i
		} else if time1 + time2 == busStopValue1 + busStopValue2 && time2 < busStopValue2 {
			busStopValue1 = time1
			busStopValue2 = time2
			busStopNumber = i
		}
	}

	fmt.Println(busStopNumber + 1)
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	var vb, vs, xu, yu float64

	fmt.Fscanf(reader, "%d %f %f\n", &n, &vb, &vs)
	stop := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%f", &stop[i])
		if i != n-1 {
			fmt.Fscanf(reader, " ")
		} else {
			fmt.Fscanf(reader, "\n")
		}
	}
	fmt.Fscanf(reader, "%f %f", &xu, &yu)
	min := 99999999999.0
	var minStop int
	for i := 1; i < n; i++ {
		t := stop[i]/vb + math.Sqrt((xu-stop[i])*(xu-stop[i])+yu*yu)/vs
		if t < min {
			minStop = i + 1
			min = t
		}
	}
	fmt.Printf("%d", minStop)
}

package main

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

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

	n, vb, vs := readThreeNums(reader)
	X := readNNums(reader, n)
	room := readNNums(reader, 2)

	fmt.Println(solve(n, vb, vs, X, room))
}

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 solve(n int, vb int, vs int, X []int, exam []int) int {
	time := make([]float64, n)
	v1 := float64(vs)
	v2 := float64(vb)
	var best = math.MaxFloat64
	var pos int
	for i := 0; i < n; i++ {
		t1 := float64(X[0]) / v1
		t2 := distance(exam[0], exam[1], X[i], 0) / v2
		time[i] = t1 + t2
		if i > 0 && time[i] < best {
			best = time[i]
			pos = i
		}
	}
	return pos + 1
}

func distance(a, b, c, d int) float64 {
	dx := float64(c - a)
	dy := float64(d - b)
	return math.Sqrt(dx*dx + dy*dy)
}

package main

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if bestTime > t {
			bestTime = t
			bestIndex = i
		}
	}
	fmt.Println(bestIndex + 1)
}

func time_for(ivb, ivs, ix, iux, iuy int) float64 {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t := x / vb
	// time running
	t += math.Sqrt((ux-x)*(ux-x)+uy*uy) / vs
	return t

}

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime, bestDist := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t, d := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if t < bestTime || (t == bestTime && d < bestDist) {
			bestTime = t
			bestIndex = i
			bestDist = d
		}
	}
	fmt.Println(bestIndex + 1)
}

func closeEnough(x, y float64) bool {
	return math.Abs(x-y) < 1e6
}

func time_for(ivb, ivs, ix, iux, iuy int) (t, d float64) {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t = x / vb

	// distance to school
	d = math.Sqrt((ux-x)*(ux-x) + uy*uy)
	// time running
	t += math.Sqrt(d / vs)
	return

}

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime, bestDist := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t, d := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if t < bestTime || (closeEnough(t, bestTime) && d < bestDist) {
			bestTime = t
			bestIndex = i
			bestDist = d
		}
	}
	fmt.Println(bestIndex + 1)
}

func closeEnough(x, y float64) bool {
	return math.Abs(x-y) < 1e6
}

func time_for(ivb, ivs, ix, iux, iuy int) (t, d float64) {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t = x / vb

	// distance to school
	d = math.Sqrt((ux-x)*(ux-x) + uy*uy)
	// time running
	t += math.Sqrt(d / vs)
	return

}

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

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &stops[i])
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	fmt.Printf("%d %f %f\n%f %f\n", n, vb, vs, xu, yu)
	for i := 0; i < n; i++ {
		fmt.Printf("%f ", stops[i])
	}
	fmt.Println()

	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &stops[i])
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		if i+1 == n {
			fmt.Scanf("%f\n", &stops[i])
		} else {
			fmt.Scanf("%f", &stops[i])
		}
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	fmt.Printf("%d %f %f\n%f %f\n", n, vb, vs, xu, yu)
	for i := 0; i < n; i++ {
		fmt.Printf("%f ", stops[i])
	}
	fmt.Println()

	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &stops[i])
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}


It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.It is known that the i-th contestant will eat si slices of pizza, and gain ai happiness for each slice of type 1 pizza they eat, and bi happiness for each slice of type 2 pizza they eat. We can order any number of type 1 and type 2 pizzas, but we want to buy the minimum possible number of pizzas for all of the contestants to be able to eat their required number of slices. Given that restriction, what is the maximum possible total happiness that can be achieved?

The first line of input will contain integers N and S (1 ≤ N ≤ 105, 1 ≤ S ≤ 105), the number of contestants and the number of slices per pizza, respectively. N lines follow. The i-th such line contains integers si, ai, and bi (1 ≤ si ≤ 105, 1 ≤ ai ≤ 105, 1 ≤ bi ≤ 105), the number of slices the i-th contestant will eat, the happiness they will gain from each type 1 slice they eat, and the happiness they will gain from each type 2 slice they eat, respectively.

Print the maximum total happiness that can be achieved.

NoteIn the first example, you only need to buy one pizza. If you buy a type 1 pizza, the total happiness will be 3·5 + 4·6 + 5·9 = 84, and if you buy a type 2 pizza, the total happiness will be 3·7 + 4·7 + 5·5 = 74.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	for _, b := range in.Bytes() {
		res = res*10 + int64(b-'0')
	}
	return res
}

type person struct {
	s, a, b int64
}

type byDiff []person

func (s byDiff) Len() int           { return len(s) }
func (s byDiff) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byDiff) Less(i, j int) bool {
	di := s[i].b - s[i].a
	if di < 0 {
		di *= -1
	}
	dj := s[j].b - s[j].a
	if dj < 0 {
		dj *= -1
	}
	return di > dj
}

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	s := readInt()
	totSlices := int64(0)
	ps := make([]person, n)
	for i := range ps {
		ps[i].s = readInt()
		ps[i].a = readInt()
		ps[i].b = readInt()
		totSlices += ps[i].s
	}
	sort.Sort(byDiff(ps))
	pizzas := (totSlices + s - 1) / s
	_, ans := ternarySearchMax(pizzas, func(a int64) int64 {
		var res int64
		b := pizzas - a
		a *= s
		b *= s
		for _, p := range ps {
			if p.a >= p.b {
				eat := p.s
				if a < p.s {
					eat = a
				}
				left := p.s - eat
				res += eat * p.a
				a -= eat
				if left > 0 {
					res += left * p.b
					b -= left
				}
			} else {
				eat := p.s
				if b < p.s {
					eat = b
				}
				left := p.s - eat
				res += eat * p.b
				b -= eat
				if left > 0 {
					res += left * p.a
					a -= left
				}
			}
		}
		return res
	})
	fmt.Println(ans)
}

func ternarySearchMax(hi int64, f func(int64) int64) (pos, val int64) {
	lo := int64(0)
	for hi-lo > 10 {
		m1 := lo + (hi-lo)/3
		m2 := hi - (hi-lo)/3
		if f(m1) < f(m2) {
			lo = m1
		} else {
			hi = m2 - 1
		}
	}
	m := f(lo)
	mx := lo
	for x := lo + 1; x <= hi; x++ {
		if y := f(x); y > m {
			m = y
			mx = x
		}
	}
	return mx, m
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	for _, b := range in.Bytes() {
		res = res*10 + int64(b-'0')
	}
	return res
}

type person struct {
	s, a, b int64
}

type byDiff []person

func (s byDiff) Len() int           { return len(s) }
func (s byDiff) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byDiff) Less(i, j int) bool { return s[i].b-s[i].a < s[j].b-s[j].a }

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	s := readInt()
	totSlices := int64(0)
	ps := make([]person, n)
	for i := range ps {
		ps[i].s = readInt()
		ps[i].a = readInt()
		ps[i].b = readInt()
		totSlices += ps[i].s
	}
	sort.Sort(byDiff(ps))
	pizzas := (totSlices + s - 1) / s
	_, ans := ternarySearchMax(pizzas, func(a int64) int64 {
		var res int64
		b := pizzas - a
		a *= s
		b *= s
		for _, p := range ps {
			if p.a >= p.b {
				eat := p.s
				if a < p.s {
					eat = a
				}
				left := p.s - eat
				res += eat * p.a
				a -= eat
				if left > 0 {
					res += left * p.b
					b -= left
				}
			} else {
				eat := p.s
				if b < p.s {
					eat = b
				}
				left := p.s - eat
				res += eat * p.b
				b -= eat
				if left > 0 {
					res += left * p.a
					a -= left
				}
			}
		}
		return res
	})
	fmt.Println(ans)
}

func ternarySearchMax(hi int64, f func(int64) int64) (pos, val int64) {
	lo := int64(0)
	for hi-lo > 10 {
		m1 := lo + (hi-lo)/3
		m2 := hi - (hi-lo)/3
		if f(m1) < f(m2) {
			lo = m1
		} else {
			hi = m2 - 1
		}
	}
	m := f(lo)
	mx := lo
	for x := lo + 1; x <= hi; x++ {
		if y := f(x); y > m {
			m = y
			mx = x
		}
	}
	return mx, m
}