Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:  the final tournament features n teams (n is always even)  the first n / 2 teams (according to the standings) come through to the knockout stage  the standings are made on the following principle: for a victory a team gets 3 points, for a draw — 1 point, for a defeat — 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place — in decreasing order of the difference between scored and missed goals; in the third place — in the decreasing order of scored goals  it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity. You are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.

The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) / 2 lines describe the held matches in the format name1-name2 num1:num2, where name1, name2 — names of the teams; num1, num2 (0 ≤ num1, num2 ≤ 100) — amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.

Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.

package main

import (
	"sort"
	"bytes"
	"os"
	"io/ioutil"
	"fmt"
	"strings"
)
type Team struct {
	Name string
	Point int
	DeltaGoal int
	Goal int
}

type TeamList []*Team
func (this TeamList) Len() int {
	return len(this)
}
func (this TeamList) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}
func (this TeamList) Less(i, j int) bool {
	return this[i].Point > this[j].Point ||
	(this[i].Point == this[j].Point && this[i].DeltaGoal > this[j].DeltaGoal) ||
	(this[i].Point == this[j].Point && this[i].DeltaGoal == this[j].DeltaGoal && this[i].Goal > this[j].Goal)
}

type SortByName []*Team
func (this SortByName) Len() int {
	return len(this)
}
func (this SortByName) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}
func (this SortByName) Less(i, j int) bool {
	return this[i].Name < this[j].Name
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	teamMap := map[string]*Team{}
	fmt.Fscanf(reader, "%d\r\n", &n)
	for i := 0;i < n;i ++ {
		var team string
		fmt.Fscanf(reader, "%s\r\n", &team)
		teamMap[team] = &Team {
			Name: team,
		}
	}
	for i := 0;i < n * (n - 1) / 2;i ++ {
		var scoreA, scoreB int
		var match string
		fmt.Fscanf(reader, "%s %d:%d\r\n", &match, &scoreA, &scoreB)
		teams := strings.Split(match, "-")
		if scoreA > scoreB {
			teamMap[teams[0]].Point += 3
		} else if scoreB > scoreA {
			teamMap[teams[1]].Point +=3
		} else {
			teamMap[teams[0]].Point ++
			teamMap[teams[1]].Point ++
		}
		teamMap[teams[0]].DeltaGoal += (scoreA - scoreB)
		teamMap[teams[1]].DeltaGoal += (scoreB - scoreA)
		teamMap[teams[0]].Goal += scoreA
		teamMap[teams[1]].Goal += scoreB
	}
	teamList := make([]*Team, 0, n)
	for _, team := range teamMap {
		teamList = append(teamList, team)
	}
	sort.Sort(TeamList(teamList))
	teamList = teamList[:(n/2)]
	sort.Sort(SortByName(teamList))
	for i := 0;i < n/2;i ++ {
		fmt.Printf("%s\n", teamList[i].Name)
	}
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

type Team struct {
  Name string
  Points, GoalsFor, GoalsAgainst, Differential int
}
func (team *Team) toS() string {
  return fmt.Sprintf("Name: %s, Points: %d, GoalsFor: %d, GoalsAgainst: %d," +
      " Differential: %d", team.Name, team.Points, team.GoalsFor,
      team.GoalsAgainst, team.Differential)
}
type Teams []*Team
func (teams Teams) Len() int {
  return len(teams)
}
func (teams Teams) Swap(i, j int) {
  teams[i], teams[j] = teams[j], teams[i]
}
func (teams Teams) Less(i, j int) bool {
  a, b := teams[i], teams[j]
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  if a.Differential != b.Differential {
    return a.Differential > b.Differential
  }
  if a.GoalsFor != b.GoalsFor {
    return a.GoalsFor > b.GoalsFor
  }
  return false
}

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

  n := getI()
  nameToTeam := map[string]*Team{}
  teams := make([]*Team, n)
  for i := 0; i < n; i++ {
    name := getS()
    team := &Team{ Name: name }
    nameToTeam[name] = team
    teams[i] = team
  }
  for i := n*(n-1)/2; i != 0; i-- {
    names := strings.Split(getS(), "-")
    goals := strings.Split(getS(), ":")
    for j := 0; j < 2; j++ {
      team := nameToTeam[names[j]]
      goalsFor, _ := strconv.Atoi(goals[j])
      goalsAgainst, _ := strconv.Atoi(goals[(j+1)%2])
      team.GoalsFor += goalsFor
      team.GoalsAgainst += goalsAgainst
      team.Differential += goalsFor - goalsAgainst
      if goalsFor > goalsAgainst {
        team.Points += 3
      } else if goalsFor == goalsAgainst {
        team.Points++
      }
    }
  }
  sort.Sort(Teams(teams))
  result := make([]string, len(teams)/2)
  for i := range result {
    result[i] = teams[i].Name
  }
  sort.Strings(result)
  for _, s := range result {
    writer.WriteString(fmt.Sprintf("%s\n", s))
  }
}

package main

import (
	"sort"
	"bytes"
	"os"
	"io/ioutil"
	"fmt"
	"strings"
)
type Team struct {
	Name string
	Score int
}

type SortByScore []*Team
func (this SortByScore) Len() int {
	return len(this)
}
func (this SortByScore) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}
func (this SortByScore) Less(i, j int) bool {
	return this[i].Score > this[j].Score
}

type SortByName []*Team
func (this SortByName) Len() int {
	return len(this)
}
func (this SortByName) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}
func (this SortByName) Less(i, j int) bool {
	return this[i].Name < this[j].Name
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	scores := map[string]int{}
	fmt.Fscanf(reader, "%d\r\n", &n)
	for i := 0;i < n;i ++ {
		var team string
		fmt.Fscanf(reader, "%s\r\n", &team)
		scores[team] = 0
	}
	for i := 0;i < n * (n - 1) / 2;i ++ {
		var scoreA, scoreB int
		var match string
		fmt.Fscanf(reader, "%s %d:%d\r\n", &match, &scoreA, &scoreB)
		teams := strings.Split(match, "-")
		if scoreA > scoreB {
			scores[teams[0]] +=3
		} else if scoreB > scoreA {
			scores[teams[1]] +=3
		} else {
			scores[teams[0]] ++
			scores[teams[1]] ++
		}
	}
	teamList := make([]*Team, 0, n)
	for team, score := range scores {
		teamList = append(teamList, &Team{
			Name : team,
			Score: score,
		})
	}
	sort.Sort(SortByScore(teamList))
	teamList = teamList[:(n/2)]
	sort.Sort(SortByName(teamList))
	for i := 0;i < n/2;i ++ {
		fmt.Printf("%s\n", teamList[i].Name)
	}
}

package main

import (
	"sort"
	"bytes"
	"os"
	"io/ioutil"
	"fmt"
	"strings"
)
type Team struct {
	Name string
	Point int
	DeltaGoal int
	Goal int
}

type TeamList []*Team
func (this TeamList) Len() int {
	return len(this)
}
func (this TeamList) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}
func (this TeamList) Less(i, j int) bool {
	return this[i].Point > this[j].Point ||
	(this[i].Point == this[j].Point && this[i].DeltaGoal > this[j].DeltaGoal) ||
	(this[i].Point == this[j].Point && this[i].DeltaGoal == this[j].DeltaGoal && this[i].Goal > this[j].DeltaGoal)
}

type SortByName []*Team
func (this SortByName) Len() int {
	return len(this)
}
func (this SortByName) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}
func (this SortByName) Less(i, j int) bool {
	return this[i].Name < this[j].Name
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	teamMap := map[string]*Team{}
	fmt.Fscanf(reader, "%d\r\n", &n)
	for i := 0;i < n;i ++ {
		var team string
		fmt.Fscanf(reader, "%s\r\n", &team)
		teamMap[team] = &Team {
			Name: team,
		}
	}
	for i := 0;i < n * (n - 1) / 2;i ++ {
		var scoreA, scoreB int
		var match string
		fmt.Fscanf(reader, "%s %d:%d\r\n", &match, &scoreA, &scoreB)
		teams := strings.Split(match, "-")
		if scoreA > scoreB {
			teamMap[teams[0]].Point += 3
		} else if scoreB > scoreA {
			teamMap[teams[1]].Point +=3
		} else {
			teamMap[teams[0]].Point ++
			teamMap[teams[1]].Point ++
		}
		teamMap[teams[0]].DeltaGoal += (scoreA - scoreB)
		teamMap[teams[1]].DeltaGoal += (scoreB - scoreA)
		teamMap[teams[0]].Goal += scoreA
		teamMap[teams[1]].Goal += scoreB
	}
	teamList := make([]*Team, 0, n)
	for _, team := range teamMap {
		teamList = append(teamList, team)
	}
	sort.Sort(TeamList(teamList))
	teamList = teamList[:(n/2)]
	sort.Sort(SortByName(teamList))
	for i := 0;i < n/2;i ++ {
		fmt.Printf("%s\n", teamList[i].Name)
	}
}


Is it really?! The robot only existing in my imagination?! The Colossal Walking Robot?!!— Kochiya Sanae Sanae made a giant robot — Hisoutensoku, but something is wrong with it. To make matters worse, Sanae can not figure out how to stop it, and she is forced to fix it on-the-fly.The state of a robot can be represented by an array of integers of length $$$n$$$. Initially, the robot is at state $$$a$$$. She wishes to turn it into state $$$b$$$. As a great programmer, Sanae knows the art of copy-and-paste. In one operation, she can choose some segment from given segments, copy the segment from $$$b$$$ and paste it into the same place of the robot, replacing the original state there. However, she has to ensure that the sum of $$$a$$$ does not change after each copy operation in case the robot go haywire. Formally, Sanae can choose segment $$$[l,r]$$$ and assign $$$a_i = b_i$$$ ($$$l\le i\le r$$$) if $$$\sum\limits_{i=1}^n a_i$$$ does not change after the operation.Determine whether it is possible for Sanae to successfully turn the robot from the initial state $$$a$$$ to the desired state $$$b$$$ with any (possibly, zero) operations.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2\cdot 10^4$$$) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \leq n\leq 2\cdot 10^5$$$, $$$1 \leq m\leq 2\cdot 10^5$$$) — the length of $$$a$$$, $$$b$$$ and the number of segments. The second line contains $$$n$$$ intergers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial state $$$a$$$. The third line contains $$$n$$$ intergers $$$b_1,b_2,\ldots,b_n$$$ ($$$1 \leq b_i \leq 10^9$$$) — the desired state $$$b$$$. Then $$$m$$$ lines follow, the $$$i$$$-th line contains two intergers $$$l_i,r_i$$$ ($$$1 \leq l_i < r_i \leq n$$$) — the segments that can be copy-pasted by Sanae. It is guaranteed that both the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10 ^ 5$$$.

For each test case, print "YES" (without quotes) if $$$a$$$ can be turned into $$$b$$$, or "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

NoteTest case 1:One possible way of turning $$$a$$$ to $$$b$$$:First, select $$$[1,3]$$$. After the operation, $$$a=[3,2,5,2,3]$$$.Then, select $$$[2,5]$$$. After the operation, $$$a=[3,2,5,4,1]=b$$$.Test case 2:It can be shown that it is impossible to turn $$$a$$$ into $$$b$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }

type rbtreesetnode struct { left, right, up int32; red bool; key int }
type rbtreeset struct {
	lessthan func(a, b int) bool; tree []rbtreesetnode; root int32; recycler []int32; sz int; minidx int32
	maxidx int32
}
type rbtreesetIterator interface { Next() (ok bool); Prev() (ok bool); Key() int }
type rbtreesetiter struct { cur int32; key int; rbtree *rbtreeset }
func (i *rbtreesetiter) Key() int { return i.key }
func (i *rbtreesetiter) Next() bool {
	rbtree := i.rbtree; v := rbtree.nextidx(i.cur); if v == 0 { return false }; i.cur, i.key = v, rbtree.tree[v].key
	return true
}
func (i *rbtreesetiter) Prev() bool {
	rbtree := i.rbtree; v := rbtree.previdx(i.cur); if v == 0 { return false }; i.cur, i.key = v, rbtree.tree[v].key
	return true
}
func Newrbtreeset(lessthan func(a, b int) bool) *rbtreeset {
	q := &rbtreeset{lessthan, make([]rbtreesetnode, 2), int32(0), make([]int32, 0), 0, 0, 0}
	q.tree[0].left, q.tree[0].right, q.tree[0].up, q.tree[0].red = 0, 0, 0, false; q.recycler = append(q.recycler, 1)
	return q
}
func (q *rbtreeset) Add(k int) {
	if q.sz == 0 {
		z := q.getNewNodenum(); tree := q.tree; q.minidx, q.maxidx, q.sz, q.root = z, z, q.sz+1, z
		tree[z].key, tree[z].up, tree[z].left, tree[z].right, tree[z].red = k, 0, 0, 0, false; return
	}
	y, cmp := q.findInsertionPoint(k); if cmp == 0 { return }; z := q.getNewNodenum(); q.sz += 1; tree := q.tree
	tree[z].key, tree[z].up, tree[z].left, tree[z].right, tree[z].red = k, y, 0, 0, true
	if cmp < 0 { tree[y].left = z } else { tree[y].right = z }
	if q.sz == 0 || q.lessthan(k, tree[q.minidx].key) { q.minidx = z }
	if q.sz == 0 || q.lessthan(tree[q.maxidx].key, k) { q.maxidx = z }; var p, g, u int32
	for p = tree[z].up; tree[p].red; p = tree[z].up {
		g = tree[p].up ; if g == 0 { break }
		if p == tree[g].left {
			u = tree[g].right
			if tree[u].red { tree[p].red, tree[u].red, tree[g].red, z = false, false, true, g; continue }
			if z == tree[p].right { z = p; q.rotleft(z); p = tree[z].up }; q.rotright(g)
			tree[g].red, tree[p].red = true, false
		} else {
			u = tree[g].left
			if tree[u].red { tree[p].red, tree[u].red, tree[g].red, z = false, false, true, g; continue }
			if z == tree[p].left { z = p; q.rotright(z); p = tree[z].up }; q.rotleft(g)
			tree[g].red, tree[p].red = true, false
		}
	}
	tree[q.root].red = false
}
func (q *rbtreeset) Delete(k int) bool {
	if q.sz == 0 { return false }; z, cmp := q.findInsertionPoint(k); if cmp != 0 { return false }; q.sz--
	q.recycler = append(q.recycler, z)
	if q.sz > 0 && !q.lessthan(q.tree[q.minidx].key, k) { q.minidx = q.nextidx(q.minidx) }
	if q.sz > 0 && !q.lessthan(k, q.tree[q.maxidx].key) { q.maxidx = q.previdx(q.maxidx) }
	if q.sz == 0 { q.root = 0; return true }; tree := q.tree; var x int32; y, y_orig_red := z, tree[z].red
	if tree[z].left == 0 {
		x = tree[z].right; q.rbTransplant(z, x)
	} else if tree[z].right == 0 {
		x = tree[z].left; q.rbTransplant(z, x)
	} else {
		y = q.findminidx(tree[z].right); y_orig_red = tree[y].red; x = tree[y].right
		if tree[y].up == z {
			tree[x].up = y
		} else {
			q.rbTransplant(y, x); tree[y].right = tree[z].right; tree[tree[y].right].up = y
		}
		q.rbTransplant(z, y); tree[y].left = tree[z].left; tree[tree[y].left].up = y; tree[y].red = tree[z].red
	}
	if !y_orig_red {
		for q.root != x && !tree[x].red {
			p := tree[x].up
			if tree[p].left == x {
				s := tree[p].right
				if tree[s].red { tree[s].red = false; tree[p].red = true; q.rotleft(p); s = tree[p].right }
				c := tree[s].left; d := tree[s].right
				if !tree[c].red && !tree[d].red {
					tree[s].red = true; x = p
				} else {
					if !tree[d].red { tree[c].red = false; tree[s].red = true; q.rotright(s); s = tree[p].right }
					tree[s].red = tree[p].red; tree[p].red = false; tree[tree[s].right].red = false; q.rotleft(p)
					x = q.root
				}
			} else {
				s := tree[p].left
				if tree[s].red { tree[s].red = false; tree[p].red = true; q.rotright(p); s = tree[p].left }
				c := tree[s].right; d := tree[s].left
				if !tree[c].red && !tree[d].red {
					tree[s].red = true; x = p
				} else {
					if !tree[d].red { tree[c].red = false; tree[s].red = true; q.rotleft(s); s = tree[p].left }
					tree[s].red = tree[p].red; tree[p].red = false; tree[tree[s].left].red = false; q.rotright(p)
					x = q.root
				}
			}
		}
		tree[x].red = false
	}
	return true
}
func (q *rbtreeset) Clear() {
	q.tree, q.root, q.recycler, q.sz = q.tree[:2], 0, q.recycler[:0], 0; q.recycler = append(q.recycler, int32(1))
}
func (q *rbtreeset) IsEmpty() bool { return q.sz == 0 }
func (q *rbtreeset) Contains(k int) bool { _, cmp := q.findInsertionPoint(k); return cmp == 0 }
func (q *rbtreeset) Count(k int) int { _, cmp := q.findInsertionPoint(k); if cmp == 0 { return 1 }; return 0 }
func (q *rbtreeset) Len() int { return q.sz }
func (q *rbtreeset) MinKey() (k int) {
	if q.sz == 0 { panic("Called MinKey on an empty rbtreeset") }; return q.tree[q.minidx].key
}
func (q *rbtreeset) MaxKey() (k int) {
	if q.sz == 0 { panic("Called MaxKey on an empty rbtreeset") }; return q.tree[q.maxidx].key
}
func (q *rbtreeset) findLtIdx(k int) (int32, bool) {
	if q.sz == 0 || !q.lessthan(q.tree[q.minidx].key, k) { return 0, false }; idx, pos := q.findInsertionPoint(k)
	if pos != 1 { idx = q.previdx(idx) }; return idx, true
}
func (q *rbtreeset) findLeIdx(k int) (int32, bool) {
	if q.sz == 0 || q.lessthan(k, q.tree[q.minidx].key) { return 0, false }; idx, pos := q.findInsertionPoint(k)
	if pos == -1 { idx = q.previdx(idx) }; return idx, true
}
func (q *rbtreeset) findGtIdx(k int) (int32, bool) {
	if q.sz == 0 || !q.lessthan(k, q.tree[q.maxidx].key) { return 0, false }; idx, pos := q.findInsertionPoint(k)
	if pos != -1 { idx = q.nextidx(idx) }; return idx, true
}
func (q *rbtreeset) findGeIdx(k int) (int32, bool) {
	if q.sz == 0 || q.lessthan(q.tree[q.maxidx].key, k) { return 0, false }; idx, pos := q.findInsertionPoint(k)
	if pos == 1 { idx = q.nextidx(idx) }; return idx, true
}
func (q *rbtreeset) FindLt(k int) (int, bool) {
	var ans int; idx, ok := q.findLtIdx(k); if ok { ans = q.tree[idx].key }; return ans, ok
}
func (q *rbtreeset) FindLe(k int) (int, bool) {
	var ans int; idx, ok := q.findLeIdx(k); if ok { ans = q.tree[idx].key }; return ans, ok
}
func (q *rbtreeset) FindGt(k int) (int, bool) {
	var ans int; idx, ok := q.findGtIdx(k); if ok { ans = q.tree[idx].key }; return ans, ok
}
func (q *rbtreeset) FindGe(k int) (int, bool) {
	var ans int; idx, ok := q.findGeIdx(k); if ok { ans = q.tree[idx].key }; return ans, ok
}
func (q *rbtreeset) FindLtIter(k int) (rbtreesetIterator, bool) {
	var ans *rbtreesetiter; idx, ok := q.findLtIdx(k); if ok { ans = &rbtreesetiter{idx, q.tree[idx].key, q} }
	return ans, ok
}
func (q *rbtreeset) FindLeIter(k int) (rbtreesetIterator, bool) {
	var ans *rbtreesetiter; idx, ok := q.findLeIdx(k); if ok { ans = &rbtreesetiter{idx, q.tree[idx].key, q} }
	return ans, ok
}
func (q *rbtreeset) FindGtIter(k int) (rbtreesetIterator, bool) {
	var ans *rbtreesetiter; idx, ok := q.findGtIdx(k); if ok { ans = &rbtreesetiter{idx, q.tree[idx].key, q} }
	return ans, ok
}
func (q *rbtreeset) FindGeIter(k int) (rbtreesetIterator, bool) {
	var ans *rbtreesetiter; idx, ok := q.findGeIdx(k); if ok { ans = &rbtreesetiter{idx, q.tree[idx].key, q} }
	return ans, ok
}
func (q *rbtreeset) FindIter(k int) (rbtreesetIterator, bool) {
	if q.sz == 0 { return nil, false }; idx, pos := q.findInsertionPoint(k); if pos != 0 { return nil, false }
	return &rbtreesetiter{idx, q.tree[idx].key, q}, true
}
func (q *rbtreeset) MinIter() (rbtreesetIterator, bool) {
	if q.sz == 0 { return nil, false }; idx := q.findminidx(q.root)
	return &rbtreesetiter{idx, q.tree[idx].key, q}, true
}
func (q *rbtreeset) MaxIter() (rbtreesetIterator, bool) {
	if q.sz == 0 { return nil, false }; idx := q.findmaxidx(q.root)
	return &rbtreesetiter{idx, q.tree[idx].key, q}, true
}
func (q *rbtreeset) rbTransplant(u, v int32) {
	tree := q.tree
	if tree[u].up == 0 {
		q.root = v
	} else {
		p := tree[u].up; if u == tree[p].left { tree[p].left = v } else { tree[p].right = v }
	}
	tree[v].up = tree[u].up
}
func (q *rbtreeset) findInsertionPoint(k int) (int32, int8) {
	n, lt, tree := q.root, q.lessthan, q.tree
	for {
		nkey := tree[n].key
		if lt(nkey, k) {
			r := tree[n].right; if r == 0 { return n, 1 }; n = r
		} else if lt(k, nkey) {
			l := tree[n].left; if l == 0 { return n, -1 }; n = l
		} else {
			return n, 0
		}
	}
}
func (q *rbtreeset) findmaxidx(n1 int32) int32 {
	tree := q.tree; for { xx := tree[n1].right; if xx == 0 { break }; n1 = xx }; return n1
}
func (q *rbtreeset) findminidx(n1 int32) int32 {
	tree := q.tree; for { xx := tree[n1].left; if xx == 0 { break }; n1 = xx }; return n1
}
func (q *rbtreeset) nextidx(cur int32) int32 {
	last := int32(-2); tree := q.tree; rr := tree[cur].right; if rr > 0 { return q.findminidx(rr) }
	for { last, cur = cur, tree[cur].up; if cur == 0 || tree[cur].left == last { break } }; return cur
}
func (q *rbtreeset) previdx(cur int32) int32 {
	last := int32(0); tree := q.tree; ll := tree[cur].left; if ll > 0 { return q.findmaxidx(ll) }
	for { last, cur = cur, tree[cur].up; if cur == 0 || tree[cur].right == last { break } }; return cur
}
func (q *rbtreeset) rotleft(x int32) {
	tree := q.tree; y := tree[x].right; p := tree[x].up; tree[x].right = tree[y].left
	if tree[y].left != 0 { tree[tree[y].left].up = x }; tree[y].up = p
	if p == 0 {
		q.root = y
	} else if x == tree[p].left {
		tree[p].left = y
	} else {
		tree[p].right = y
	}
	tree[y].left = x; tree[x].up = y
}
func (q *rbtreeset) rotright(x int32) {
	tree := q.tree; y := tree[x].left; p := tree[x].up; tree[x].left = tree[y].right
	if tree[y].right != 0 { tree[tree[y].right].up = x }; tree[y].up = p
	if p == 0 {
		q.root = y
	} else if x == tree[p].right {
		tree[p].right = y
	} else {
		tree[p].left = y
	}
	tree[y].right = x; tree[x].up = y
}
func (q *rbtreeset) getNewNodenum() int32 {
	l := len(q.recycler); newnode := q.recycler[l-1]; q.recycler = q.recycler[:l-1]
	if l == 1 { q.tree = append(q.tree, rbtreesetnode{}); q.recycler = append(q.recycler, int32(len(q.tree)-1)) }
	return newnode
}

func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := gis(N); B := gis(N); L,R := fill2(M)
		cum := make([]int64,N+1); cum[0] = 0
		for i:=0;i<N;i++ { cum[i+1] = cum[i] + int64(A[i] - B[i]) }
		q := make([]int,0,N+1); ss := Newrbtreeset(func (a,b int) bool { return a < b } )
		zerosb := make([]bool,N+1); for i:=0;i<=N;i++ { if cum[i] == 0 { zerosb[i] = true; q = append(q,i) } else { ss.Add(i) } }
		gr := make([][]int,N+1); for i:=0;i<M;i++ { lm1,r := L[i]-1,R[i]; gr[lm1] = append(gr[lm1],i); gr[r] = append(gr[r],i) }
		working := ia(N+1)
		for len(q) > 0 {
			x := q[0]; q = q[1:]
			for _,ii := range gr[x] {
				lm1,r := L[ii]-1,R[ii]
				if !zerosb[lm1] || !zerosb[r] { continue }
				working = working[:0]; last := lm1
				for {
					nxt,ok := ss.FindGt(last)
					if !ok || nxt > r { break }
					working = append(working,nxt)
					last = nxt
				}
				for _,w := range working { zerosb[w] = true; q = append(q,w); ss.Delete(w) }
			}
		}
		ans := "YES"; for _,b := range zerosb { if !b { ans = "NO" } }
		fmt.Fprintln(wrtr,ans)
	}
}


You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types:  Choose any array and clone it. After that there is one more copy of the chosen array.  Swap two elements from any two copies (maybe in the same copy) on any positions. You need to find the minimal number of operations needed to obtain a copy where all elements are equal.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output a single integer — the minimal number of operations needed to create at least one copy where all elements are equal.

NoteIn the first test case all elements in the array are already equal, that's why the answer is $$$0$$$.In the second test case it is possible to create a copy of the given array. After that there will be two identical arrays:$$$[ \ 0 \ 1 \ 3 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 0 \ 1 \ 3 \ 3 \ 7 \ 0 \ ]$$$After that we can swap elements in a way so all zeroes are in one array:$$$[ \ 0 \ \underline{0} \ \underline{0} \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ \underline{1} \ 1 \ 3 \ 3 \ 7 \ \underline{3} \ ]$$$Now let's create a copy of the first array:$$$[ \ 0 \ 0 \ 0 \ 3 \ 7 \ 0 \ ]$$$, $$$[ \ 0 \ 0 \ 0 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 1 \ 1 \ 3 \ 3 \ 7 \ 3 \ ]$$$Let's swap elements in the first two copies:$$$[ \ 0 \ 0 \ 0 \ \underline{0} \ \underline{0} \ 0 \ ]$$$, $$$[ \ \underline{3} \ \underline{7} \ 0 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 1 \ 1 \ 3 \ 3 \ 7 \ 3 \ ]$$$.Finally, we made a copy where all elements are equal and made $$$6$$$ operations.It can be proven that no fewer operations are enough.

package main

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

/*
the most common element count is v,
it increases by 2 times after one copy and swap, like:
v -> v*2 -> v*4 -> ...
until after m+1 copies, v*2^(m+1)>=n, operations ends,

copy times is m, if 2^m<n, need one more copy.
swap time: n-v.
*/
func max(a,b int)int{
  if a>b{return a}
  return b
}
func nxt(s *bufio.Scanner)int{
  s.Scan()
  v,_:=strconv.Atoi(s.Text())
  return v
}
func main(){
  s:=bufio.NewScanner(os.Stdin)
  s.Split(bufio.ScanWords)

  t:=nxt(s)
  var n,v,most int
  for i:=0;i<t;i++{
    n=nxt(s)

    most=0
    c:=map[int]int{}
    for j:=0;j<n;j++{
      v=nxt(s)
      c[v]++
      most=max(most,c[v])
    }

    res:=0
    for t:=most;t<n;t*=2{
      res+=1
    }
    fmt.Println(res+n-most)
  }
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, curr int
		fmt.Fscan(reader, &n)
		m := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			m[curr]++
		}
		max_count := 0
		for _, v := range m {
			if v > max_count {
				max_count = v
			}
		}
		ans := n - max_count
		for max_count < n {
			ans++
			max_count = max_count * 2
		}
		write_int(f, ans)
		write_string(f, "\n")

	}
}

// 00
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, curr int
		fmt.Fscan(reader, &n)
		m := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			m[curr]++
		}
		max_count := 0
		for _, v := range m {
			if v > max_count {
				max_count = v
			}
		}
		ans := n - max_count
		for max_count < n {
			ans++
			max_count = max_count * 2
		}
		fmt.Println(ans)

	}
}

package main

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

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

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

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

		h := make(map[int]int)

		for i := 0; i < len(a); i++ {
			h[a[i]]++
		}

		maxA := a[0]
		for k, v := range h {
			if v > h[maxA] {
				maxA = k
			}
		}

		count := 0
		current := h[maxA]

		for current < n {
			count += 1 + min(current, n-current)
			current = current * 2
		}

		fmt.Fprintln(out, count)
	}
}

package main

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

const mod = 998244353

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in,&n)
	arr := make([]int,n)
	mp := map[int]int{}
	mx := 0
	for i := 0;i < n;i++{
		fmt.Fscan(in,&arr[i])
		mp[arr[i]]++
		mx = max(mx,mp[arr[i]])
	}
	if mx == n{
		fmt.Fprintln(out,0)
		return
	}
	ans := 0
	cur := mx
	for mx < n{
		ans += 1
		mx *= 2
	}
	fmt.Fprintln(out,ans + n - cur)
}

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

func max(a,b int)int{
	if a > b{
		return a
	}
	return b
}
func min(a,b int)int{
	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"
	"os"
	"strconv"
)

// if it is an even number, then c and d will be 1 and 1 and we just need to find two primes number to a and b and a + b = n - 2

// if it is an odd number, then b and c and d will be 1, a will be n - 3 which is an even number

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

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

	for i := 0; i < t; i++ {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		max := 0
		freq := make(map[int]int)

		for k := 0; k < a; k++ {
			scanner.Scan()
			cur, _ := strconv.Atoi(scanner.Text())

			freq[cur]++
			if freq[cur] > max {
				max = freq[cur]
			}
		}

		sum, cnt := max, 0
		for sum < a {
			sum *= 2
			cnt++
		}

		fmt.Println(a - max + cnt)
	}

}

package main

// Problem description URL https://atcoder.jp/contests/abc236/tasks/abc240_a

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
)

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

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

type pair struct {
	Color int
	Size  int
}

var (
	n   = 0
	t   = 0
	a   []int
	res []int
	s   *list.List
	cur = 0
)

func gcd(a int, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}
func solve() {
	scan(&t)
	for t != 0 {
		t--
		scan(&n)
		count := map[int]int{}
		m := 0
		for i := 0; i < n; i++ {
			x := 0
			scan(&x)
			count[x]++
			m = int(math.Max(float64(m), float64(count[x])))
		}
		res := 0
		for m < n{
			res ++
			if(2*m >n){
				res += n-m
				break
			}
			res += m
			m *= 2
		}
		printf("%d\n", res)
	}
}

func main() {
	defer out.Flush()
	solve()
}

package main

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

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

	var err error

	var tests int
	_, err = fmt.Fscan(reader, &tests)
	if err != nil {
		panic(err.Error())
	}

	for t := 0; t < tests; t++ {
		var n int
		_, err = fmt.Fscan(reader, &n)
		if err != nil {
			panic(err.Error())
		}
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			var x int
			_, err = fmt.Fscan(reader, &x)
			if err != nil {
				panic(err.Error())
			}
			_, ok := cnt[x]
			if ok {
				cnt[x] += 1
			} else {
				cnt[x] = 1
			}
		}
		cur := 0
		for _, x := range cnt {
			if x > cur {
				cur = x
			}
		}
		ans := 0
		for cur < n {
			if cur+cur >= n {
				ans += 1 + n - cur
				cur = n
			} else {
				ans += 1 + cur
				cur += cur
			}
		}
		_, err := fmt.Fprintln(writer, ans)
		if err != nil {
			panic(err.Error())
		}
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	_, _ = fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		_, _ = fmt.Fscan(reader, &n)
		var counter = make(map[int]int)
		for i := 0; i < n; i++ {
			var d int
			_, _ = fmt.Fscan(reader, &d)
			counter[d]++
		}
		idx := -1
		for i := range counter {
			if idx == -1 || counter[i] > counter[idx] {
				idx = i
			}
		}
		ops := 0
		for counter[idx] < n {
			ops++
			if counter[idx] < n-counter[idx] {
				ops += counter[idx]
			} else {
				ops += n - counter[idx]
			}
			counter[idx] *= 2
		}
		fmt.Println(ops)
	}
}

package main

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

func main_div2_781_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	/* Begin Coding */
	sol = func() {
		var n int
		Fscan(in, &n)
		var ans, max int
		count := map[int]int{}
		for i := 0; i < n; i++ {
			var temp int
			Fscan(in, &temp)
			count[temp]++
			if max < count[temp] {
				max = count[temp]
			}
		}
		for max < n {
			ans++
			if n-max >= max {
				ans += max
			} else {
				ans += n - max
			}
			max *= 2
		}
		Fprintln(out, ans)
	}
	/* Code Ending */
	for i := 0; i < cas; i++ {
		sol()
	}

}

func main() {
	main_div2_781_B()
}

package main

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

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

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

	wr = bufio.NewWriter(os.Stdout)
}

func scanInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

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

func main() {
	defer wr.Flush()
	T := scanInt()

	for ; T > 0; T-- {
		n := scanInt()
		dict := make(map[int]int)
		for i := 0; i < n; i++ {
			dict[scanInt()]++
		}

		freq := math.MinInt
		for _, val := range dict {
			if val > freq {
				freq = val
			}
		}

		fmt.Fprintln(wr, solve(n, freq))
	}

}

func solve(n, k int) int {
	var count int
	for k < n {
		count++
		if 2*k >= n {
			count += n - k
			break
		}
		count += k
		k *= 2
	}

	return count
}

package main

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

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

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

	var c int
	var n int
	Fscan(in, &c)
	for ; c > 0; c-- {
		Fscan(in, &n)
		a := make([]int, n)
		max_cnt := 0
		cnt := make(map[int]int)
		for i := range a {
			Fscan(in, &a[i])
			cnt[a[i]]++
			if cnt[a[i]] > max_cnt {
				max_cnt = cnt[a[i]]
			}
		}
		ans := 0
		remain := n - max_cnt
		for remain > 0 {
			//copy
			ans++
			//swap
			k := min(remain, max_cnt)
			ans += k
			remain -= k
			max_cnt *= 2
		}
		Fprintf(out, "%d\n", ans)
	}
}

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

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

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

		m := make(map[int]int)
		a := make([]int, n+1)

		mx := 0
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
			m[a[i]] += 1
		}

		for _, v := range m {
			if v > mx {
				mx = v
			}
		}

		i := mx
		j := n - i

		ans := 0
		for j > 0 {
			ans += min(i, j)
			j -= i
			i += i
			ans += 1
		}

		Fprintln(out, ans)

	}

}

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

package main

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

func solve(in io.Reader, out io.Writer) {
	var n int
	Fscan(in, &n)
	cnt := make(map[int]int)
	mx := 0
	for i := 0; i < n; i++ {
		var x int
		Fscan(in, &x)
		cnt[x]++
		mx = max(mx, cnt[x])
	}
	if n == 1 { Fprintln(out, 0); return }

	step, ans := 0, mx
	for ans < n {
		if ans * 2 <= n {
			step = step + 1 + ans
			ans *= 2
		} else {
			step = step + 1 + (n - ans)
			break
		}
	}
	Fprintln(out, step)
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for; t > 0; t-- {
		solve(in, out)
	}
}

func min(a, b int) int { if a > b { return b }; return a }
func max(a, b int) int { if a < b { return b }; return a }
func abs(v int) int { if v > 0 { return v }; return -v }
func gcd(a, b int) int { if b > 0 { return gcd(b, a % b) }; return a }
func lcm(a, b int) int { return a * b / gcd(a, b) }

package main

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

const MOD int64 = 1000000007

var n int

var a []int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(read, &a[i])
		}

		a := solve()
		fmt.Println(a)
	}
}

type pair struct {
	v int
	idx []int
}

func solve()  int {
	mp := make(map[int]int)

	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var maxKey int
	var maxV int

	for k, v := range mp{
		if v > maxV {
			maxV = v
			maxKey = k
		}
	}

	maxV = mp[maxKey]

	if maxV == n {
		return 0
	}

	other := n - maxV

	var cnt int
	for ;; {
		cnt++

		if maxV >= other {
			cnt += other
			break
		}

		cnt += maxV
		maxV += maxV
		other = n - maxV
	}

	return cnt
}

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

package main

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

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

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 int64
		fmt.Fscan(in, &n)

		m := make(map[int64]int64)
		var max int64
		for i := int64(0); i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			m[v]++
			if m[v] > max {
				max = m[v]
			}
		}

		var c int64
		for max < n {
			c += min(max, n-max) + 1
			max *= 2
		}
		fmt.Fprintln(out, c)
	}
}


Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ positions should contain exactly one flower: a rose or a lily.She knows that exactly $$$m$$$ people will visit this exhibition. The $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $$$r_i$$$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $$$r_i$$$ inclusive.

Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.

NoteIn the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;  in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$;  in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$;  in the segment $$$[2\ldots5]$$$, there are two roses and two lilies, so the beauty is equal to $$$2\cdot 2=4$$$. The total beauty is equal to $$$2+2+4=8$$$.In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;  in the segment $$$[5\ldots6]$$$, there are one rose and one lily, so the beauty is equal to $$$1\cdot 1=1$$$;  in the segment $$$[1\ldots4]$$$, there are two roses and two lilies, so the beauty is equal to $$$2\cdot 2=4$$$;  in the segment $$$[4\ldots6]$$$, there are two roses and one lily, so the beauty is equal to $$$2\cdot 1=2$$$. The total beauty is equal to $$$1+4+2=7$$$.

package main

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

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

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

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

    n := ReadInt()

    for ; n > 0; n-- {
	    if n%2 == 0 {
	    	writer.WriteString("1")
	    }else {
	    	writer.WriteString("0")
	    }
    }
	writer.WriteString("\n")

}

package main

import (
	"fmt"
)

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

package main

import "fmt"

func main() {
    var n,m int
    fmt.Scan(&n,&m)
    for i:=0;i<m;i++{
        var x,y int
        fmt.Scan(&x,&y)

    }
    for i:=0;i<n;i++{
        if i%2== 0 {
            fmt.Print(0)
        } else {
            fmt.Print(1)
        }
    }
    fmt.Println()

}


In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u > v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u > v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to:  $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$,  $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$,  $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$,  $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$,  $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$,  $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.

The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).

Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.

NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.

package main

import (
	"fmt"
	"math"
)

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

	for i := 1; i < n+1; i++ {
		c := i
		fmt.Print(c, " ")
		for j := 0; j < n-1; j++ {
			if j%2 == 0 {
				c = c + 2*(n-i) + 1
			} else {
				c = c + 2*i - 1
			}
			fmt.Print(c, " ")
		}
		fmt.Println()
	}
}

func exp(x int) int {
	return int(math.Exp2(float64(x)))
}
func comb(x, y int) int {
	m := 1
	n := 1
	for i := 0; i < y; i++ {
		m = m * (x - i)
		n = n * (i + 1)
	}
	return m / n
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

package main

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

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

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var answers [][]int

func main() {
	n = ReadInt()

	r := n / 2
	answers = make([][]int, n)
	for i := 0; i < n; i++ {
		answers[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			answers[i][j] = i*n + (j + 1)
		}
	}
	// fmt.Println(answers)
	for i := 0; i < r; i++ {
		answers[i] = Reverse(answers[i])
	}
	// fmt.Println(answers)

	for j := 0; j < n; j++ {
		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Printf("%d\n", answers[i][j])
			} else {
				fmt.Printf("%d ", answers[i][j])
			}
		}
	}
}

func Reverse(A []int) []int {
	res := []int{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

func main() {
	defer Flush()

	n := readi()
	ans := make([][]int, n)
	for i := range ans {
		ans[i] = make([]int, 0, n)
	}
	i := 0
	d := 1
	for v := 1; v <= n*n; v++ {
		if i == n {
			i = n - 1
			d = -1
		} else if i == -1 {
			i = 0
			d = 1
		}
		ans[i] = append(ans[i], v)
		i += d
	}

	for i := range ans {
		sp := ""
		for _, v := range ans[i] {
			printf("%s%d", sp, v)
			sp = " "
		}
		println()
	}
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

var DIV int64 = 1000000007

func culc(a, n int64) int64 {
	if n == 0 {
		return 1
	}

	if n == 1 {
		return a
	}

	if n%2 == 1 {
		return culc(a, n-1) * a % DIV
	}

	sum := culc(a, n/2)
	return sum * sum % DIV
}

func main() {

	reader := bufio.NewReader(os.Stdin)

	var n, m int

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

	for i := 1; i <= n; i++ {
		for j := 0; j < n; j++ {
			if j%2 == 0 {
				m = j*n + i
			} else {
				m = n*(j+1) + 1 - i
			}
			fmt.Printf("%d ", m)
		}
		fmt.Printf("\n")
	}
}


You have a connected undirected graph made of $$$n$$$ nodes and $$$m$$$ edges. The $$$i$$$-th node has a value $$$v_i$$$ and a target value $$$t_i$$$.In an operation, you can choose an edge $$$(i, j)$$$ and add $$$k$$$ to both $$$v_i$$$ and $$$v_j$$$, where $$$k$$$ can be any integer. In particular, $$$k$$$ can be negative.Your task to determine if it is possible that by doing some finite number of operations (possibly zero), you can achieve for every node $$$i$$$, $$$v_i = t_i$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$), the number of test cases. Then the test cases follow. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$, $$$n-1\leq m\leq \min(2\cdot 10^5, \frac{n(n-1)}{2})$$$) — the number of nodes and edges respectively. The second line contains $$$n$$$ integers $$$v_1\ldots, v_n$$$ ($$$-10^9 \leq v_i \leq 10^9$$$) — initial values of nodes. The third line contains $$$n$$$ integers $$$t_1\ldots, t_n$$$ ($$$-10^9 \leq t_i \leq 10^9$$$) — target values of nodes. Each of the next $$$m$$$ lines contains two integers $$$i$$$ and $$$j$$$ representing an edge between node $$$i$$$ and node $$$j$$$ ($$$1 \leq i, j \leq n$$$, $$$i\ne j$$$). It is guaranteed that the graph is connected and there is at most one edge between the same pair of nodes. It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$2 \cdot 10^5$$$ and the sum of $$$m$$$ over all testcases does not exceed $$$2 \cdot 10^5$$$.

For each test case, if it is possible for every node to reach its target after some number of operations, print "YES". Otherwise, print "NO".

NoteHere is a visualization of the first test case (the orange values denote the initial values and the blue ones the desired values):   One possible order of operations to obtain the desired values for each node is the following:  Operation $$$1$$$: Add $$$2$$$ to nodes $$$2$$$ and $$$3$$$.  Operation $$$2$$$: Add $$$-2$$$ to nodes $$$1$$$ and $$$4$$$.  Operation $$$3$$$: Add $$$6$$$ to nodes $$$3$$$ and $$$4$$$. Now we can see that in total we added $$$-2$$$ to node $$$1$$$, $$$2$$$ to node $$$2$$$, $$$8$$$ to node $$$3$$$ and $$$4$$$ to node $$$4$$$ which brings each node exactly to it's desired value.For the graph from the second test case it's impossible to get the target values.

package main
import("bufio";."fmt";"os";"runtime/debug")

// github.com/EndlessCheng/codeforces-go
func init() { debug.SetGCPercent(-1) }
func main(){
	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i,_n,buf:=0,0,make([]byte, 1<<12)
	rc:=func()byte{
		if _i==_n {
			_n,_=os.Stdin.Read(buf)
			if _n==0{return 0}
			_i=0
		}
		b:=buf[_i];_i++;return b
	}
	r:=func()(x int){
		b:=rc()
		neg:=false
		for;'0'>b;b=rc(){if b=='-'{neg=true}}
		for;'0'<=b;b=rc(){x=x*10+int(b&15)}
		if neg{return -x};return
	}
	for T:=r();T>0;T--{
		n,m :=r(),r()
		a:=make([]int,n)
		for i:=range a{a[i]=r()}
		x:=0
		for i:=range a{a[i]-=r();x^=a[i]}
		g:=make([][]int,n)
		for;m>0;m--{
			v,w:=r()-1,r()-1
			g[v]=append(g[v],w)
			g[w]=append(g[w],v)
		}
		s:=int64(0)
		C:=make([]int8,n)
		var f func(int,int8)bool
		f=func(v int,c int8)bool{
			if c>0{s+=int64(a[v])}else if c<0{s-=int64(a[v])}
			C[v]=c
			for _,w:=range g[v]{if C[w]==c||C[w]==0&&f(w,-c){return true}}
			return false
		}
		if x&1==0&&(f(0,1)||s==0){Fprintln(out, "YES")}else{Fprintln(out, "NO")}
	}
}

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

// github.com/EndlessCheng/codeforces-go
func main(){
	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i,_n,buf:=0,0,make([]byte, 1<<12)
	rc:=func()byte{
		if _i==_n {
			_n,_=os.Stdin.Read(buf)
			if _n==0{return 0}
			_i=0
		}
		b:=buf[_i];_i++;return b
	}
	r:=func()(x int){
		b:=rc()
		neg:=false
		for;'0'>b;b=rc(){if b=='-'{neg=true}}
		for;'0'<=b;b=rc(){x=x*10+int(b&15)}
		if neg{return -x};return
	}
	for T:=r();T>0;T--{
		n,m :=r(),r()
		a:=make([]int,n)
		for i:=range a{a[i]=r()}
		x:=0
		for i:=range a{a[i]-=r();x^=a[i]}
		g:=make([][]int,n)
		for;m>0;m--{
			v,w:=r()-1,r()-1
			g[v]=append(g[v],w)
			g[w]=append(g[w],v)
		}
		s:=int64(0)
		C:=make([]int8,n)
		var f func(int,int8)bool
		f=func(v int,c int8)bool{
			if c>0{s+=int64(a[v])}else if c<0{s-=int64(a[v])}
			C[v]=c
			for _,w:=range g[v]{if C[w]==c||C[w]==0&&f(w,-c){return true}}
			return false
		}
		if x&1==0&&(f(0,1)||s==0){Fprintln(out, "YES")}else{Fprintln(out, "NO")}
	}
}

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

// github.com/EndlessCheng/codeforces-go
func main(){
	in:=bufio.NewReader(Stdin)
	var T,n,m,v,w int
	for Fscan(in,&T);T>0;T--{
		Fscan(in,&n,&m)
		a:=make([]int64,n)
		for i:=range a{Fscan(in,&a[i])}
		var x,s int64
		for i:=range a{
			Fscan(in,&v)
			a[i]=int64(v)-a[i]
			x^=a[i]
		}
		g:=make([][]int,n)
		for;m>0;m--{
			Fscan(in,&v,&w);v--;w--
			g[v]=append(g[v],w)
			g[w]=append(g[w],v)
		}
		C:=make([]int,n)
		var f func(int,int)bool
		f=func(v,c int)bool{
			s+=int64(c)*a[v]
			C[v]=c
			for _,w:=range g[v]{if C[w]==c||C[w]==0&&f(w,-c){return true}}
			return false
		}
		if x&1==0&&(f(0,1)||s==0){Println("YES")}else{Println("NO")}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) bool {
		var n, m int
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int64, n)
		s := int64(0)
		for i := range b {
			Fscan(in, &b[i])
			b[i] -= a[i]
			s += b[i]
		}

		g := make([][]int, n)
		for i := 0; i < m; i++ {
			var v, w int
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		if s&1 > 0 {
			return false
		}
		colors := make([]int8, n)
		colors[0] = 1
		var f func(int, int) bool
		f = func(v, p int) bool {
			for _, w := range g[v] {
				if colors[w] == 0 {
					colors[w] = 3 - colors[v]
					if f(w, v) {
						return true
					}
				}
				if colors[w] == colors[v] {
					return true
				}
			}
			if p >= 0 {
				b[p] -= b[v]
				b[v] = 0
			}
			return false
		}
		return f(0, -1) || b[0] == 0
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}

}

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

package main
import (
    "fmt"
    "bufio"
    "io"
    "os"
)
const N int = 2e5+10
var casee int
var n, m, tot int
var x, y int
var v1, v2 int64
var flag bool
var visit [N]int
var v, t [N]int
var head [N]int
var nxt, to [N<<1]int
func dfs (now, state int) {
    visit[now] = state + 2
    if (state & 1) > 0 {
        v1 += int64(t[now] - v[now])
    } else {
        v2 += int64(t[now] - v[now])
    }
    for i := head[now]; i > 0; i = nxt[i] {
        var index int = to[i]
        if visit[index] > 0 {
            if visit[index] == visit[now] {
                flag = true
            }
            continue
        }
        dfs(index, state^1)
    }
}
func main() {
    var input io.Reader = bufio.NewReader(os.Stdin)
    for fmt.Fscan(input, &casee); casee > 0; casee-- {
        v1 = 0
        v2 = 0
        tot = 0
        flag = false
        head = [N]int{}
        visit = [N]int{}

        fmt.Fscan(input, &n)
        fmt.Fscan(input, &m)
        for i := 1; i <= n; i++ {
            fmt.Fscan(input, &v[i])
        }
        for i:= 1; i <= n; i++ {
            fmt.Fscan(input, &t[i])
        }
        for ; m > 0; m-- {
            fmt.Fscan(input, &x)
            fmt.Fscan(input, &y)
            tot++; to[tot] = y; nxt[tot] = head[x]; head[x] = tot
            tot++; to[tot] = x; nxt[tot] = head[y]; head[y] = tot
        }

        dfs(1, 0)

        if ((flag && (v1+v2+1) % 2 != 0) || (!flag && v1 == v2)) {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

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

// github.com/EndlessCheng/codeforces-go
func main(){
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = os.Stdin.Read(buf)
			if _n == 0 {
				return 0
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T:=r();T>0;T--{
		n,m :=r(),r()
		a:=make([]int,n)
		for i:=range a{a[i]=r()}
		x:=0
		for i:=range a{
			a[i]-=r()
			x^=a[i]
		}
		g:=make([][]int,n)
		for;m>0;m--{
			v,w:=r()-1,r()-1
			g[v]=append(g[v],w)
			g[w]=append(g[w],v)
		}
		s:=int64(0)
		C:=make([]int8,n)
		var f func(int,int8)bool
		f=func(v int,c int8)bool{
			if c>0{s+=int64(a[v])}else{s-=int64(a[v])}
			C[v]=c
			for _,w:=range g[v]{if C[w]==c||C[w]==0&&f(w,-c){return true}}
			return false
		}
		if x&1==0&&(f(0,1)||s==0){Fprintln(out, "YES")}else{Fprintln(out, "NO")}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) bool {
		var n, m int
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int64, n)
		for i := range b {
			Fscan(in, &b[i])
			b[i] -= a[i]
		}

		g := make([][]int, n)
		d := make([]int, n)
		for i := 0; i < m; i++ {
			var v, w int
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
			d[v]++
			d[w]++
		}
		if m == 1 {
			return b[0]==b[1]
		}
		if m > n {
			return true
		}
		q := []int{}
		c:=0
		for i, d := range d {
			if d == 1 {
				q = append(q, i)
				c++
			}
		}
		last := 0
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			for _, w := range g[v] {
				b[w] -= b[v]
				if d[w]--; d[w] == 1 {
					last = w
					q = append(q, w)
					c++
				}
			}
		}
		if c==n {
			return b[last] == 0
		}
		s := int64(0)
		for i, d := range d {
			if d > 1 {
				if  d> 2 {
					return true
				}
				if i&1==0 {
					s+=b[i]
				} else {
					s-=b[i]
				}
			}
		}
		return s==0
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}

}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) bool {
		var n, m int
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int64, n)
		for i := range b {
			Fscan(in, &b[i])
			b[i] -= a[i]
		}

		g := make([][]int, n)
		d := make([]int, n)
		for i := 0; i < m; i++ {
			var v, w int
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
			d[v]++
			d[w]++
		}
		if m == 1 {
			return b[0]==b[1]
		}
		q := []int{}
		c:=0
		for i, d := range d {
			if d == 1 {
				q = append(q, i)
				c++
			}
		}
		last := 0
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			for _, w := range g[v] {
				b[w] -= b[v]
				if d[w]--; d[w] == 1 {
					last = w
					q = append(q, w)
					c++
				}
			}
		}
		if c==n {
			return b[last] == 0
		}
		s := int64(0)
		for i, d := range d {
			if d > 1 {
				if  d> 2 {
					return true
				}
				if i&1==0 {
					s+=b[i]
				} else {
					s-=b[i]
				}
			}
		}
		return s==0
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}

}

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

package main
import (
    "fmt"
    "bufio"
    "io"
    "os"
)
const N int = 2e5+10
var casee int
var n, m, tot int
var x, y int
var v1, v2 int64
var flag bool
var visit [N]int
var v, t [N]int
var head [N]int
var nxt, to [N<<1]int
func dfs (now, state int) {
    visit[now] = state + 2
    if (state & 1) > 0 {
        v1 += int64(t[now] - v[now])
    } else {
        v2 += int64(t[now] - v[now])
    }
    for i := head[now]; i > 0; i = nxt[i] {
        var index int = to[i]
        if visit[index] > 0 {
            if visit[index] == visit[now] {
                flag = true
            }
            continue
        }
        dfs(index, state^1)
    }
}
func main() {
    var input io.Reader = bufio.NewReader(os.Stdin)
    for fmt.Fscan(input, &casee); casee > 0; casee-- {
        v1 = 0
        v2 = 0
        tot = 0
        flag = false
        head = [N]int{}
        visit = [N]int{}

        fmt.Fscan(input, &n)
        fmt.Fscan(input, &m)
        for i := 1; i <= n; i++ {
            fmt.Fscan(input, &v[i])
        }
        for i:= 1; i <= n; i++ {
            fmt.Fscan(input, &t[i])
        }
        for ; m > 0; m-- {
            fmt.Fscan(input, &x)
            fmt.Fscan(input, &y)
            tot++; to[tot] = y; nxt[tot] = head[x]; head[x] = tot
            tot++; to[tot] = x; nxt[tot] = head[y]; head[y] = tot
        }

        dfs(1, 0)
        if ((flag && (v1+v2+1 & 1) != 0) || (!flag && v1 == v2)) {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main
import (
    "fmt"
    "bufio"
    "io"
    "os"
)
const N int = 2e5+10
var casee int
var n, m, tot int
var x, y int
var v1, v2 int64
var flag bool
var visit [N]int
var v, t [N]int
var head [N]int
var nxt, to [N<<1]int
func dfs (now, state int) {
    visit[now] = state + 2
    if (state & 1) > 0 {
        v1 += int64(t[now] - v[now])
    } else {
        v2 += int64(t[now] - v[now])
    }
    for i := head[now]; i > 0; i = nxt[i] {
        var index int = to[i]
        if visit[index] > 0 {
            if visit[index] == visit[now] {
                flag = true
            }
            continue
        }
        dfs(index, state^1)
    }
}
func main() {
    var input io.Reader = bufio.NewReader(os.Stdin)
    for fmt.Fscan(input, &casee); casee > 0; casee-- {
        v1 = 0
        v2 = 0
        tot = 0
        flag = false
        head = [N]int{}
        visit = [N]int{}

        fmt.Fscan(input, &n)
        fmt.Fscan(input, &m)
        for i := 1; i <= n; i++ {
            fmt.Fscan(input, &v[i])
        }
        for i:= 1; i <= n; i++ {
            fmt.Fscan(input, &t[i])
        }
        for ; m > 0; m-- {
            fmt.Fscan(input, &x)
            fmt.Fscan(input, &y)
            tot++; to[tot] = y; nxt[tot] = head[x]; head[x] = tot
            tot++; to[tot] = x; nxt[tot] = head[y]; head[y] = tot
        }

        dfs(1, 0)

        if ((flag && (v1+v2+1 & 1) > 0) || (!flag && v1 == v2)) {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}


Today at the lesson of mathematics, Petya learns about the digital root.The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached. Let's denote the digital root of $$$x$$$ as $$$S(x)$$$. Then $$$S(5)=5$$$, $$$S(38)=S(3+8=11)=S(1+1=2)=2$$$, $$$S(10)=S(1+0=1)=1$$$.As a homework Petya got $$$n$$$ tasks of the form: find $$$k$$$-th positive number whose digital root is $$$x$$$.Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all $$$n$$$ tasks from Petya's homework.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$) — the number of tasks in Petya's homework. The next $$$n$$$ lines contain two integers $$$k_i$$$ ($$$1 \le k_i \le 10^{12}$$$) and $$$x_i$$$ ($$$1 \le x_i \le 9$$$) — $$$i$$$-th Petya's task in which you need to find a $$$k_i$$$-th positive number, the digital root of which is $$$x_i$$$.

Output $$$n$$$ lines, $$$i$$$-th line should contain a single integer — the answer to the $$$i$$$-th problem.

package main

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

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for t > 0 {
		t--
		var k, x int64
		fmt.Scanf("%d %d ", &k, &x)
		fmt.Println(9*(k-1) + x)

	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var n int64
	scanf("%d\n", &n)

	for n>0 {
		n--
		var k,x int64

		scanf("%d %d\n", &k, &x)

		ans := int64(9) * (k - int64(1)) + x

		printf("%d\n", ans)
	}
}

package main

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

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

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

func droot(x int) int {
	if x < 10 {
		return x
	}
	sum := 0
	for x > 0 {
		sum += x % 10
		x /= 10
	}
	return droot(sum)
}

func main() {
	defer writer.Flush()
	// for i := 1; i < 50; i++ {
	// 	fmt.Println(i, droot(i))
	// }
	var q, k, x int64
	scanf("%d\n", &q)
	for i := int64(0); i < q; i++ {
		scanf("%d %d\n", &k, &x)
		printf("%d\n", (k-1)*9+x)
	}
}

package main

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

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

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

func dr(n int) int {
	return 1 + (n - 1) % 9
}

func sol(k int64, x int64) int64 {
	return x + (k - 1) * 9
}

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

	var n int
	var x, k int64
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &k, &x)
		printf("%d\n", sol(k, x))
		// for f := 1; f <= 10; f++ {
		// 	printf("%d: %d\t", i*10 + f, dr(i*10 + f))
		// }
		// printf("\n")
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64
		var x int
		var s string

		fmt.Scanf("%s %d ", &s, &x)
		k, _ := strconv.ParseInt(s, 10, 64)
		k -= 1
		fmt.Println(k*9 + int64(x))
	}

}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		//var k int64
		var x int
		var s string

		fmt.Scanf("%s %d", &s, &x)
		k, _ := strconv.ParseInt(s, 10, 64)
		k -= 1
		fmt.Println(k*9 + int64(x))
	}

}

package main

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

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for t > 0 {
		t--
		var k, x int
		fmt.Scanf("%d %d ", &k, &x)
		fmt.Println(9*(k-1) + x)

	}
}

package main

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

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

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

func dr(n int) int {
	return 1 + (n - 1) % 9
}

func sol(k int, x int64) int64 {
	return x + (int64(k) - 1) * 9
}

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

	var n, k int
	var x int64
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &k, &x)
		printf("%d\n", sol(k, x))
		// for f := 1; f <= 10; f++ {
		// 	printf("%d: %d\t", i*10 + f, dr(i*10 + f))
		// }
	}
}