Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.Arpa can perform two types of operations:  Choose a number and delete it with cost x.  Choose a number and increase it by 1 with cost y. Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.Help Arpa to find the minimum possible cost to make the list good.

First line contains three integers n, x and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y. Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.

Print a single integer: the minimum possible cost to make the list good.

NoteIn example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.

// Codeforces 850 B  Arpa and a list of numbers, train, read help
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n int
var x, y int64
var a []int
var ans int64
var primes []int
var nma []int  // suma[i] = number of a == i
var suma []int // suma[i] = number of a <= i
var nsuma []int64 // suma[i] = sum of a <= i
var maxA int

// readData read data for out problem.
func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	var ix, iy int
	n, ix, iy, _, _ = readFive()
	x = int64(ix)
	y = int64(iy)
	a = readLineNumbs(n)
}

// prepare primes
func prepPrimes(maxPrime int) {
	// demtab, 0 - primes
	demtab := make([]byte, maxPrime)
	for i := 2; i*i < maxPrime+100; i++ {
		if demtab[i] == 0 {
			for j := i + i; j < maxPrime; j += i {
				demtab[j] = 1
			}
		}
	}
	// save and count primes
	for i := 2; i < maxPrime; i++ {
		if demtab[i] == 0 {
			primes = append(primes, i)
		}
	}
}

func countSum() {
	// count maxA
	maxA = 0
	for _, aa := range a {
		if aa > maxA {
			maxA = aa
		}
	}
	maxA++
	nma = make([]int, maxA)
	suma = make([]int, maxA)
	nsuma = make([]int64, maxA)
	for _, aa := range a {
		nma[aa]++
	}
	sm := 0
	nsm := int64(0)
	for i := 0; i < maxA; i++ {
		sm += nma[i]
		nsm += int64(i)*int64(nma[i])
		suma[i] = sm
		nsuma[i] = nsm
	}
}

// cnt from l to r including
func cnt(l,r int) int64 {
	if r>=maxA {
		r = maxA-1
	}
	if l>r {
		return 0
	}
	if l<1 {
		fmt.Printf("Bad l,r in cnt: %d %d\n", l,r)
		return 0
	}
	// fmt.Printf("cnt(%d, %d)\n", l,r)
	cnta := int64(suma[r] - suma[l-1])
	//fmt.Printf("cnt(%d, %d) returned %d\n", l,r,cnta)
	return cnta
}

func sum(l,r int) int64 {
	if r>=maxA {
		r = maxA-1
	}
	if l>r {
		return 0
	}
	if l<1 {
		fmt.Printf("Bad l,r in sum: %d %d\n", l,r)
		return 0
	}
	//fmt.Printf("sum(%d, %d)\n", l,r)
	nsa := nsuma[r] - nsuma[l-1]
	//fmt.Printf("sum(%d, %d) returned %d\n", l,r,nsa)
	return nsa
}

// count efforts for given prime g
func efforts(g int, maxEfforts int64) int64 {
	var eff int64
	xy := int(x/y)
	for int64(xy)*y <= x {
		xy++
	}
	x0 := 1
	x1 := g - xy
	y0 := x1+1
	y1 := g-1
	if xy > g-1 {
		x1 = 0
		y0 = 1
	}
	//fmt.Printf("efforts, g,x0,x1,y0,y1 = %d %d %d %d %d\n",g,x0,x1,y0,y1)
	for i := 0; i < maxA+g; i+=g {
		// counting efforts for (i-1)*g<a<=i*g
		eff += x*int64(cnt(i+x0, i+x1))
		eff += y*(int64(i+g)*int64(cnt(i+y0, i+y1)) - sum(i+y0, i+y1))
		if eff > maxEfforts {
			break
		}
	}
	//fmt.Printf("efforts(g = %d,..) returned %d\n", g, eff)
	return eff
}

// solve func solves our problem.
func solve() {
	prepPrimes(1000222)
	countSum()
	maxEfforts := int64(1e15)
	for _, pr := range primes {
		if pr > maxA+2 {
			break
		}
		eff := efforts(pr, maxEfforts)
		if eff < maxEfforts {
			maxEfforts = eff
		}
	}
	ans = maxEfforts
}

// printRes print problem solution in expected format.
func printRes() {
	fmt.Println(ans)
}

func main() {
	readData()
	solve()
	printRes()
}

// Codeforces 850 B  Arpa and a list of numbers, train, read help
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n int
var x, y int64
var a []int
var ans int64
var primes []int
var nma []int  // suma[i] = number of a == i
var suma []int // suma[i] = number of a <= i
var nsuma []int64 // suma[i] = sum of a <= i
var maxA int

// readData read data for out problem.
func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	var ix, iy int
	n, ix, iy, _, _ = readFive()
	x = int64(ix)
	y = int64(iy)
	a = readLineNumbs(n)
}

// prepare primes
func prepPrimes(maxPrime int) {
	// demtab, 0 - primes
	demtab := make([]byte, maxPrime)
	for i := 2; i*i < maxPrime+100; i++ {
		if demtab[i] == 0 {
			for j := i + i; j < maxPrime; j += i {
				demtab[j] = 1
			}
		}
	}
	// save and count primes
	for i := 2; i < maxPrime; i++ {
		if demtab[i] == 0 {
			primes = append(primes, i)
		}
	}
}

func countSum() {
	// count maxA
	maxA = 0
	for _, aa := range a {
		if aa > maxA {
			maxA = aa
		}
	}
	maxA++
	nma = make([]int, maxA)
	suma = make([]int, maxA)
	nsuma = make([]int64, maxA)
	for _, aa := range a {
		nma[aa]++
	}
	sm := 0
	nsm := int64(0)
	for i := 0; i < maxA; i++ {
		sm += nma[i]
		nsm += int64(i)*int64(nma[i])
		suma[i] = sm
		nsuma[i] = nsm
	}
}

// cnt from l to r including
func cnt(l,r int) int {
	if r>=maxA {
		r = maxA-1
	}
	if l>r {
		return 0
	}
	if l<1 {
		fmt.Printf("Bad l,r in cnt: %d %d\n", l,r)
		return 0
	}
	// fmt.Printf("cnt(%d, %d)\n", l,r)
	cnta := suma[r] - suma[l-1]
	//fmt.Printf("cnt(%d, %d) returned %d\n", l,r,cnta)
	return cnta
}

func sum(l,r int) int64 {
	if r>=maxA {
		r = maxA-1
	}
	if l>r {
		return 0
	}
	if l<1 {
		fmt.Printf("Bad l,r in sum: %d %d\n", l,r)
		return 0
	}
	//fmt.Printf("sum(%d, %d)\n", l,r)
	nsa := nsuma[r] - nsuma[l-1]
	//fmt.Printf("sum(%d, %d) returned %d\n", l,r,nsa)
	return nsa
}

// count efforts for given prime g
func efforts(g int, maxEfforts int64) int64 {
	var eff int64
	xy := int(x/y)
	for int64(xy)*y <= x {
		xy++
	}
	x0 := 1
	x1 := g - xy
	y0 := x1+1
	y1 := g-1
	if xy > g-1 {
		x1 = 0
		y0 = 1
	}
	//fmt.Printf("efforts, g,x0,x1,y0,y1 = %d %d %d %d %d\n",g,x0,x1,y0,y1)
	for i := 0; i < maxA+g; i+=g {
		// counting efforts for (i-1)*g<a<=i*g
		eff += x*int64(cnt(i+x0, i+x1))
		eff += y*(int64((i+g)*cnt(i+y0, i+y1)) - sum(i+y0, i+y1))
		if eff > maxEfforts {
			break
		}
	}
	//fmt.Printf("efforts(g = %d,..) returned %d\n", g, eff)
	return eff
}

// solve func solves our problem.
func solve() {
	prepPrimes(1000222)
	countSum()
	maxEfforts := int64(1e15)
	for _, pr := range primes {
		if pr > maxA+2 {
			break
		}
		eff := efforts(pr, maxEfforts)
		if eff < maxEfforts {
			maxEfforts = eff
		}
	}
	ans = maxEfforts
}

// printRes print problem solution in expected format.
func printRes() {
	fmt.Println(ans)
}

func main() {
	readData()
	solve()
	printRes()
}

// Codeforces 850 B  Arpa and a list of numbers, train
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n int
var x,y int64
var a []int
var ans int64
var primes []int

// readData read data for out problem.
func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	var ix,iy int
	n, ix, iy, _, _ = readFive()
	x = int64(ix)
	y = int64(iy)
	a = readLineNumbs(n)
}

// prepare primes
func prepPrimes(maxPrime int) {
	// demtab, 0 - primes
	demtab := make([]byte, maxPrime)
	for i:=2; i*i<maxPrime+100; i++ {
		if demtab[i]==0 {
			for j:=i+i; j<maxPrime; j+=i {
				demtab[j] = 1
			}
		}
	}
	// save and count primes
	for i:=2; i<maxPrime; i++ {
		if demtab[i]==0 {
			primes = append(primes, i)
		}
	}
	fmt.Println("number primes ", len(primes))
}

// count efforts for given prime
func efforts(prime int, maxEfforts int64) int64 {
	var eff int64
	var eInc int64
	for i:=0; i<n; i++ {
		eInc = y*int64(a[i] % prime)
		if eInc<x {
			eff += eInc
		} else {
			eff += x
		}
		if eff>maxEfforts {
			break
		}
	}
	return eff
}

// solve func solves our problem.
func solve() {
	prepPrimes(1000222)
	maxEfforts := int64(1e15)
	for _,pr := range primes {
		eff := efforts(pr, maxEfforts)
		if eff < maxEfforts {
			maxEfforts = eff
		}
	}
	ans = maxEfforts
}

// printRes print problem solution in expected format.
func printRes() {
	fmt.Println(ans)
}

func main() {
	readData()
	solve()
	printRes()
}


As a human, she can erase history of its entirety. As a Bai Ze (Hakutaku), she can create history out of nothingness.—Perfect Memento in Strict SenseKeine has the ability to manipulate history. The history of Gensokyo is a string $$$s$$$ of length $$$1$$$ initially. To fix the chaos caused by Yukari, she needs to do the following operations $$$n$$$ times, for the $$$i$$$-th time:  She chooses a non-empty substring $$$t_{2i-1}$$$ of $$$s$$$. She replaces $$$t_{2i-1}$$$ with a non-empty string, $$$t_{2i}$$$. Note that the lengths of strings $$$t_{2i-1}$$$ and $$$t_{2i}$$$ can be different.Note that if $$$t_{2i-1}$$$ occurs more than once in $$$s$$$, exactly one of them will be replaced.For example, let $$$s=$$$"marisa", $$$t_{2i-1}=$$$"a", and $$$t_{2i}=$$$"z". After the operation, $$$s$$$ becomes "mzrisa" or "marisz".After $$$n$$$ operations, Keine got the final string and an operation sequence $$$t$$$ of length $$$2n$$$. Just as Keine thinks she has finished, Yukari appears again and shuffles the order of $$$t$$$. Worse still, Keine forgets the initial history. Help Keine find the initial history of Gensokyo!Recall that a substring is a sequence of consecutive characters of the string. For example, for string "abc" its substrings are: "ab", "c", "bc" and some others. But the following strings are not its substring: "ac", "cba", "acb".HacksYou cannot make hacks in this problem.

Each test contains multiple test cases. The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^3$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n < 10 ^ 5$$$) — the number of operations. The next $$$2n$$$ lines contains one non-empty string $$$t_{i}$$$ — the $$$i$$$-th string of the shuffled sequence $$$t$$$. The next line contains one non-empty string $$$s$$$ — the final string. It is guaranteed that the total length of given strings (including $$$t_i$$$ and $$$s$$$) over all test cases does not exceed $$$2 \cdot 10 ^ 5$$$. All given strings consist of lowercase English letters only. It is guaranteed that the initial string exists. It can be shown that the initial string is unique.

For each test case, print the initial string in one line.

2

2

a

ab

b

cd

acd

3

z

a

a

aa

yakumo

ran

yakumoran

NoteTest case 1:Initially $$$s$$$ is "a". In the first operation, Keine chooses "a", and replaces it with "ab". $$$s$$$ becomes "ab". In the second operation, Keine chooses "b", and replaces it with "cd". $$$s$$$ becomes "acd".So the final string is "acd", and $$$t=[$$$"a", "ab", "b", "cd"$$$]$$$ before being shuffled.Test case 2:Initially $$$s$$$ is "z". In the first operation, Keine chooses "z", and replaces it with "aa". $$$s$$$ becomes "aa". In the second operation, Keine chooses "a", and replaces it with "ran". $$$s$$$ becomes "aran". In the third operation, Keine chooses "a", and replaces it with "yakumo". $$$s$$$ becomes "yakumoran".So the final string is "yakumoran", and $$$t=[$$$"z", "aa", "a", "ran", "a", "yakumo"$$$]$$$ before being shuffled.

package main

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

func Solve(reader *bufio.Reader, testCaseIdx int) {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanln(reader, &n)
	f := make(map [rune]int)
	for k := 0; k < 2 * n + 1; k++ {
		var s string
		fmt.Fscanln(reader, &s)
		for _, ch := range s {
			f[ch]++
		}
	}

	for ch, cnt := range f {
		if cnt % 2 == 1 {
			fmt.Fprintf(writer, "%c\n", ch)
			return
		}
	}
}

func main() {
	var testCaseCount int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(reader, t)
	}
}

package main

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

func Solve(reader *bufio.Reader, testCaseIdx int) {
	var n int
	fmt.Fscanln(reader, &n)
	f := make(map [rune]int)
	for k := 0; k < 2 * n + 1; k++ {
		var s string
		fmt.Fscanln(reader, &s)
		for _, ch := range s {
			f[ch]++
		}
	}

	for ch, cnt := range f {
		if cnt % 2 == 1 {
			fmt.Printf("%c\n", ch)
			return
		}
	}
}

func main() {
	var testCaseCount int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(reader, t)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)
		m := make([]int64, 26)
		for i := 0; i < n*2+1; i++ {
			var s string
			fmt.Fscan(in, &s)
			for _, ch := range s {
				m[ch-'a']++
			}
		}

		g := 0
		for i, v := range m {
			if v%2 != 0 {
				g = i
				break
			}
		}
		fmt.Fprintln(out, string(rune(g)+'a'))
	}
}

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," ") }
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 := gi(); sb := ia(26)
		for i:=0;i<=2*N;i++ { s := gs(); for _,c := range s { sb[int(c-'a')]++ } }
		anschar := 'a'; for i:=0;i<26;i++ { if sb[i] % 2 == 1 { anschar = 'a' + rune(i) } }
		ans := string([]rune{anschar})
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

func A4() {
	_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()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var ans byte
		for i := 0; i < n; i++ {
			var s, t string
			Fscan(in, &s, &t)
			for j := 0; j < len(s); j++ {
				ans ^= s[j]
			}
			for j := 0; j < len(t); j++ {
				ans ^= t[j]
			}
		}
		var fin string
		Fscan(in, &fin)
		for j := 0; j < len(fin); j++ {
			ans ^= fin[j]
		}
		Fprintln(out, string(ans))
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	t := make([]string, 2 * n)
	for i := range t {
		fmt.Fscan(r, &t[i])
	}
	var s string
	fmt.Fscan(r, &s)
	m := map[byte]int{}
	for i := range t {
		for tt := range t[i] {
			m[t[i][tt]]++
		}
	}
	for ss := range s {
		m[s[ss]]++
	}
	for k, v := range m {
		if v % 2 == 1 {
			fmt.Fprintln(w, string(k))
			return
		}
	}
}

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

package main

import (
	"fmt"
)

func Solve(testCaseIdx int) {
	var n int
	fmt.Scanf("%d", &n)
	f := make(map [rune]int)
	for k := 0; k < 2 * n + 1; k++ {
		var s string
		fmt.Scanf("%s", &s)
		for _, ch := range s {
			f[ch]++
		}
	}

	for ch, cnt := range f {
		if cnt % 2 == 1 {
			fmt.Printf("%c\n", ch)
			return
		}
	}
}

func main() {
	var testCaseCount int
	fmt.Scanf("%d", &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t)
	}
}

package main

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

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

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

		arr := make([]string, n*2)
		chs := make([]int, 26)
		for i := 0; i < n*2; i++ {
			fmt.Fscan(in, &arr[i])
			if len(arr[i]) == 1 {
				chs[arr[i][0]-'a']++
			}
		}
		sort.Slice(arr, func(i, j int) bool {
			if len(arr[i]) == len(arr[j]) {
				return arr[i] < arr[j]
			}
			return len(arr[i]) < len(arr[j])
		})
		var z string
		fmt.Fscan(in, &z)

		g := "0"
		for i := range chs {
			if chs[i] == 0 {
				continue
			}
			ch := rune(i + 'a')

			var c0, c1 int
			if strings.HasPrefix(z, string(ch)) {
				c0++
			}

			if strings.HasSuffix(z, string(ch)) {
				c1++
			}

			for _, s2 := range arr {
				if strings.HasPrefix(s2, string(ch)) {
					c0++
				}
				if strings.HasSuffix(s2, string(ch)) {
					c1++
				}
			}

			if c0 > n || c1 > n || c0+c1 == 2 {
				g = string(ch)
			}
		}
		fmt.Fprintln(out, g)
	}
}


Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of pairs to check. Further input contains $$$n$$$ descriptions of pairs. The first line of each description contains a single non-empty word $$$s$$$ consisting of lowercase Latin letters. The second line of the description contains a single non-empty word $$$t$$$ consisting of lowercase Latin letters. The lengths of both strings are not greater than $$$10^6$$$. It is guaranteed that the total length of all words $$$s$$$ in the input is not greater than $$$10^6$$$. Also, it is guaranteed that the total length of all words $$$t$$$ in the input is not greater than $$$10^6$$$.

Output $$$n$$$ lines. In the $$$i$$$-th line for the $$$i$$$-th pair of words $$$s$$$ and $$$t$$$ print YES if the word $$$t$$$ could be printed by typing the word $$$s$$$. Otherwise, print NO.

4
hello
hello
hello
helloo
hello
hlllloo
hello
helo

5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

package main

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

var DEBUG = false
var reader *bufio.Reader
var writer *bufio.Writer
var f = os.Stdin

func Scanf(format string, a ...interface{}) {
	fmt.Fscanf(reader, format, a...)
}

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

func calc(s, t string) string {
	idx1, idx2, cnt1, cnt2 := 0, 0, 0, 0
	for idx1 < len(s) && idx2 < len(t) {
		c := s[idx1]
		cnt1, cnt2 = 0, 0
		if s[idx1] != t[idx2] {
			return "NO"
		}
		for idx1+cnt1 < len(s) && s[idx1+cnt1] == c {
			cnt1++
		}
		for idx2+cnt2 < len(t) && t[idx2+cnt2] == c {
			cnt2++
		}
		if cnt2 < cnt1 {
			return "NO"
		}
		idx1 += cnt1
		idx2 += cnt2
	}
	if idx2 < len(t) || idx1 < len(s) {
		return "NO"
	}
	return "YES"
}

func main() {
	if DEBUG {
		f, _ = os.Open("input")
	}
	var n int
	var s, t string
	reader = bufio.NewReader(f)
	writer = bufio.NewWriter(os.Stdout)
	Scanf("%d\n", &n)
	for ; n > 0; n-- {
		Scanf("%s\n%s\n", &s, &t)
		Printf("%s\n", calc(s, t))
	}
	writer.Flush()
}

package main

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

func main() {

	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	var d, cnt, index int
	var st, st1 string

	fmt.Fscanln(scr, &d)

	for d > 0 {
		fmt.Fscanln(scr, &st)
		fmt.Fscanln(scr, &st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) >= 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Fprintln(ocr, "NO")
		} else if string(a) == string(b) {
			fmt.Fprintln(ocr, "YES")
		} else {
			fmt.Fprintln(ocr, "NO")
		}

		ocr.Flush()

		cnt = 0
		index = 0

		d--
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		a := ""
		b := ""
		fmt.Fscanf(in, "%s\n", &a)
		fmt.Fscanf(in, "%s\n", &b)
		o := 0
		p := 0
		ok := true
		for o < len(a) {
			cur := a[o]
			cnt := 1
			for o+1 < len(a) && a[o+1] == a[o] {
				o++
				cnt++
			}
			cntb := 0
			for p < len(b) && b[p] == cur {
				p++
				cntb++
			}
			if cntb < cnt {
				fmt.Fprintf(out, "NO\n")
				ok = false
				break
			}
			o++
		}
		if ok {
			if p != len(b) {
				fmt.Fprintf(out, "NO\n")
			} else {
				fmt.Fprintf(out, "YES\n")
			}
		}
	}
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1185/B

package main

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

type Group struct {
	letter string
	count  int
}

func createGroupList(a string) []Group {
	var answer []Group
	for i := 0; i < len(a); i++ {
		if i == 0 {
			answer = append(answer, Group{letter: string(a[i]), count: 1})
		} else if string(a[i]) != answer[len(answer)-1].letter {
			answer = append(answer, Group{letter: string(a[i]), count: 1})
		} else {
			answer[len(answer)-1].count += 1
		}
	}
	return answer
}

func Solve(a string, b string) string {
	aGroupList := createGroupList(a)
	bGroupList := createGroupList(b)
	if len(aGroupList) != len(bGroupList) {
		return "NO"
	}
	for i := 0; i < len(aGroupList); i++ {
		if (aGroupList[i].count > bGroupList[i].count) || (aGroupList[i].letter != bGroupList[i].letter) {
			return "NO"
		}
	}
	return "YES"
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	var a string
	var b string
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n%s\n", &a, &b)
		fmt.Fprintf(writer, "%s\n", Solve(a, b))
	}
}

package main

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

var DEBUG = true
var reader *bufio.Reader
var writer *bufio.Writer
var f = os.Stdin

func Scanf(format string, a ...interface{}) {
	fmt.Fscanf(reader, format, a...)
}

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

func calc(s, t string) string {
	idx1, idx2, cnt1, cnt2 := 0, 0, 0, 0
	for idx1 < len(s) && idx2 < len(t) {
		c := s[idx1]
		cnt1, cnt2 = 0, 0
		if s[idx1] != t[idx2] {
			return "NO"
		}
		for idx1+cnt1 < len(s) && s[idx1+cnt1] == c {
			cnt1++
		}
		for idx2+cnt2 < len(t) && t[idx2+cnt2] == c {
			cnt2++
		}
		if cnt2 < cnt1 {
			return "NO"
		}
		idx1 += cnt1
		idx2 += cnt2
	}
	if idx2 < len(t) || idx1 < len(s) {
		return "NO"
	}
	return "YES"
}

func main() {
	if DEBUG {
		f, _ = os.Open("input")
	}
	var n int
	var s, t string
	reader = bufio.NewReader(f)
	writer = bufio.NewWriter(os.Stdout)
	Scanf("%d\n", &n)
	for ; n > 0; n-- {
		Scanf("%s\n%s\n", &s, &t)
		Printf("%s\n", calc(s, t))
	}
	writer.Flush()
}

package main

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

var DEBUG = true
var reader *bufio.Reader
var writer *bufio.Writer
var f = os.Stdin

func Scanf(format string, a ...interface{}) {
	fmt.Fscanf(reader, format, a...)
}

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

func calc(s, t string) string {
	idx1, idx2, cnt1, cnt2 := 0, 0, 0, 0
	for idx1 < len(s) {
		c := s[idx1]
		cnt1, cnt2 = 0, 0
		if s[idx1] != t[idx2] {
			return "NO"
		}
		for idx1+cnt1 < len(s) && s[idx1+cnt1] == c {
			cnt1++
		}
		for idx2+cnt2 < len(t) && t[idx2+cnt2] == c {
			cnt2++
		}
		if cnt2 < cnt1 {
			return "NO"
		}
		idx1 += cnt1
		idx2 += cnt2
	}
	if idx2 < len(t) {
		return "NO"
	}
	return "YES"
}

func main() {
	if DEBUG {
		f, _ = os.Open("input")
	}
	var n int
	var s, t string
	reader = bufio.NewReader(f)
	writer = bufio.NewWriter(os.Stdout)
	Scanf("%d\n", &n)
	for ; n > 0; n-- {
		Scanf("%s\n%s\n", &s, &t)
		Printf("%s\n", calc(s, t))
	}
	writer.Flush()
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) >= 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if len(b) > len(a) {
				cnt = 5
				break
			}
			if (index <= len(a)-1) && (a[index] == y) {
				b = append(b, y)
				index++
				continue
			} else if (len(b) > 1) && (y == b[len(b)-1]) {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}

		for _, y := range st1 {
			if len(b) > len(a) {
				cnt = 5
				break
			}
			if (index <= len(a)-1) && (a[index] == y) {
				b = append(b, y)
				index++
				continue
			} else if (len(b) > 1) && (y == b[len(b)-1]) {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else if string(b) == string(a) {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) > 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

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

func main() {

	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	var d, cnt, index int
	var st, st1 string
	fmt.Fscanln(scr, &d)

	for d > 0 {
		fmt.Fscanln(scr, &st)
		fmt.Fscanln(scr, &st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) >= 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Fprintln(ocr, "NO")
		} else if string(a) == string(b) {
			fmt.Fprintln(ocr, "YES")
		} else {
			fmt.Fprintln(ocr, "NO")
		}

		cnt = 0
		index = 0

		d--
	}
}


There are $$$n$$$ workers and $$$m$$$ tasks. The workers are numbered from $$$1$$$ to $$$n$$$. Each task $$$i$$$ has a value $$$a_i$$$ — the index of worker who is proficient in this task.Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $$$1$$$ hour. Otherwise, it takes them $$$2$$$ hours.The workers work in parallel, independently of each other. Each worker can only work on one task at once.Assign the workers to all tasks in such a way that the tasks are completed as early as possible. The work starts at time $$$0$$$. What's the minimum time all tasks can be completed by?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le m \le 2 \cdot 10^5$$$) — the number of workers and the number of tasks. The second line contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le n$$$) — the index of the worker proficient in the $$$i$$$-th task. The sum of $$$m$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a single integer — the minimum time all tasks can be completed by.

NoteIn the first testcase, the first worker works on tasks $$$1$$$ and $$$3$$$, and the second worker works on tasks $$$2$$$ and $$$4$$$. Since they both are proficient in the corresponding tasks, they take $$$1$$$ hour on each. Both of them complete $$$2$$$ tasks in $$$2$$$ hours. Thus, all tasks are completed by $$$2$$$ hours.In the second testcase, it's optimal to assign the first worker to tasks $$$1, 2$$$ and $$$3$$$ and the second worker to task $$$4$$$. The first worker spends $$$3$$$ hours, the second worker spends $$$2$$$ hours (since they are not proficient in the taken task).In the third example, each worker can be assigned to the task they are proficient at. Thus, each of them complete their task in $$$1$$$ hour.

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask += (time / 2)
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += (v + (time-v)/2)
			}
		}
		if totalTask >= m {
			return true
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func min(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 < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		aa := make([]int, m)
		bb := make([]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			aa[i] = v
			bb[v-1]++
		}
		sort.Slice(bb, func(i, j int) bool {
			return bb[i] > bb[j]
		})

		resp := sort.Search(m*2, func(i int) bool {
			t := 0
			for _, v := range bb {
				if v >= i {
					t += v - i
				} else {
					t -= (i - v) / 2
				}
				if t <= 0 {
					break
				}
			}
			return t <= 0
		})
		fmt.Fprintln(out, resp)
	}
}

package main

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

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

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(2*m+1, func(t int) bool {
		var ans int64
		for i := range worker {
			remain := int64(t - worker[i])
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscan(reader, &n, &m)
	f := make([]int, n)
	mx := 0
	for k := 0; k < m; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		ak--
		f[ak]++
		if f[ak] > mx {
			mx = f[ak]
		}
	}

	l := 1
	r := mx

	for l < r {
		mid := (l + r) / 2

		delta := int64(0)
		for k := 0; k < n; k++ {
			if f[k] >= mid {
				delta += int64(f[k] - mid)
			} else {
				delta -= int64(mid - f[k]) / 2
			}
		}

		if delta <= 0 {
			r = mid
		} else {
			l = mid + 1
		}
	}

	fmt.Fprintln(writer, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscan(reader, &n, &m)
	f := make([]int, n)
	ff := make([]int, n)
	mx := 0
	for k := 0; k < m; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		ak--
		f[ak]++
		if f[ak] > mx {
			mx = f[ak]
		}
	}

	sort.Ints(f)

	l := 1
	r := mx

	for l < r {
		mid := (l + r) / 2
		copy(ff, f)
		k := 0
		ok := true
		for j := n - 1; j >= 0; j-- {
			for k < j && ff[j] > mid {
				if ff[k] + 2 > mid {
					k++
					continue
				}
				ff[j]--
				ff[k] += 2
			}
			ok = ok && ff[j] <= mid
		}

		if ok {
			r = mid
		} else {
			l = mid + 1
		}
	}

	fmt.Fprintln(writer, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

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

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

	var T int
	var n int
	var m int
	var x int

	for Fscan(in, &T); T > 0; T-- {

		Fscan(in, &n)
		Fscan(in, &m)

		a := make([]int, m)
		d := make([]int, n)
		for i := 0; i < m; i++ {
			Fscan(in, &x)
			a[i] = x
			d[x-1]++
		}
		sort.Ints(d)
		for i := 0; i < len(d)/2; i++ {
			d[i], d[len(d)-1-i] = d[len(d)-1-i], d[i]
		}

		ans := sort.Search(m*2, func(f int) bool {
			t := 0
			for _, v := range d {
				if v >= f {
					t += v - f
				} else {
					t -= (f - v) / 2
				}
				if t <= 0 {
					break
				}
			}
			return t <= 0
		})

		Fprintln(out, ans)
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask += (time / 2)
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += (v + (time-v)/2)
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask = totalTask + (time / 2)
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += v + (time-v)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += v + (time-v)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for _, v := range good {
		if time <= v {
			totalTask += time
		} else {
			totalTask += v + (time-v)/2
		}
	}
	totalTask += (time / 2) * (n - len(good))

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	inp := bufio.NewReader(os.Stdin)
	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var work int
			fmt.Scan(&work)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	var test int
	fmt.Scanln(&test)
	res := []int{}

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var work int
			fmt.Scan(&work)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		res = append(res, solve(n, m, good))
	}

	for _, v := range res {
		fmt.Println(v)
	}
}

package main

import (
	"fmt"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	fmt.Println(n, m, good)
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var work int
			fmt.Scanf("%d", &work)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
	"strconv"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	fmt.Println(n, m, good)
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var tmp string
			fmt.Scan(&tmp)
			work, _ := strconv.Atoi(tmp)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
	"strconv"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var tmp string
			fmt.Scan(&tmp)
			work, _ := strconv.Atoi(tmp)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func min(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 < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

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

		var tot int
		var idle int
		for m > 0 {
			size := len(mm)
			for k := range mm {
				d := min(mm[k]-1, idle)
				mm[k] -= 1 + d
				m -= 1 + d
				idle -= d
				if mm[k] == 0 {
					delete(mm, k)
				}
			}
			idle = n - size
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

func min(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 < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

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

		var tot int
		var idle int
		for m > 0 {
			size := len(mm)
			for k := range mm {
				d := min(mm[k]-1, idle)
				mm[k] -= 1 + d
				m -= 1 + d

				if mm[k] == 0 {
					delete(mm, k)
				}
			}
			idle = n - size
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

func min(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 < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

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

		var tot int
		var idle int
		for m > 0 {
			size := len(mm)
			for k := range mm {
				d := min(mm[k]-1, idle)
				mm[k] -= 1 + d
				m -= 1 + d

				if mm[k] == 0 {
					delete(mm, k)
				}
			}
			idle = size
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

func min(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 < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

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

		var tot int
		for m > 0 {
			var idle int
			for i := 1; i <= n; i++ {
				if mm[i] <= 0 {
					idle++
				}
			}

			var f bool
			for i := 1; i <= n; i++ {
				if idle > 0 && mm[i] > 2 {
					d := min(mm[i]-2, idle)
					idle -= d
					mm[i] -= 2 + d
					f = true
					m -= 2 + d
				} else if (idle > 0 || f) && mm[i] == 2 {
					mm[i] -= 2
					m -= 2
					f = true
				} else if mm[i] > 0 {
					mm[i]--
					m--
				}
			}
			tot++
			if f {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

func min(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 < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

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

		var tot int
		for m > 0 {
			var idle int
			for i := 1; i <= n; i++ {
				if mm[i] <= 0 {
					idle++
				}
			}

			var f bool
			for i := 1; i <= n; i++ {
				if idle > 0 && mm[i] > 2 {
					d := min(mm[i]-2, idle)
					idle -= d
					mm[i] -= 2 + d
					f = true
					m -= 2 + d
				} else if idle > 0 && mm[i] == 2 {
					mm[i] -= 2
					m -= 2
					f = true
				} else if mm[i] > 0 {
					mm[i]--
					m--
				}
			}
			tot++
			if f {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

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

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

		var tot int
		for m > 0 {
			var idle int
			for i := 1; i <= n; i++ {
				if mm[i] <= 0 {
					idle++
				}
			}

			var f bool
			for i := 1; i <= n; i++ {
				if idle > 0 && mm[i] > 2 {
					idle--
					mm[i] -= 3
					f = true
					m -= 3
				} else if idle > 0 && mm[i] == 2 {
					mm[i] -= 2
					m -= 2
					f = true
				} else if mm[i] > 0 {
					mm[i]--
					m--
				}
			}
			tot++
			if f {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(2*m+1, func(t int) bool {
		ans := 0
		for i := range worker {
			remain := t - worker[i]
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

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

package main

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

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

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(m+1, func(t int) bool {
		ans := 0
		for i := range worker {
			remain := t - worker[i]
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

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

package main

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

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

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(2e5+1, func(t int) bool {
		ans := 0
		for i := range worker {
			remain := t - worker[i]
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscan(reader, &n, &m)
	f := make([]int, n)
	mx := 0
	for k := 0; k < m; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		ak--
		f[ak]++
		if f[ak] > mx {
			mx = f[ak]
		}
	}

	sort.Ints(f)

	l := 1
	r := mx

	for l < r {
		mid := (l + r) / 2

		delta := 0
		for k := 0; k < n; k++ {
			if f[k] >= mid {
				delta += f[k] - mid
			} else {
				delta -= (mid - f[k]) / 2
			}
		}

		if delta <= 0 {
			r = mid
		} else {
			l = mid + 1
		}
	}

	fmt.Fprintln(writer, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}