Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109). Some positions may coincide.

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and  for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

package main

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

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

	var n, x, y int
	Fscan(in, &n)
	rows, cols := map[int]int{}, map[int]int{}
	cnts := map[[2]int]int{}
	ans := int64(0)
	for ; n > 0; n-- {
		Fscan(in, &x, &y)
		p := [2]int{x, y}
		ans += int64(rows[y] + cols[x] - cnts[p])
		rows[y]++
		cols[x]++
		cnts[p]++
	}
	Fprint(out, ans)
}

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

package main

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

var (
	sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
	wr *bufio.Writer  = bufio.NewWriter(os.Stdout)
)

func readInt() int64 {
	sc.Scan()
	ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return ans
}

func printInts(ints ...int64) {
	for _, v := range ints {
		wr.WriteString(strconv.FormatInt(v, 10))
		wr.WriteByte(' ')
	}
}

func println() {
	wr.WriteByte('\n')
}

type pt struct {
	x, y int64
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)

	var n int64 = readInt()

	cols := make(map[int64]int64)
	rows := make(map[int64]int64)
	set := make(map[pt]int64)
	for i := int64(0); i < n; i++ {
		x, y := readInt(), readInt()
		if _, prs := cols[x]; prs {
			cols[x] = cols[x] + 1
		} else {
			cols[x] = 1
		}
		if _, prs := rows[y]; prs {
			rows[y] = rows[y] + 1
		} else {
			rows[y] = 1
		}
		p := pt{x, y}
		if _, prs := set[p]; prs {
			set[p] = set[p] + 1
		} else {
			set[p] = 1
		}
	}
	var r int64
	for _, v := range rows {
		r += v * (v - 1) / 2
	}
	for _, v := range cols {
		r += v * (v - 1) / 2
	}
	for _, v := range set {
		if v > 1 {
			r -= v * (v - 1) / 2
		}
	}
	printInts(r)
	println()
}

package main

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

type Pair struct {
	first, second int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	ver := make(map[int]int64)
	hor := make(map[int]int64)
	p := make(map[Pair]int64)
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		ver[x] += 1
		hor[y] += 1
		p[Pair{x, y}] += 1
	}
	var ans int64
	for _, v := range hor {
		ans += v * (v - 1) / 2
	}
	for _, v := range ver {
		ans += v * (v - 1) / 2
	}
	for _, v := range p {
		ans -= v * (v - 1) / 2
	}
	fmt.Println(ans)
}

package main

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

type Pair struct {
	first, second int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	ver := make(map[int]int64)
	hor := make(map[int]int64)
	p := make(map[int64]int64)
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		ver[x] += 1
		hor[y] += 1
		p[int64(x)*1000000000+int64(y)] += 1
		//p[Pair{x, y}] += 1
	}
	var ans int64
	for _, v := range hor {
		ans += v * (v - 1) / 2
	}
	for _, v := range ver {
		ans += v * (v - 1) / 2
	}
	for _, v := range p {
		ans -= v * (v - 1) / 2
	}
	fmt.Println(ans)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

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

func main() {
	in.Split(bufio.ScanWords)
	var res int64
	mx := make(map[int]int)
	my := make(map[int]int)
	mxy := make(map[[2]int]int)

	n := readInt()
	for i := 0; i < n; i++ {
		x := readInt()
		y := readInt()
		xy := [2]int{x, y}
		res += int64(mx[x] + my[y] - mxy[xy])
		mx[x]++
		my[y]++
		mxy[xy]++
	}
	fmt.Println(res)
}

package main

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

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

	pair_count := int64(0)
	s_map := make(map[string]int)
	x_map := make(map[int]map[int]int)
	y_map := make(map[int]map[int]int)

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	for i := 0; i < n; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			s = re.ReplaceAllString(s, "")

			xy := strings.Split(s, " ")
			a, err := strconv.Atoi(xy[0])
			if err != nil {
				return
			}
			b, err := strconv.Atoi(xy[1])
			if err != nil {
				return
			}

			if s_map[s] > 0 {
				pair_count += int64(s_map[s])
			}
			s_map[s] += 1
			if x_map[a] == nil {
				x_map[a] = make(map[int]int)
			}
			x_map[a][b] += 1
			if y_map[b] == nil {
				y_map[b] = make(map[int]int)
			}
			y_map[b][a] += 1
		}
	}

	bf := make([]int, n)
	bl := 0

	for _, xm := range x_map {
		if len(xm) > 1 {
			bl = 0
			for _, c := range xm {
				if bl == 0 {
					bf[0] = c
				} else {
					pair_count += int64(bf[bl-1]) * int64(c)
					bf[bl] = bf[bl-1] + c
				}
				bl++
			}
		}
	}

	for _, ym := range y_map {
		if len(ym) > 1 {
			bl = 0
			for _, c := range ym {
				if bl == 0 {
					bf[0] = c
				} else {
					pair_count += int64(bf[bl-1]) * int64(c)
					bf[bl] = bf[bl-1] + c
				}
				bl++
			}
		}
	}

	fmt.Println(pair_count)
}

package main

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

type point struct {
	x int
	y int
}

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

	mx := make(map[int]int)
	my := make(map[int]int)
	mp := make(map[point]int)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		x, _ := strconv.Atoi(bs.Text())
		bs.Scan()
		y, _ := strconv.Atoi(bs.Text())

		//if _, ok := mx[x]; ok {
		//		mx[x]++
		//	} else {
		//		mx[x] = 1
		//	}
		mx[x]++

		if _, ok := my[y]; ok {
			my[y]++
		} else {
			my[y] = 1
		}
		//my[y]++

		pt := point{x, y}
		if _, ok := mp[pt]; ok {
			mp[pt]++
		} else {
			mp[pt] = 1
		}
		//mp[pt]++
	}

	var ans uint64
	ans = 0
	for _, v := range mx {
		if v > 1 {
			ans += uint64(v) * uint64(v-1) / 2
		}
	}
	for _, v := range my {
		if v > 1 {
			ans += uint64(v) * uint64(v-1) / 2
		}
	}

	for _, v := range mp {
		if v > 1 {
			ans -= uint64(v) * uint64(v-1) / 2
		}
	}

	fmt.Println(ans)
}

package main

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

type point struct {
	x int
	y int
}

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

	mx := make(map[int]int)
	my := make(map[int]int)
	mp := make(map[point]int)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		x, _ := strconv.Atoi(bs.Text())
		bs.Scan()
		y, _ := strconv.Atoi(bs.Text())

		//if _, ok := mx[x]; ok {
		//		mx[x]++
		//	} else {
		//		mx[x] = 1
		//	}
		mx[x]++

		//if _, ok := my[y]; ok {
		//	my[y]++
		//} else {
		//	my[y] = 1
		//}
		my[y]++

		pt := point{x, y}
		//if _, ok := mp[pt]; ok {
		//	mp[pt]++
		//} else {
		//	mp[pt] = 1
		//}
		mp[pt]++
	}

	var ans uint64
	ans = 0
	for _, v := range mx {
		if v > 1 {
			ans += uint64(v) * uint64(v-1) / 2
		}
	}
	for _, v := range my {
		if v > 1 {
			ans += uint64(v) * uint64(v-1) / 2
		}
	}

	for _, v := range mp {
		if v > 1 {
			ans -= uint64(v) * uint64(v-1) / 2
		}
	}

	fmt.Println(ans)
}

package main

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

type point struct {
	x int
	y int
}

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

	mx := make(map[int]int)
	my := make(map[int]int)
	mp := make(map[point]int)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		x, _ := strconv.Atoi(bs.Text())
		bs.Scan()
		y, _ := strconv.Atoi(bs.Text())

		if _, ok := mx[x]; ok {
			mx[x]++
		} else {
			mx[x] = 1
		}
		//mx[x]++

		if _, ok := my[y]; ok {
			my[y]++
		} else {
			my[y] = 1
		}

		pt := point{x, y}
		if _, ok := mp[pt]; ok {
			mp[pt]++
		} else {
			mp[pt] = 1
		}
	}

	var ans uint64
	ans = 0
	for _, v := range mx {
		if v > 1 {
			ans += uint64(v) * uint64(v-1) / 2
		}
	}
	for _, v := range my {
		if v > 1 {
			ans += uint64(v) * uint64(v-1) / 2
		}
	}

	for _, v := range mp {
		if v > 1 {
			ans -= uint64(v) * uint64(v-1) / 2
		}
	}

	fmt.Println(ans)
}

package main

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

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

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

	X := make(map[int64]int64)
	Y := make(map[int64]int64)
	Z := make(map[int64]int64)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		X[x]++
		Y[y]++

		z := x<<32 + y
		Z[z]++
	}

	var m int64
	for _, v := range X {
		if v > 1 {
			m += v * (v - 1) / 2
		}
	}
	for _, v := range Y {
		if v > 1 {
			m += v * (v - 1) / 2
		}
	}

	for _, v := range Z {
		if v > 1 {
			m -= v * (v - 1) / 2
		}
	}

	fmt.Println(m)
}

package main

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

var (
	sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
	wr *bufio.Writer  = bufio.NewWriter(os.Stdout)
)

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

func printInts(ints ...int) {
	for _, v := range ints {
		wr.WriteString(strconv.Itoa(v))
		wr.WriteByte(' ')
	}
}

func println() {
	wr.WriteByte('\n')
}

type pt struct {
	x, y int
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)

	var n int = readInt()

	cols := make(map[int]int)
	rows := make(map[int]int)
	set := make(map[pt]int)
	for i := 0; i < n; i++ {
		x, y := readInt(), readInt()
		if _, prs := cols[x]; prs {
			cols[x] = cols[x] + 1
		} else {
			cols[x] = 1
		}
		if _, prs := rows[y]; prs {
			rows[y] = rows[y] + 1
		} else {
			rows[y] = 1
		}
		p := pt{x, y}
		if _, prs := set[p]; prs {
			set[p] = set[p] + 1
		} else {
			set[p] = 1
		}
	}
	var r int
	for _, v := range rows {
		r += v * (v - 1) / 2
	}
	for _, v := range cols {
		r += v * (v - 1) / 2
	}
	for _, v := range set {
		if v > 1 {
			r -= v * (v - 1) / 2
		}
	}
	printInts(r)
	println()
}

package main

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

type Pair struct {
	first, second int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	if n > 100000 {
		for i := 0; i < n; i++ {
			var x, y int
			fmt.Fscanf(in, "%d %d\n", &x, &y)
			//fmt.Scanf("%d %d\n", &x, &y)
		}
		return
	}
	ver := make(map[int]int64)
	hor := make(map[int]int64)
	p := make(map[int64]int64)
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		ver[x] += 1
		hor[y] += 1
		p[int64(x)*1000000000+int64(y)] += 1
		//p[Pair{x, y}] += 1
	}
	var ans int64
	for _, v := range hor {
		ans += v * (v - 1) / 2
	}
	for _, v := range ver {
		ans += v * (v - 1) / 2
	}
	for _, v := range p {
		ans -= v * (v - 1) / 2
	}
	fmt.Println(ans)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

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

func main() {
	in.Split(bufio.ScanWords)
	var res int64
	mx := make(map[int]int)
	my := make(map[int]int)
	mxy := make(map[[2]int]int)

	n := readInt()
	for i := 0; i < n; i++ {
		x := readInt()
		y := readInt()
		xy := [2]int{x, y}
		res += int64(mx[x] + my[y] - mxy[xy])
		mx[x]++
		my[y]++
		mxy[xy]++
	}
	fmt.Println(res)
}

package main

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

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

	s_map := make(map[string]int)
	x_map := make(map[int]map[int]int)
	y_map := make(map[int]map[int]int)

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	for i := 0; i < n; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			s = re.ReplaceAllString(s, "")

			xy := strings.Split(s, " ")
			a, err := strconv.Atoi(xy[0])
			if err != nil {
				return
			}
			b, err := strconv.Atoi(xy[1])
			if err != nil {
				return
			}

			s_map[s] += 1
			if x_map[a] == nil {
				x_map[a] = make(map[int]int)
			}
			x_map[a][b] += 1
			if y_map[b] == nil {
				y_map[b] = make(map[int]int)
			}
			y_map[b][a] += 1
		}
	}

	pair_count := 0
	bf := make([]int, n)
	bl := 0

	for _, xm := range x_map {
		if len(xm) > 1 {
			bl = 0
			for _, c := range xm {
				for i := 0; i < bl; i++ {
					pair_count += bf[i] * c
				}

				bf[bl] = c
				bl++
			}
		}
	}

	for _, ym := range y_map {
		if len(ym) > 1 {
			bl = 0
			for _, c := range ym {
				for i := 0; i < bl; i++ {
					pair_count += bf[i] * c
				}

				bf[bl] = c
				bl++
			}
		}
	}

	for _, c := range s_map {
		if c > 1 {
			pair_count += c * (c - 1) / 2
		}
	}

	fmt.Println(pair_count)
}

package main

import (
	"bytes"
	"fmt"
)

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

	X := make(map[int]int)
	Y := make(map[int]int)
	Z := make(map[string]int)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &x, &y)
		X[x]++
		Y[y]++

		var buf bytes.Buffer
		fmt.Fprintf(&buf, "%d,%d", x, y)
		Z[buf.String()]++
	}

	var m int
	for _, v := range X {
		if v > 1 {
			m += v * (v - 1) / 2
		}
	}
	for _, v := range Y {
		if v > 1 {
			m += v * (v - 1) / 2
		}
	}

	for _, v := range Z {
		if v > 1 {
			m -= (v - 1)
		}
	}

	fmt.Println(m)
}


This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.Initially you have a set containing one element — $$$0$$$. You need to handle $$$q$$$ queries of the following types:+ $$$x$$$ — add the integer $$$x$$$ to the set. It is guaranteed that this integer is not contained in the set; ? $$$k$$$ — find the $$$k\text{-mex}$$$ of the set. In our problem, we define the $$$k\text{-mex}$$$ of a set of integers as the smallest non-negative integer $$$x$$$ that is divisible by $$$k$$$ and which is not contained in the set.

The first line contains an integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$) — the number of queries. The following $$$q$$$ lines describe the queries. An addition query of integer $$$x$$$ is given in the format + $$$x$$$ ($$$1 \leq x \leq 10^{18}$$$). It is guaranteed that $$$x$$$ was not contained in the set. A search query of $$$k\text{-mex}$$$ is given in the format ? $$$k$$$ ($$$1 \leq k \leq 10^{18}$$$). It is guaranteed that there will be at least one query of type ?.

For each query of type ? output a single integer — the $$$k\text{-mex}$$$ of the set.

NoteIn the first example:After the first and second queries, the set will contain elements $$$\{0, 1, 2\}$$$. The smallest non-negative number that is divisible by $$$1$$$ and is not contained in the set is $$$3$$$.After the fourth query, the set will contain the elements $$$\{0, 1, 2, 4\}$$$. The smallest non-negative number that is divisible by $$$2$$$ and is not contained in the set is $$$6$$$.In the second example:   Initially, the set contains only the element $$$\{0\}$$$.  After adding an integer $$$100$$$ the set contains elements $$$\{0, 100\}$$$.  $$$100\text{-mex}$$$ of the set is $$$200$$$.  After adding an integer $$$200$$$ the set contains elements $$$\{0, 100, 200\}$$$.  $$$100\text{-mex}$$$ of the set is $$$300$$$.  After adding an integer $$$50$$$ the set contains elements $$$\{0, 50, 100, 200\}$$$.  $$$50\text{-mex}$$$ of the set is $$$150$$$.

package main

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

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

	var q int
	var x int64
	var op string
	Fscan(in, &q)
	mex := map[int64]int64{}
	has := map[int64]bool{}
	for qi := 1; qi <= q; qi++ {
		Fscan(in, &op, &x)
		if op == "+" {
			has[x] = true
		} else {
			if mex[x] == 0 {
				mex[x] = x
			}
			for has[mex[x]] {
				mex[x] += x
			}
			Fprintln(out, mex[x])
		}
	}
}

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

package main

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

const cf = true

func solve() {
	var q int
	fmt.Fscan(in, &q)
	var set set[int]
	var query string
	var val int
	cache := make(map[int]int)
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &query, &val)
		if query == "+" {
			set.add(val)
		} else {
			cur, ok := cache[val]
			if !ok {
				cur = val
			}
			for set.has(cur) {
				cur += val
			}
			fmt.Fprintln(out, cur)
			cache[val] = cur
		}
	}
}

func main() {
	defer out.Flush()
	t := 1
	//fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

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

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

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

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

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

type Solver struct {
	m map[int64]bool
	k map[int64]int64
}

func (s *Solver) Add(n int64) {
	s.m[n] = true
}

func (s *Solver) KMex(n int64) int64 {
	from := n
	if prev, ok := s.k[n]; ok {
		from = prev
	}
	for {
		if !s.m[from] {
			s.k[n] = from
			return from
		}
		from += n
	}
}

func main() {
	defer writer.Flush()
	s := &Solver{
		m: map[int64]bool{},
		k: map[int64]int64{},
	}
	for q := _int(); q > 0; q-- {
		op := _string()
		n := _int64()
		if op == "+" {
			s.Add(n)
		} else {
			printf("%d\n", s.KMex(n))
		}
	}
}


Let's assume that   v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find .

The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.  Each of the following t lines of the input contains integer n (2 ≤ n ≤ 109).

Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.

package main

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

func isPrime(p int) bool {
	for i := 2; i <= int(math.Sqrt(float64(p))); i++ {
		if p%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		var v, u int64
		for j := n; j >= 2; j-- {
			if isPrime(j) {
				v = int64(j)
				break
			}
		}
		for j := n + 1; ; j++ {
			if isPrime(j) {
				u = int64(j)
				break
			}
		}
		ans := big.NewRat(v-2, 2*v)
		sub := big.NewRat(int64(n)-v+1, v*u)
		ans.Add(ans, sub)
		fmt.Printf("%s\n", ans.String())
	}
}


This year in Equestria was a year of plenty, so Applejack has decided to build some new apple storages. According to the advice of the farm designers, she chose to build two storages with non-zero area: one in the shape of a square and another one in the shape of a rectangle (which possibly can be a square as well).Applejack will build the storages using planks, she is going to spend exactly one plank on each side of the storage. She can get planks from her friend's company. Initially, the company storehouse has $$$n$$$ planks, Applejack knows their lengths. The company keeps working so it receives orders and orders the planks itself. Applejack's friend can provide her with information about each operation. For convenience, he will give her information according to the following format:  $$$+$$$ $$$x$$$: the storehouse received a plank with length $$$x$$$  $$$-$$$ $$$x$$$: one plank with length $$$x$$$ was removed from the storehouse (it is guaranteed that the storehouse had some planks with length $$$x$$$). Applejack is still unsure about when she is going to order the planks so she wants to know if she can order the planks to build rectangular and square storages out of them after every event at the storehouse. Applejack is busy collecting apples and she has completely no time to do the calculations so she asked you for help!We remind you that all four sides of a square are equal, and a rectangle has two pairs of equal sides.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$): the initial amount of planks at the company's storehouse, the second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^5$$$): the lengths of the planks. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$): the number of events in the company. Each of the next $$$q$$$ lines contains a description of the events in a given format: the type of the event (a symbol $$$+$$$ or $$$-$$$) is given first, then goes the integer $$$x$$$ ($$$1 \le x \le 10^5$$$).

After every event in the company, print "YES" if two storages of the required shape can be built from the planks of that company's set, and print "NO" otherwise. You can print each letter in any case (upper or lower).

NoteAfter the second event Applejack can build a rectangular storage using planks with lengths $$$1$$$, $$$2$$$, $$$1$$$, $$$2$$$ and a square storage using planks with lengths $$$1$$$, $$$1$$$, $$$1$$$, $$$1$$$.After the sixth event Applejack can build a rectangular storage using planks with lengths $$$2$$$, $$$2$$$, $$$2$$$, $$$2$$$ and a square storage using planks with lengths $$$1$$$, $$$1$$$, $$$1$$$, $$$1$$$.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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
}

var (
	dx     [4]int       = [4]int{-1, 0, 1, 0}
	dy     [4]int       = [4]int{0, 1, 0, -1}
	dirMap map[byte]int = map[byte]int{'U': 0, 'R': 1, 'D': 2, 'L': 3}
)

func solve() {
	n := nextInt()
	nums := map[int]int{}
	has := [4]int{}

	for i := 0; i < n; i++ {
		x := nextInt()
		nums[x]++
		if nums[x] == 8 {
			has[3]++
			has[2]--
		} else if nums[x] == 6 {
			has[2]++
			has[1]--
		} else if nums[x] == 4 {
			has[1]++
			has[0]--
		} else if nums[x] == 2 {
			has[0]++
		}
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		qt, x := next(), nextInt()
		if qt == "+" {
			nums[x]++
			if nums[x] == 8 {
				has[3]++
				has[2]--
			} else if nums[x] == 6 {
				has[2]++
				has[1]--
			} else if nums[x] == 4 {
				has[1]++
				has[0]--
			} else if nums[x] == 2 {
				has[0]++
			}
		} else {
			nums[x]--
			if nums[x] == 1 {
				has[0]--
			} else if nums[x] == 3 {
				has[1]--
				has[0]++
			} else if nums[x] == 5 {
				has[2]--
				has[1]++
			} else if nums[x] == 7 {
				has[3]--
				has[2]++
			}
		}
		if has[3] > 0 || has[2] > 1 || (has[2] > 0 && has[0]+has[1] > 0) || has[1] > 1 || (has[1] > 0 && has[0] > 1) {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}

}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }
}

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	solver := NewSolver(n, A)

	q := readNum(reader)

	var buf bytes.Buffer

	for q > 0 {
		q--
		s, _ := reader.ReadBytes('\n')

		var x int
		readInt(s, 2, &x)
		var res bool
		if s[0] == '+' {
			res = solver.Add(x)
		} else {
			res = solver.Add(-x)
		}

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

type Solver struct {
	planks map[int]int
	two    int
	four   int
}

func NewSolver(n int, A []int) Solver {
	planks := make(map[int]int)

	for i := 0; i < n; i++ {
		planks[A[i]]++
	}

	var two int
	var four int
	for _, v := range planks {
		two += v / 2
		four += v / 4
	}

	return Solver{planks, two, four}
}

func (solver *Solver) Add(x int) bool {
	sign := 1
	if x < 0 {
		x = -x
		sign = -1
	}
	y := solver.planks[x]

	two, four := solver.two, solver.four

	two -= y / 2
	four -= y / 4

	y += sign

	two += y / 2
	four += y / 4

	solver.two = two
	solver.four = four
	solver.planks[x] = y

	return four >= 1 && two >= 4
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	const maxa = int(1e5 + 5)

	n := io.NextInt()
	a := io.NextInts(n)
	f := make([]int, maxa)
	c2, c4, c6, c8 := 0, 0, 0, 0

	upd := func(x, d int) {
		if d == 1 {
			f[x]++
			if f[x] == 2 {
				c2++
			}
			if f[x] == 4 {
				c4++
			}
			if f[x] == 6 {
				c6++
			}
			if f[x] == 8 {
				c8++
			}
		} else {
			if f[x] == 2 {
				c2--
			}
			if f[x] == 4 {
				c4--
			}
			if f[x] == 6 {
				c6--
			}
			if f[x] == 8 {
				c8--
			}
			f[x]--
		}
	}

	for _, x := range a {
		upd(x, 1)
	}

	for q := io.NextInt(); q > 0; q-- {
		t, x := io.Next(), io.NextInt()
		if t == "+" {
			upd(x, 1)
		} else {
			upd(x, -1)
		}
		if c4 >= 1 && c2 >= 3 || c4 >= 2 || c6 >= 1 && c2 >= 2 || c8 >= 1 {
			io.Println("YES")
		} else {
			io.Println("NO")
		}
	}
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

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

	inputStr := func() string {
		scanner.Scan()
		return scanner.Text()
	}

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

	n := inputInt()
	a := make([]int, 10e5+1)

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

	count2 := 0
	count4 := 0

	for i := range a {
		count2 += a[i] / 2
		count4 += a[i] / 4
	}

	q := inputInt()

	for i := 0; i < q; i++ {
		sgn := inputStr()
		val := inputInt()
		count2 -= a[val] / 2
		count4 -= a[val] / 4
		switch sgn {
		case "+":
			{
				a[val]++
				count2 += a[val] / 2
				count4 += a[val] / 4
			}
		case "-":
			{
				a[val]--
				count2 += a[val] / 2
				count4 += a[val] / 4
			}
		}

		if count4 >= 1 && count2 >= 4 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

/*
URL:
https://codeforces.com/contest/1393/problem/B
*/

package main

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

/********** 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 (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n int
	A []int
	q int

	cnts [100000 + 50]int
	G    [10]int
)

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)
	q = ReadInt()

	for i := 0; i < n; i++ {
		cnts[A[i]]++
	}
	for i := 1; i <= 100000; i++ {
		// if cnts[i] >= 4 {
		// 	G[4]++
		// } else if cnts[i] >= 2 {
		// 	G[2]++
		// }
		cnt := cnts[i]
		four := cnt / 4
		two := (cnt % 4) / 2
		G[4] += four
		G[2] += two
	}

	for i := 0; i < q; i++ {
		tmp := ReadString()
		x := ReadInt()

		preCnt := cnts[x]
		four := preCnt / 4
		two := (preCnt % 4) / 2
		G[4] -= four
		G[2] -= two

		if tmp == "+" {
			cnts[x]++
		} else {
			cnts[x]--
		}
		curCnt := cnts[x]
		four = curCnt / 4
		two = (curCnt % 4) / 2
		G[4] += four
		G[2] += two

		if G[4] >= 2 || (G[4] >= 1 && G[2] >= 2) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func toG(cnt int) int {
	if cnt >= 8 {
		// G[8]++
		return 8
	} else if cnt >= 6 {
		// G[6]++
		return 6
	} else if cnt >= 4 {
		// G[4]++
		return 4
	} else if cnt >= 2 {
		// G[2]++
		return 2
	}
	return 0
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	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
}

// 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])
		res = append(res, []rune(str)...)

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

	return string(res)
}

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

	for i := 0; i < len(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)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if debug != 0 && len(os.Args) > 1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024*1024)

	planks := make([]int, int(1e5)+3)
	_ = readInt()
	arr := readInts()
	c2, c4 := 0, 0
	for _, v64 := range arr {
		v := int(v64)
		planks[v]++
		if planks[v] % 2 == 0 {
			c2++
		}
		if planks[v] % 4 == 0 {
			c4++
		}
	}
	q := readInt()
	for ; q > 0; q-- {
		str := readLine()
		op := str[0]
		v, _ := strconv.ParseInt(str[2:], 10, 32)
		switch op {
		case '+':
			planks[v]++
			if planks[v] % 2 == 0 {
				c2++
			}
			if planks[v] % 4 == 0 {
				c4++
			}
			break
		case '-':
			if planks[v] % 2 == 0 {
				c2--
			}
			if planks[v] % 4 == 0 {
				c4--
			}
			planks[v]--
			break
		}
		if c4 >= 2 || (c4 == 1 && c2 >= 4) {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = v
	}
	return res
}

func readInt() int64 {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 32)
	return int64(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func band(i int64) int64 {
	for _, b := range []int64{8, 6, 4, 2} {
		if i >= b {
			return b
		}
	}
	return 0
}

func main() {
	defer writer.Flush()
	n := sint64()
	counts := map[int64]int64{}
	for i := int64(0); i < n; i++ {
		counts[sint64()]++
	}
	bands := map[int64]int64{}
	for _, c := range counts {
		bands[band(c)]++
	}
	q := sint64()
	for i := int64(0); i < q; i++ {
		diff := sstring()
		num := sint64()
		bands[band(counts[num])]--
		if diff == "+" {
			counts[num]++
		} else {
			counts[num]--
		}
		bands[band(counts[num])]++
		has4 := false
		has2a := false
		has2b := false
		for _, b := range []int64{8, 6, 4, 2} {
			c := bands[b]
			if c > 0 {
				if b == 8 {
					has4, has2a, has2b = true, true, true
				} else if b == 6 {
					if c > 1 {
						has4, has2a, has2b = true, true, true
					} else {
						if has4 {
							has2a, has2b = true, true
						} else {
							has4 = true
							if has2a {
								has2b = true
							} else {
								has2a = true
							}
						}
					}
				} else if b == 4 {
					if c > 1 {
						has4, has2a, has2b = true, true, true
					} else {
						if has4 {
							has2a, has2b = true, true
						} else {
							has4 = true
						}
					}
				} else if b == 2 {
					if c > 1 {
						has2a, has2b = true, true
					} else {
						if has2a {
							has2b = true
						} else {
							has2a = true
						}
					}
				}
			}
			if has4 && has2a && has2b {
				break
			}
		}
		if has4 && has2a && has2b {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	solver := NewSolver(n, A)

	q := readNum(reader)

	var buf bytes.Buffer

	for q > 0 {
		q--
		s, _ := reader.ReadBytes('\n')

		var x int
		readInt(s, 2, &x)
		var res bool
		if s[0] == '+' {
			res = solver.Add(x)
		} else {
			res = solver.Sub(x)
		}

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

type Solver struct {
	planks map[int]int
	cnt    [4]int
}

func NewSolver(n int, A []int) Solver {
	planks := make(map[int]int)

	for i := 0; i < n; i++ {
		planks[A[i]]++
	}
	var cnt [4]int
	for _, v := range planks {
		cnt[v%4]++
	}

	return Solver{planks, cnt}
}

func (solver *Solver) Add(x int) bool {
	prev := solver.planks[x]

	solver.cnt[prev%4]--

	solver.planks[x]++

	cur := prev + 1

	solver.cnt[cur%4]++

	// cnt[0] doesn't matter
	// cnt[1] == 0 && cnt[3] == 0
	return check(solver.cnt)
}

func (solver *Solver) Sub(x int) bool {
	prev := solver.planks[x]
	solver.cnt[prev%4]--

	solver.planks[x]--

	cur := prev - 1

	solver.cnt[cur%4]++

	return check(solver.cnt)

}

func check(cnt [4]int) bool {
	if cnt[1] != 0 || cnt[3] != 0 {
		return false
	}
	x := cnt[2]
	return x&1 == 0
}

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	solver := NewSolver(n, A)

	q := readNum(reader)

	var buf bytes.Buffer

	for q > 0 {
		q--
		s, _ := reader.ReadBytes('\n')

		var x int
		readInt(s, 2, &x)
		var res bool
		if s[0] == '+' {
			res = solver.Add(x)
		} else {
			res = solver.Add(-x)
		}

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

type Solver struct {
	planks map[int]int
	two    int
}

func NewSolver(n int, A []int) Solver {
	planks := make(map[int]int)

	for i := 0; i < n; i++ {
		planks[A[i]]++
	}

	var two int
	for _, v := range planks {

		x, y := v / 4, v % 4

		two += (x * 4) / 2

		if y >= 2 {
			two++
		}
	}

	return Solver{planks, two}
}

func (solver *Solver) Add(x int) bool {
	sign := 1
	if x < 0 {
		x = -x
		sign = -1
	}
	y := solver.planks[x]

	a, b := y / 4, y % 4

	two := solver.two

	two -= (a * 4) / 2
	if b >= 2 {
		two--
	}

	y += sign

	a, b = y / 4, y % 4

	two += (a * 4) / 2
	if b >= 2 {
		two++
	}
	solver.planks[x] = y
	solver.two = two
	return two/2 >= 2
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	const maxa = int(1e5 + 5)

	n := io.NextInt()
	a := io.NextInts(n)
	f := make([]int, maxa)
	c2, c4, c6, c8 := 0, 0, 0, 0

	upd := func(x, d int) {
		if d == 1 {
			f[x]++
			if f[x] == 2 {
				c2++
			}
			if f[x] == 4 {
				c4++
			}
			if f[x] == 6 {
				c6++
			}
			if f[x] == 8 {
				c8++
			}
		} else {
			if f[x] == 2 {
				c2--
			}
			if f[x] == 4 {
				c4--
			}
			if f[x] == 6 {
				c6--
			}
			if f[x] == 8 {
				c8--
			}
			f[x]--
		}
	}

	for _, x := range a {
		upd(x, 1)
	}

	for q := io.NextInt(); q > 0; q-- {
		t, x := io.Next(), io.NextInt()
		if t == "+" {
			upd(x, 1)
		} else {
			upd(x, -1)
		}
		io.Println(c2, c4, c6, c8)
		if c4 >= 1 && c2 >= 3 || c4 >= 2 || c6 >= 1 && c2 >= 2 || c8 >= 1 {
			io.Println("YES")
		} else {
			io.Println("NO")
		}
	}
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

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

	inputStr := func() string {
		scanner.Scan()
		return scanner.Text()
	}

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

	n := inputInt()
	a := make([]int, 10e5+1)

	fmt.Println(len(a))

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

	count2 := 0
	count4 := 0

	for i := range a {
		count2 += a[i] / 2
		count4 += a[i] / 4
	}

	q := inputInt()

	for i := 0; i < q; i++ {
		sgn := inputStr()
		val := inputInt()
		count2 -= a[val] / 2
		count4 -= a[val] / 4
		switch sgn {
		case "+":
			{
				a[val]++
				count2 += a[val] / 2
				count4 += a[val] / 4
			}
		case "-":
			{
				a[val]--
				count2 += a[val] / 2
				count4 += a[val] / 4
			}
		}

		if count4 >= 1 && count2 >= 4 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	n := sint64()
	counts := map[int64]int64{}
	for i := int64(0); i < n; i++ {
		counts[sint64()]++
	}
	q := sint64()
	for i := int64(0); i < q; i++ {
		diff := sstring()
		if diff == "+" {
			counts[sint64()]++
		} else {
			counts[sint64()]--
		}
		has4 := false
		has2 := false
		has := false
		for _, c := range counts {
			if c >= 8 {
				has = true
				break
			}
			if c >= 6 {
				if has4 {
					has = true
					break
				}
				has4 = true
				if has2 {
					has = true
					break
				}
				has2 = true
				continue
			}
			if c >= 4 {
				if has4 {
					has = true
					break
				}
				has4 = true
				continue
			}
			if c >= 2 {
				if has4 && has2 {
					has = true
				}
				has2 = true
				continue
			}
		}
		if has {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func band(i int64) int64 {
	for _, b := range []int64{8, 6, 4, 2} {
		if i >= b {
			return b
		}
	}
	return 0
}

func main() {
	defer writer.Flush()
	n := sint64()
	counts := map[int64]int64{}
	for i := int64(0); i < n; i++ {
		counts[sint64()]++
	}
	bands := map[int64]int64{}
	for _, c := range counts {
		bands[band(c)]++
	}
	q := sint64()
	for i := int64(0); i < q; i++ {
		diff := sstring()
		num := sint64()
		bands[band(counts[num])]--
		if diff == "+" {
			counts[num]++
		} else {
			counts[num]--
		}
		bands[band(counts[num])]++
		has4 := false
		has2a := false
		has2b := false
		for b, c := range bands {
			if b == 8 {
				has4, has2a, has2b = true, true, true
				break
			}
			if b == 6 && c > 1 {
				has4, has2a, has2b = true, true, true
				break
			}
			if b == 6 && c == 1 {
				if has4 {
					has2a, has2b = true, true
				} else {
					has4 = true
					if has2a {
						has2b = true
						break
					} else {
						has2a = true
					}
				}
			}
			if b == 4 && c > 1 {
				has4, has2a, has2b = true, true, true
				break
			}
			if b == 4 && c == 1 {
				if has4 {
					has2a, has2b = true, true
				} else {
					has4 = true
				}
			}
			if b == 2 && c > 1 {
				has2a, has2b = true, true
			}
			if b == 2 {
				if has2a {
					has2b = true
				} else {
					has2a = true
				}
			}
			if has4 && has2a && has2b {
				break
			}
		}
		if has4 && has2a && has2b {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}


Ela loves reading a lot, just like her new co-workers in DTL! On her first day after becoming an engineer in DTL, she is challenged by a co-worker to sort a heap of books into different compartments on the shelf.$$$n$$$ books must be split into $$$k$$$ compartments on the bookshelf ($$$n$$$ is divisible by $$$k$$$). Each book is represented by a lowercase Latin letter from 'a' to 'y' inclusively, which is the beginning letter in the title of the book.Ela must stack exactly $$$\frac{n}{k}$$$ books in each compartment. After the books are stacked, for each compartment indexed from $$$1$$$ to $$$k$$$, she takes the minimum excluded (MEX) letter of the multiset of letters formed by letters representing all books in that compartment, then combines the resulting letters into a string. The first letter of the resulting string is the MEX letter of the multiset of letters formed by the first compartment, the second letter of the resulting string is the MEX letter of the multiset of letters formed by the second compartment, ... and so on. Please note, under the constraint of this problem, MEX letter can always be determined for any multiset found in this problem because 'z' is not used.What is the lexicographically greatest resulting string possible that Ela can create?A string $$$a$$$ is lexicographically greater than a string $$$b$$$ if and only if one of the following holds:  $$$b$$$ is a prefix of $$$a$$$, but $$$b \ne a$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears later in the alphabet than the corresponding letter in $$$b$$$. The minimum excluded (MEX) letter of a multiset of letters is the letter that appears earliest in the alphabet and is not contained in the multiset. For example, if a multiset of letters contains $$$7$$$ letters 'b', 'a', 'b', 'c', 'e', 'c', 'f' respectively, then the MEX letter of this compartment is 'd', because 'd' is not included in the multiset, and all letters comes before 'd' in the alphabet, namely 'a', 'b' and 'c', are included in the multiset.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 200$$$; $$$1 \le k \le n$$$). It is guaranteed that $$$n$$$ is divisible by $$$k$$$. The second line of each test case contains a string of $$$n$$$ lowercase Latin letters from 'a' to 'y' inclusively. Each letter represents the starting letter of the title of a book in the initial heap. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.

For each test case, output a string of $$$k$$$ letters which is the most optimal string that Ela can find.

5

12 3

cabccadabaac

12 6

cabccadabaac

12 12

cabccadabaac

25 1

abcdefghijklmnopqrstuvwxy

10 5

bcdxedbcfg

NoteIn the first test case, the books can be divided into $$$3$$$ compartments as below:  the first compartment contains the books with indices $$$1, 2, 3, 7$$$: $$$multiset_1 = \{$$$'c', 'a', 'b', 'd'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_1) =$$$ 'e'  the second compartment contains the books with indices $$$4, 5, 6, 9$$$ : $$$multiset_2 = \{$$$'c', 'c', 'a', 'b'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_2) =$$$ 'd'  the third compartment contains the remaining books $$$8, 10, 11, 12$$$ : $$$multiset_3 = \{$$$ 'a', 'a', 'a', 'c'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_3) =$$$ 'b' Therefore, the answer is 'edb'. It can be proven that there is no way that Ela can arrange the books so that it results in a lexicographically greater string.

// https://codeforces.com/problemset/problem/1737/A

// 1737A - Ela Sorting Books

// Ela loves reading a lot, just like her new co-workers in DTL! On her first day after becoming an engineer in DTL, she is challenged by a co-worker to sort a heap of books into different compartments on the shelf.

// n books must be split into k compartments on the bookshelf (n is divisible by k). Each book is represented by a lowercase Latin letter from 'a' to 'y' inclusively, which is the beginning letter in the title of the book.
// Ela must stack exactly n/k books in each compartment. After the books are stacked, for each compartment indexed from 1 to k, she takes the minimum excluded (MEX) letter of the multiset of letters formed by letters representing all books in that compartment, then combines the resulting letters into a string. The first letter of the resulting string is the MEX letter of the multiset of letters formed by the first compartment, the second letter of the resulting string is the MEX letter of the multiset of letters formed by the second compartment, ... and so on. Please note, under the constraint of this problem, MEX letter can always be determined for any multiset found in this problem because 'z' is not used.
// What is the lexicographically greatest resulting string possible that Ela can create?
// A string a is lexicographically greater than a string b if and only if one of the following holds:
//  • b is a prefix of a, but b≠a;
//  • in the first position where a and b differ, the string a has a letter that appears later in the alphabet than the corresponding letter in b.
// The minimum excluded (MEX) letter of a multiset of letters is the letter that appears earliest in the alphabet and is not contained in the multiset. For example, if a multiset of letters contains 7 letters 'b', 'a', 'b', 'c', 'e', 'c', 'f' respectively, then the MEX letter of this compartment is 'd', because 'd' is not included in the multiset, and all letters comes before 'd' in the alphabet, namely 'a', 'b' and 'c', are included in the multiset.

// Input
// Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). Description of the test cases follows.
// The first line of each test case contains two integers n and k (1≤n≤200; 1≤k≤n). It is guaranteed that n is divisible by k.
// The second line of each test case contains a string of n lowercase Latin letters from 'a' to 'y' inclusively. Each letter represents the starting letter of the title of a book in the initial heap.
// It is guaranteed that the sum of n over all test cases does not exceed 1000.

// Output
// For each test case, output a string of k letters which is the most optimal string that Ela can find.

// Example
// input
// 5
// 12 3
// cabccadabaac
// 12 6
// cabccadabaac
// 12 12
// cabccadabaac
// 25 1
// abcdefghijklmnopqrstuvwxy
// 10 5
// bcdxedbcfg
// output
// edb
// ccbbba
// bbbbbaaaaaaa
// z
// aaaaa

// Note

// In the first test case, the books can be divided into 3 compartments as below:
//  • the first compartment contains the books with indices 1,2,3,7: multiset1={'c', 'a', 'b', 'd'} → MEX(multiset1)= 'e'
//  • the second compartment contains the books with indices 4,5,6,9 : multiset2={'c', 'c', 'a', 'b'} → MEX(multiset2)= 'd'
//  • the third compartment contains the remaining books 8,10,11,12 : multiset3={ 'a', 'a', 'a', 'c'} → MEX(multiset3)= 'b'
// Therefore, the answer is 'edb'. It can be proven that there is no way that Ela can arrange the books so that it results in a lexicographically greater string.

// Tutorial

// We'll iterate through compartments from 1 to K. we'll try to put 1 'a' book in it, so the MEX in that compartment will not be 'a'. If any compartment can't be filled by 'a' because we ran out of 'a', the MEX of that compartment will have to be 'a'.
// The same logic applies to 'b', 'c', 'd', ..., where for each compartment from 1, if the MEX of that compartment hasn't been determined, we'll fill the corresponding letter there.
// We'll stop when reaching the end of the alphabet, or we've reached the (N/K)-th letter in the alphabet (because the first compartment is already full).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var q int
	var t, n, k, i, j uint
	var s string
	var count_char []uint
	var ans []byte
	var c rune
	var char byte

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

			count_char = make([]uint, 26)
			ans = make([]byte, 0)

			for _, c = range s {
				count_char[c-'a']++
			}

			for i = 0; i < 25 && i*k < n; i++ {
				for k > count_char[i]+uint(len(ans)) {
					ans = append(ans, byte('a'+i))
				}
			}

			if n < 25*k {
				char = byte('a' + n/k)
			} else {
				char = byte('a' + 25)
			}

			for uint(len(ans)) < k {
				ans = append(ans, char)
			}

			for i, j = 0, uint(len(ans)); i+1 < j; i, j = i+1, j-1 {
				ans[i], ans[j-1] = ans[j-1], ans[i]
			}

			fmt.Fprintln(writer, string(ans))
		}
	}

	writer.Flush()
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

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

		var s string
		fmt.Fscan(r, &s)

		sr := make([]byte, k)
		cmap := make(map[int]int)
		for _, v := range s {
			cmap[int(v)]++
		}

		for i := 0; i < k; i++ {
			var j int
			for j = 'a'; j < 'a' + n/k && cmap[j] > 0; j++ {
				cmap[j]--
			}
			sr[i] = byte(j)
		}

		fmt.Fprintln(w, string(sr))

	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const INF = 1e18
const N = 105

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		n, k, s := nextInt(), nextInt(), nextString()
		a := make([]int, 26)
		for _, v := range s {
			a[v-'a']++
		}
		res := make([]byte, k)
		for i := 0; i < k; i++ {
			res[i] = 'a'
		}
		l, r := 0, k-1
		for i := 0; i < n/k; i++ {
			for j := l; j <= r; j++ {
				if a[i] > 0 {
					a[i]--
					res[j]++
				} else {
					r = j - 1
					break
				}
			}
		}
		for _, v := range res {
			fmt.Printf("%c", v)
		}
		fmt.Printf("\n")
	}
}

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

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

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var T int
	fmt.Scan(&T)
	for tt:=0; tt<T; tt++ {
		var n, k int
		var s string
		fmt.Scan(&n, &k, &s)
		d := n / k

		cnt := make([]int, 25)
		for i:=0; i<n; i++ {
			cnt[s[i]-'a']++
		}

		var res string
		for i:=0; i<k; i++ {
			ch := 0
			for j:=0; j< int(math.Min(25, float64(d))); j++ {
				if cnt[ch] > 0 {
					cnt[ch]--
					ch++
					continue
				}
				break
			}
			res += string('a' + ch)
		}

		fmt.Println(res)
	}
}

package main

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

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

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}
	defer out.Flush()
}

func solve() {
	var n, k int
	var s string

	fmt.Fscan(in, &n, &k, &s)
	m := n / k
	cnt := make(map[rune]int)
	for _, c := range s {
		cnt[c]++
	}
	// fmt.Println(cnt)

	var res string
	for i := 0; i < k; i++ {
		j := 0
		c := 'a'
		for ; c <= 'z' && j < m; c++ {
			if cnt[c] <= 0 {
				res = res + string(c)
				// fmt.Println(i, j, c)
				break
			}
			// fmt.Println(i, j, c, cnt[c])
			j++
			cnt[c]--
		}
		if j >= m {
			res = res + string(c)
		}
	}
	fmt.Fprintf(out, "%s\n", res)
}

package main

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

const cf = true

func solve() {
	var n, k int
	fmt.Fscan(in, &n, &k)
	var str string
	cnt := make(map[byte]int)
	fmt.Fscan(in, &str)
	for i := 0; i < n; i++ {
		cnt[str[i]]++
	}
	len := n / k
	for i := 0; i < k; i++ {
		cur := "a"[0]
		for j := 0; j < len; j++ {
			if val, ok := cnt[cur]; ok && val > 0 {
				cnt[cur]--
				cur++
			} else {
				break
			}
		}
		fmt.Fprint(out, string(cur))
	}
	fmt.Fprintln(out)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}