Andryusha is an orderly boy and likes to keep things in their place.Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs. The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi. It is guaranteed that Andryusha took exactly two socks of each pair.

Print single integer — the maximum number of socks that were on the table at the same time.

NoteIn the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.In the second example Andryusha behaved as follows:   Initially the table was empty, he took out a sock from pair 2 and put it on the table.  Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table.  Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe.  Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table.  Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe.  Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.  Thus, at most two socks were on the table at the same time.

package main

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

func solve() {
	n := readInt() * 2
	res := 0
	a := make([]int, n+10)
	cur := 0
	for i := 0; i < n; i++ {
		s := readInt()
		a[s]++
		if a[s] == 1 {
			cur++
			if cur > res {
				res = cur
			}
		} else {
			cur--
		}
	}
	fmt.Println(res)
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func input(in io.Reader) []string {
	reader := bufio.NewReader(in)
	line, _ := reader.ReadString('\n')
	line, _ = reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(line), " ")
	return arr
}

func main() {
	var tmp, count, max int
	var arr [100000]bool
	arr2 := input(os.Stdin)
	for i := range arr2 {
		tmp, _ = strconv.Atoi(arr2[i])
		if !arr[tmp-1] {
			arr[tmp-1] = true
			count++
			if count > max {
				max = count
			}
		} else {
			count--
		}
	}
	fmt.Println(max)
}

package main

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

func main() {
	fmt.Println(solveQuestion(os.Stdin))
}

func solveQuestion(in io.Reader) int {
	_, socks := input(in)
	socksOut := 0
	maxSocks := 0
	isSockOut := make(map[string]bool)

	for _, sock := range *socks {
		if isSockOut[sock] {
			// If this is true
			if maxSocks < socksOut {
				maxSocks = socksOut
			}
			socksOut -= 2

		}
		socksOut += 1
		isSockOut[sock] = true

	}
	return maxSocks
}

func input(in io.Reader) (int, *[]string) {
	reader := bufio.NewReader(in)

	line, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}
	num1, err := strconv.Atoi(strings.TrimSpace(line))
	if err != nil {
		panic(err)
	}
	line, err = reader.ReadString('\n')
	if err == io.EOF {
		err = nil
	}
	if err != nil {
		panic(err)
	}
	socks := strings.Split(strings.TrimSpace(line), " ")
	if err != nil {
		panic(err)
	}

	return num1, &socks

}

package main

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

func main() {
	fmt.Println(solveQuestion(os.Stdin))
}

func solveQuestion(in io.Reader) int {
	_, socks := input(in)
	socksOut := 0
	maxSocks := 0
	isSockOut := make(map[string]bool)

	for _, sock := range *socks {
		if isSockOut[sock] {
			// If this is true
			if maxSocks < socksOut {
				maxSocks = socksOut
			}
			socksOut -= 2
			delete(isSockOut, sock)

		} else {
			isSockOut[sock] = true
		}
		socksOut += 1

	}
	return maxSocks
}

func input(in io.Reader) (int, *[]string) {
	reader := bufio.NewReader(in)

	line, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}
	num1, err := strconv.Atoi(strings.TrimSpace(line))
	if err != nil {
		panic(err)
	}
	line, err = reader.ReadString('\n')
	if err == io.EOF {
		err = nil
	}
	if err != nil {
		panic(err)
	}
	socks := strings.Split(strings.TrimSpace(line), " ")
	if err != nil {
		panic(err)
	}

	return num1, &socks

}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
	"math/big"
)

func main() {
	fmt.Println(solveQuestion(os.Stdin))
}

func solveQuestion(in io.Reader) int {
	_, socks := input(in)
	socksOut := 0
	maxSocks := 0
	isSockOut := Empty()

	for _, sock := range *socks {
		i, err := strconv.Atoi(sock)
		if err != nil {
			panic(err)
		}
		if isSockOut.Test(uint(i)) {
			// If this is true
			if maxSocks < socksOut {
				maxSocks = socksOut
			}
			socksOut -= 2

		} else {
			isSockOut.Set(uint(i))
		}
		socksOut += 1

	}
	return maxSocks
}

func input(in io.Reader) (int, *[]string) {
	reader := bufio.NewReader(in)

	line, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}
	num1, err := strconv.Atoi(strings.TrimSpace(line))
	if err != nil {
		panic(err)
	}
	line, err = reader.ReadString('\n')
	if err == io.EOF {
		err = nil
	}
	if err != nil {
		panic(err)
	}
	socks := strings.Split(strings.TrimSpace(line), " ")
	if err != nil {
		panic(err)
	}

	return num1, &socks

}

type BitSet struct {
	bits big.Int
}

func (b *BitSet) Set(bit uint) *BitSet {
	b.bits.SetBit(&b.bits, int(bit), 1)
	return b
}

func (b *BitSet) Test(bit uint) bool {
	return b.bits.Bit(int(bit)) == 1
}

func Empty() *BitSet {
	return new(BitSet)
}

func (b BitSet) String() string {
	return fmt.Sprintf("%b", &b.bits)
}

package main

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

type fastReader struct {
	data  []byte
	cur   int
	space []byte
}

func NewFastReader(rd io.Reader) *fastReader {
	b, err := ioutil.ReadAll(rd)
	if err != nil {
		panic(err)
	}
	fr := &fastReader{
		data: append(b, byte(0)),
		cur: 0,
		space: []byte(" \n\t\r"),
	}
	return fr
}

func (fr *fastReader) isSpace(b byte) bool {
	for _, d := range fr.space {
		if b == d {
			return true
		}
	}
	return false
}

func (fr *fastReader) asInt(b byte) int64 {
	return int64(b) - int64('0')
}

func (fr *fastReader) read() (b byte) {
	b = fr.data[fr.cur]
	fr.cur++
	return
}

func (fr *fastReader) ReadNoneSpace() byte {
	b := fr.read()
	for fr.isSpace(b) {
		b = fr.read()
	}
	return b
}

func (fr *fastReader) ReadString() string {
	bs := make([]byte, 10)
	b := fr.read()
	if !fr.isSpace(b) {
		bs = append(bs, b)
	}
	return string(bs)
}

func (fr *fastReader) getSign(b byte) (sign int64, bRet byte) {
	if b == '-' {
		sign = -1
		bRet = fr.read()
	} else {
		sign = 1
		if b == '+' {
			bRet = fr.read()
		} else {
			bRet = b
		}
	}
	return
}

func (fr *fastReader) ReadInt() int64 {
	b := fr.ReadNoneSpace()
	sign, b := fr.getSign(b)
	ret := int64(0)
	for !fr.isSpace(b) {
		ret *= 10
		ret += fr.asInt(b)
		b = fr.read()
	}
	return ret * sign
}

func (fr *fastReader) ReaderFloat() float64 {
	b := fr.ReadNoneSpace()
	sign, b := fr.getSign(b)
	ret := float64(0.0)
	for !fr.isSpace(b) && b != '.' {
		if b == 'e' || b == 'E' {
			return ret * math.Pow10(int(fr.ReadInt()))
		}
		ret *= 10
		ret += float64(fr.asInt(b))
		b = fr.read()
	}
	if b == '.' {
		b = fr.read()
		fra := float64(1.0)
		for !fr.isSpace(b) {
			if b == 'e' || b == 'E' {
				return ret * math.Pow10(int(fr.ReadInt()))
			}
			fra /= float64(10)
			ret += float64(fr.asInt(b)) * fra
			b = fr.read()
		}
	}
	return ret * float64(sign)
}

func main() {
	reader := NewFastReader(os.Stdin)

	n := reader.ReadInt()

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * int(n); i++ {
		x := reader.ReadInt()

		if found[x] {
			cur--
		} else {
			cur++
			found[x] = true
		}

		if cur > ans {
			ans = cur
		}
	}

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

package main

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

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

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

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int

		for {
			_, err := fmt.Fscanf(reader, "%d", &x)
			if err == nil {
				break
			}
		}

		if found[x] {
			cur--
		} else {
			cur++
			found[x] = true
		}

		if cur > ans {
			ans = cur
		}
	}

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

package main

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

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

	table := make(map[int]bool)
	table_count := 0
	max_table_count := 0

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < 2*n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}

		if _, ok := table[a]; ok {
			delete(table, a)
			table_count -= 1
		} else {
			table[a] = true
			table_count += 1
			if table_count > max_table_count {
				max_table_count = table_count
			}
		}
	}

	fmt.Println(max_table_count)
}

package main

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

func main() {
	fmt.Println(solveQuestion(os.Stdin))
}

func solveQuestion(in io.Reader) int {
	_, socks := input(in)
	socksOut := 0
	maxSocks := 0
	isSockOut := make(map[string]bool)

	for _, sock := range *socks {
		if isSockOut[sock] {
			// If this is true
			if maxSocks < socksOut {
				maxSocks = socksOut
			}
			socksOut--
		} else {
			isSockOut[sock] = true
			socksOut++
		}
	}
	return maxSocks
}

func input(in io.Reader) (int, *[]string) {
	reader := bufio.NewReader(in)

	line, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}
	num1, err := strconv.Atoi(strings.TrimSpace(line))
	if err != nil {
		panic(err)
	}
	line, err = reader.ReadString('\n')
	if err == io.EOF {
		err = nil
	}
	if err != nil {
		panic(err)
	}
	socks := strings.Split(line, " ")
	if err != nil {
		panic(err)
	}

	return num1, &socks

}

package main

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

func main() {
	fmt.Println(solveQuestion(os.Stdin))
}

func solveQuestion(in io.Reader) int {
	_, socks := input(in)
	socksOut := 0
	maxSocks := 0
	isSockOut := make(map[string]bool)

	fmt.Println(*socks)
	for _, sock := range *socks {
		if isSockOut[sock] {
			// If this is true
			if maxSocks < socksOut {
				maxSocks = socksOut
			}
			socksOut -= 2

		}
		socksOut += 1
		isSockOut[sock] = true

	}
	return maxSocks
}

func input(in io.Reader) (int, *[]string) {
	reader := bufio.NewReader(in)

	line, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}
	num1, err := strconv.Atoi(strings.TrimSpace(line))
	if err != nil {
		panic(err)
	}
	line, err = reader.ReadString('\n')
	if err == io.EOF {
		err = nil
	}
	if err != nil {
		panic(err)
	}
	socks := strings.Split(strings.TrimSpace(line), " ")
	if err != nil {
		panic(err)
	}

	return num1, &socks

}

package main

import (
	"fmt"
)

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

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

package main

import (
	"fmt"
)

func notWorking() {
	var n int
	fmt.Scanf("%d", &n)

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	fmt.Printf("n=%d\n", n)

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)

		fmt.Printf("x=%d\n", x)
		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf(">>> found[%d]=%t\n", x, found[x])
		if found[x] {
			fmt.Printf(">>>1 pre >>> cur=%d\n", cur)
			cur--
			fmt.Printf(">>>1 aft >>> cur=%d\n", cur)
		} else {
			fmt.Printf(">>>2 pre >>> cur=%d\n", cur)
			cur++
			fmt.Printf(">>>2 aft >>> cur=%d\n", cur)
			found[x] = true
			fmt.Printf(">>>2 found[%d]=%t\n", x, found[x])
		}

		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf("cur=%d, ans=%d\n", cur, ans)

		if cur > ans {
			ans = cur
		}

		fmt.Printf("ans=%d\n", ans)
	}

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

package main

import (
	"fmt"
)

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

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

package main

import (
	"fmt"
)

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

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		if exist {
			delete(found, x)
		} else {
			found[x] = true
		}

		if len(found) > ans {
			ans = len(found)
		}
	}

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

package main

import (
	"fmt"
)

func notWorking() {
	var n int
	fmt.Scanf("%d", &n)

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	fmt.Printf("n=%d\n", n)

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int

		for {
			nread, err := fmt.Scanf("%d", &x)
			fmt.Printf("nread=%d, err=%v\n", nread, err)
			if err == nil {
				break
			}
		}

		fmt.Printf("x=%d\n", x)
		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf(">>> found[%d]=%t\n", x, found[x])
		if found[x] {
			fmt.Printf(">>>1 pre >>> cur=%d\n", cur)
			cur--
			fmt.Printf(">>>1 aft >>> cur=%d\n", cur)
		} else {
			fmt.Printf(">>>2 pre >>> cur=%d\n", cur)
			cur++
			fmt.Printf(">>>2 aft >>> cur=%d\n", cur)
			found[x] = true
			fmt.Printf(">>>2 found[%d]=%t\n", x, found[x])
		}

		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf("cur=%d, ans=%d\n", cur, ans)

		if cur > ans {
			ans = cur
		}

		fmt.Printf("ans=%d\n", ans)
	}

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

package main

import (
	"fmt"
)

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

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		if exist {
			delete(found, x)
		} else {
			found[x] = true
		}

		if len(found) > ans {
			ans = len(found)
		}
	}

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

package main

import (
	"fmt"
)

func notWorking() {
	var n int
	fmt.Scanf("%d", &n)

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	fmt.Printf("n=%d\n", n)

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		nread, err := fmt.Scanf("%d", &x)
		fmt.Printf("nread=%d, err=%v\n", nread, err)

		fmt.Printf("x=%d\n", x)
		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf(">>> found[%d]=%t\n", x, found[x])
		if found[x] {
			fmt.Printf(">>>1 pre >>> cur=%d\n", cur)
			cur--
			fmt.Printf(">>>1 aft >>> cur=%d\n", cur)
		} else {
			fmt.Printf(">>>2 pre >>> cur=%d\n", cur)
			cur++
			fmt.Printf(">>>2 aft >>> cur=%d\n", cur)
			found[x] = true
			fmt.Printf(">>>2 found[%d]=%t\n", x, found[x])
		}

		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf("cur=%d, ans=%d\n", cur, ans)

		if cur > ans {
			ans = cur
		}

		fmt.Printf("ans=%d\n", ans)
	}

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

package main

import (
	"fmt"
)

func notWorking() {
	var n int
	fmt.Scanf("%d", &n)

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)

		if found[x] {
			cur--
		} else {
			cur++
			found[x] = true
		}

		if cur > ans {
			ans = cur
		}
	}

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

package main

import (
	"fmt"
)

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

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	fmt.Printf("n=%d\n", n)

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		nread, err := fmt.Scanf("%d", &x)
		fmt.Printf("nread=%d, err=%v\n", nread, err)

		fmt.Printf("x=%d\n", x)
		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf(">>> found[%d]=%t\n", x, found[x])
		if found[x] {
			fmt.Printf(">>>1 pre >>> cur=%d\n", cur)
			cur--
			fmt.Printf(">>>1 aft >>> cur=%d\n", cur)
		} else {
			fmt.Printf(">>>2 pre >>> cur=%d\n", cur)
			cur++
			fmt.Printf(">>>2 aft >>> cur=%d\n", cur)
			found[x] = true
			fmt.Printf(">>>2 found[%d]=%t\n", x, found[x])
		}

		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf("cur=%d, ans=%d\n", cur, ans)

		if cur > ans {
			ans = cur
		}

		fmt.Printf("ans=%d\n", ans)
	}

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

package main

import (
	"fmt"
)

func notWorking() {
	var n int
	fmt.Scanf("%d", &n)

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	fmt.Printf("n=%d\n", n)

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", x)

		fmt.Printf("x=%d\n", x)
		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf(">>> found[%d]=%t\n", x, found[x])
		if found[x] {
			fmt.Printf(">>>1 pre >>> cur=%d\n", cur)
			cur--
			fmt.Printf(">>>1 aft >>> cur=%d\n", cur)
		} else {
			fmt.Printf(">>>2 pre >>> cur=%d\n", cur)
			cur++
			fmt.Printf(">>>2 aft >>> cur=%d\n", cur)
			found[x] = true
			fmt.Printf(">>>2 found[%d]=%t\n", x, found[x])
		}

		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf("cur=%d, ans=%d\n", cur, ans)

		if cur > ans {
			ans = cur
		}

		fmt.Printf("ans=%d\n", ans)
	}

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

package main

import (
	"fmt"
)

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

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	var x int
	for i := 0; i < 2 * n; i++ {
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

package main

import (
	"fmt"
)

func notWorking() {
	var n int
	fmt.Scanf("%d", &n)

	fmt.Printf("n=%d\n", n)

	var found map[int]bool = make(map[int]bool)

	var ans int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		_, exist := found[x]

		fmt.Printf("x=%d, exist=%t\n", n, exist)

		if exist {
			fmt.Printf("delete\n")
			delete(found, x)
		} else {
			fmt.Printf("set true\n")
			found[x] = true
		}

		for k, v := range found {
			fmt.Printf("key[%s] value[%s]\n", k, v)
		}

		fmt.Printf("len(found)=%d, ans=%d\n", len(found), ans)
		if len(found) > ans {
			ans = len(found)
			fmt.Printf("update ans=%d\n", ans)
		}
	}

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

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

	fmt.Printf("n=%d\n", n)

	var found []bool = make([]bool, n + 1)
	var ans int = 0
	var cur int = 0
	for i := 0; i < 2 * n; i++ {
		var x int
		fmt.Scanf("%d", &x)

		fmt.Printf("x=%d\n", x)
		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		if found[x] {
			cur--
		} else {
			cur++
			found[x] = true
		}

		for j := 0; j <= n; j++ {
			fmt.Printf("found[%d]=%t\n", j, found[j])
		}

		fmt.Printf("cur=%d, ans=%d\n", cur, ans)

		if cur > ans {
			ans = cur
		}

		fmt.Printf("ans=%d\n", ans)
	}

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


This problem is a simplified version of D2, but it has significant differences, so read the whole statement.Polycarp has an array of $$$n$$$ ($$$n$$$ is even) integers $$$a_1, a_2, \dots, a_n$$$. Polycarp conceived of a positive integer $$$k$$$. After that, Polycarp began performing the following operations on the array: take an index $$$i$$$ ($$$1 \le i \le n$$$) and reduce the number $$$a_i$$$ by $$$k$$$.After Polycarp performed some (possibly zero) number of such operations, it turned out that all numbers in the array became the same. Find the maximum $$$k$$$ at which such a situation is possible, or print $$$-1$$$ if such a number can be arbitrarily large.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains an even integer $$$n$$$ ($$$4 \le n \le 40$$$) ($$$n$$$ is even). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$$$ ($$$-10^6 \le a_i \le 10^6$$$). It is guaranteed that the sum of all $$$n$$$ specified in the given test cases does not exceed $$$100$$$.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 1$$$) — the maximum possible number that Polycarp used in operations on the array, or $$$-1$$$, if such a number can be arbitrarily large.

package main

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

//problem D1

type problem struct {
	nums []int
	data map[int]bool
}

func (p *problem) maximum() int {
	n := len(p.nums)
	p.data = make(map[int]bool, n*n)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sub := p.nums[i] - p.nums[j]
			if sub == 0 {
				continue
			}
			if sub < 0 {
				sub = 0 - sub
			}
			if _, ok := p.data[sub]; !ok {
				p.data[sub] = true
			}
		}
	}

	if len(p.data) == 0 {
		return -1
	}

	subs := make([]int, 0, len(p.data))
	for sub := range p.data {
		subs = append(subs, sub)
	}

	gcd := subs[0]

	for i := 1; gcd != 1 && i < len(subs); i++ {
		gcd = GCD(gcd, subs[i])
	}

	return gcd
}

func GCD(x, y int) int {
	if x > y {
		x, y = y, x
	}

	for x != 0 {
		x, y = y%x, x
	}
	return y
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	var t, n int
	var p problem

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)
		p.nums = make([]int, n)

		for i := 0; i < n; i++ {
			if i < n-1 {
				fmt.Fscanf(reader, "%d ", &p.nums[i])
			} else {
				fmt.Fscanf(reader, "%d\n", &p.nums[i])
			}
		}

		fmt.Printf("%d\n", p.maximum())
	}
}

package main

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

func main() {
	//输入输出部分
	cnt := 0
	fmt.Fscan(os.Stdin, &cnt)
	arr := make([][]int, cnt)
	ans := []int{}
	for i := 0; i < cnt; i++ {
		n := 0
		fmt.Fscan(os.Stdin, &n)
		arr[i] = make([]int, n)
		for j := 0; j < n; j++ {
			tmp := 0
			fmt.Fscan(os.Stdin, &tmp)
			arr[i][j] = tmp
		}
	}

	//算法部分
	for _, sl := range arr {
		//如果4个数相等则return -1
		//以最小的数为基准然后求所有和最小数差的最大公约数
		tmp := []int{}
		sort.Ints(sl)
		min := sl[0]
		for _, v := range sl {
			if min != v {
				tmp = append(tmp, v-min)
			}
		}
		if len(tmp) == 0 {
			ans = append(ans, -1)
			continue
		}
		for res := tmp[0]; res >= 1; res-- {
			flag := true
			for _, v := range tmp {
				if v % res != 0 {
					flag = false
				}
			}
			if flag {
				ans = append(ans, res)
				break
			}
		}
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

package main

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

func gcd(x int, y int) int {
  if x < 0 {
    x = -x
  }
  if y < 0 {
    y = -y
  }
  if x < y {
    return gcd(y, x)
  }
  if y == 0 {
    return x
  }
  return gcd(y, x%y)
}

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

  var t int
  fmt.Fscan(reader, &t)
  for ; t > 0; t-- {
    var n int
    fmt.Fscan(reader, &n)
    arr := make([]int, n)
    for i := 0; i < n; i++ {
      fmt.Fscan(reader, &arr[i])
    }
    ans := 0
    for i := 0; i < n-1; i++ {
      ans = gcd(ans, arr[i+1]-arr[i])
    }
    if ans == 0 {
      ans = -1
    }
    fmt.Fprint(writer, ans, "\n")
  }
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n, h int

	_, _ = fmt.Fscan(r, &t)

	for ; t > 0; t-- {
		_, _ = fmt.Fscan(r, &n)
		var a []int

		result := -1
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(r, &h)
			a = append(a, h)
			if i > 0 && a[i] != a[0] {
				result = 0
			}
		}

		if result == -1 {
			fmt.Println(result)
			continue
		}

		Loop: for i := 2000000; i >= 1; i-- {
			mi:= a[0] % i
			if mi < 0 {
				mi += i
			}

			for j := 1; j < n; j++ {
				mj := a[j] % i
				if mj < 0 {
					mj += i
				}

				if mj != mi {
					continue Loop
				}
			}

			fmt.Println(i)
			break
		}
	}
}

package main

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

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

	T int

	n int
	a []int
)

func unique(a []int) {
	b := a[:1]
	for _, i := range a {
		if i != b[len(b)-1] {
			b = append(b, i)
		}
	}
}

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

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n)
		a = make([]int, n)
		for i := range a {
			fmt.Fscan(rr, &a[i])
		}
		sort.Ints(a)
		if a[0] == a[len(a)-1] {
			fmt.Fprintln(ww, -1)
			continue
		}
		unique(a)
		g := a[1] - a[0]

		for i := 2; i < len(a); i++ {
			g = gcd(g, a[i] - a[i - 1])
		}
		fmt.Fprintln(ww, g)
	}
	_ = ww.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1593D1(in io.Reader, out io.Writer) {
	var T, n, v0, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &v0)
		g := 0
		for ; n > 1; n-- {
			Fscan(in, &v)
			g = gcd(g, abs(v-v0))
		}
		if g == 0 {
			g = -1
		}
		Fprintln(out, g)
	}
}

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

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

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

package main

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

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

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([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Ints(arr)
		k := arr[n-1] - arr[0]
		if k == 0 {
			fmt.Fprintln(out, -1)
		} else {
			for i := n - 2; i >= 1; i-- {
				if arr[i] == arr[0] || k == 1 {
					break
				}

				k = gcd(arr[i]-arr[0], k)
			}

			fmt.Fprintln(out, k)
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

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

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

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

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

		ARR := make([]int, n)

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

		sort.Ints(ARR)
		Dif := make([]int, 0)
		Dif = append(Dif, ARR[0])

		for i := 1; i < n; i++ {
			if ARR[i] != ARR[i-1] {
				Dif = append(Dif, ARR[i])
			}
		}

		if len(Dif) == 1 {
			fmt.Println(-1)
		} else {
			q := len(Dif)
			begin := int64(Dif[1] - Dif[0])
			for i := 2; i < q; i++ {
				sec := Dif[i] - Dif[i-1]
				begin = GCD(int64(begin), int64(sec))
			}
			fmt.Println(begin)
		}

	}

}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	// writer  = bufio.NewWriter(os.Stdout)
	t, n int
	x    []int
)

func lcd(x, y int) int {
	if x%y == 0 {
		return y
	}
	return lcd(y, x%y)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		x = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &x[i])
		}
		sort.Ints(x)
		if x[0] == x[n-1] {
			fmt.Println(-1)
			continue
		}
		var y []int
		for i := 1; i < n; i++ {
			if x[i] > x[0] {
				y = append(y, x[i]-x[0])
			}
		}
		k := y[0]
		for i := 1; i < len(y); i++ {
			k = lcd(k, y[i])
		}
		fmt.Println(k)
	}
}

package main

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

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

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

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

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

		diff := false
		for i := 0; i < n; i++ {
			if arr[i] != arr[0] {
				diff = true
			}
		}

		if !diff {
			fmt.Println(-1)
			continue
		}

		x := 0
		for i := 0; i < len(arr); i++ {
			res := 0
			for j := 0; j < len(arr); j++ {
				d := abs(arr[i] - arr[j])
				res = gcd(d, res)
			}
			if res > x {
				x = res
			}
		}

		fmt.Println(x)
	}
}

package main

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

var N int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &N)

		a = make([]int, N)

		for j := 0; j < N; j++ {
			fmt.Fscan(r, &a[j])
		}

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int64 {
	var diff []int

	for  i := 1; i < N; i++ {
		d := abs(a[i] - a[i - 1])

		diff = append(diff, d)
	}

	allZero := true
	for i := 0; i < len(diff); i++ {
		if diff[i] == 0 {
			continue
		}
		allZero = false
		break
	}

	if allZero {
		return -1
	}

	cur := GCD(diff[1], diff[0])

	for j := 2; j < len(diff); j++ {
		cur = GCD(cur, diff[j])
	}

	return int64(cur)
}

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

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

package main

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

//problem D1

type problem struct {
	nums []int
	data map[int]bool
}

func (p *problem) maximum() int {
	n := len(p.nums)
	p.data = make(map[int]bool, n*n)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sub := p.nums[i] - p.nums[j]
			if sub == 0 {
				continue
			}
			if sub < 0 {
				sub = 0 - sub
			}
			if _, ok := p.data[sub]; !ok {
				p.data[sub] = true
			}
		}
	}

	if len(p.data) == 0 {
		return -1
	}

	subs := make([]int, 0, len(p.data))
	for sub := range p.data {
		subs = append(subs, sub)
	}

	gcd := subs[0]

	for i := 1; i < len(subs); i++ {
		gcd = GCD(gcd, subs[i])
	}

	return gcd
}

func GCD(x, y int) int {
	if x > y {
		x, y = y, x
	}

	for x != 0 {
		x, y = x%y, x
	}
	return y
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	var t, n int
	var p problem

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)
		p.nums = make([]int, n)

		for i := 0; i < n; i++ {
			if i < n-1 {
				fmt.Fscanf(reader, "%d ", &p.nums[i])
			} else {
				fmt.Fscanf(reader, "%d\n", &p.nums[i])
			}
		}

		fmt.Printf("%d\n", p.maximum())
	}
}

package main

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

//problem D

type problem struct {
	nums []int
	data map[int]bool
}

func (p *problem) maximum() int {
	n := len(p.nums)
	p.data = make(map[int]bool, n*n)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sub := p.nums[i] - p.nums[j]
			if sub == 0 {
				continue
			}
			if sub < 0 {
				sub = 0 - sub
			}
			if _, ok := p.data[sub]; !ok {
				p.data[sub] = true
			}
		}
	}

	if len(p.data) == 0 {
		return -1
	}

	subs := make([]int, 0, len(p.data))
	for sub := range p.data {
		subs = append(subs, sub)
	}

	gcd := subs[0]

	for i := 1; i < len(subs); i++ {
		gcd = GCD(gcd, subs[i])
	}

	return gcd
}

func GCD(x, y int) int {
	if x > y {
		x, y = y, x
	}

	for x != 0 {
		x, y = x%y, x
	}
	return y
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	var t, n int
	var p problem

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)
		p.nums = make([]int, n)

		for i := 0; i < n; i++ {
			if i < n {
				fmt.Fscanf(reader, "%d ", &p.nums[i])
			} else {
				fmt.Fscanf(reader, "%d\n", &p.nums[i])
			}
		}

		fmt.Printf("%d\n", p.maximum())
	}
}

package main

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

//problem D1

type problem struct {
	nums []int
	data map[int]bool
}

func (p *problem) maximum() int {
	n := len(p.nums)
	p.data = make(map[int]bool, n*n)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sub := p.nums[i] - p.nums[j]
			if sub == 0 {
				continue
			}
			if sub < 0 {
				sub = 0 - sub
			}
			if _, ok := p.data[sub]; !ok {
				p.data[sub] = true
			}
		}
	}

	if len(p.data) == 0 {
		return -1
	}

	subs := make([]int, 0, len(p.data))
	for sub := range p.data {
		subs = append(subs, sub)
	}

	gcd := subs[0]

	for i := 1; i < len(subs); i++ {
		gcd = GCD(gcd, subs[i])
	}

	return gcd
}

func GCD(x, y int) int {
	if x > y {
		x, y = y, x
	}

	for x != 0 {
		x, y = x%y, x
	}
	return y
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	var t, n int
	var p problem

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)
		p.nums = make([]int, n)

		for i := 0; i < n; i++ {
			if i < n {
				fmt.Fscanf(reader, "%d ", &p.nums[i])
			} else {
				fmt.Fscanf(reader, "%d\n", &p.nums[i])
			}
		}

		fmt.Printf("%d\n", p.maximum())
	}
}

package main

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

func main() {
	//输入输出部分
	cnt := 0
	fmt.Fscan(os.Stdin, &cnt)
	arr := make([][]int, cnt)
	for i := 0; i < cnt; i++ {
		n := 0
		fmt.Fscan(os.Stdin, &n)
		arr[i] = make([]int, n)
		for j := 0; j < n; j++ {
			tmp := 0
			fmt.Fscan(os.Stdin, &tmp)
			arr[i][j] = tmp
		}
	}
	//算法部分
	for _, sl := range arr {
		//如果4个数相等则return -1
		//以最小的数为基准然后求所有和最小数差的最大公约数
		tmp := []int{}
		sort.Ints(sl)
		min := sl[0]
		for _, v := range sl {
			tmp = append(tmp, v-min)
		}
		if tmp[len(tmp)-1] == 0 {
			fmt.Println(-1)
		} else {
			for res := tmp[0]; res >= 1; res-- {
				flag := true
				for _, v := range tmp {
					if v % res != 0 {
						flag = false
					}
				}
				if flag {
					fmt.Println(res)
					break
				}
			}
		}
	}
}

package main

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

func gcd(x int, y int) int {
  if x < 0 {
    x = -x
  }
  if y < 0 {
    y = -y
  }
  if x < y {
    return gcd(y, x)
  }
  if y == 0 {
    return x
  }
  return gcd(y, x%y)
}

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

  var t int
  fmt.Fscan(reader, &t)
  for ; t > 0; t-- {
    var n int
    fmt.Fscan(reader, &n)
    arr := make([]int, n)
    for i := 0; i < n; i++ {
      fmt.Fscan(reader, &arr[i])
    }
    ans := 0
    for i := 0; i < n-1; i++ {
      ans = gcd(ans, arr[i+1]-arr[i])
    }
    fmt.Fprint(writer, ans, "\n")
  }
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n, h int

	_, _ = fmt.Fscan(r, &t)

	for ; t > 0; t-- {
		_, _ = fmt.Fscan(r, &n)
		var a []int

		result := -1
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(r, &h)
			a = append(a, h)
			if i > 0 && a[i] != a[0] {
				result = 0
			}
		}

		if result == -1 {
			fmt.Println(result)
			continue
		}

		Loop: for i := 1000000; i >= 1; i-- {
			mi:= a[0] % i
			if mi < 0 {
				mi += i
			}

			for j := 1; j < n; j++ {
				mj := a[j] % i
				if mj < 0 {
					mj += i
				}

				if mj != mi {
					continue Loop
				}
			}

			fmt.Println(i)
			break
		}
	}
}

package main

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

const Inf = 1000

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

	T int

	n int
	a []int
)

func main() {
	fmt.Fscan(rr, &T)
	for ; T > 0; T-- {
		fmt.Fscan(rr, &n)
		a = make([]int, n)
		for i := range a {
			fmt.Fscan(rr, &a[i])
		}
		min, max := a[0], a[0]
		for _, i := range a {
			if min > i {
				min = i
			}
			if max < i {
				max = i
			}
		}
		min = max - min + 1
		ans := 1
		for i := 2; i <= min; i++ {
			mod := ((a[0] % i) + i) % i
			flag := true
			for _, j := range a {
				if ((j % i) + i) % i != mod {
					flag = false
					break
				}
			}
			if flag {
				ans = i
			}
		}
		fmt.Fprintln(ww, ans)
	}
	_ = ww.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1593D1(in io.Reader, out io.Writer) {
	var T, n, v0, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &v0)
		g := 0
		for ; n > 1; n-- {
			Fscan(in, &v)
			g = gcd(g, abs(v-v0))
		}
		Fprintln(out, g)
	}
}

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

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

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


Petya has a string of length n consisting of small and large English letters and digits.He performs m operations. Each operation is described with two integers l and r and a character c: Petya removes from the string all characters c on positions between l and r, inclusive. It's obvious that the length of the string remains the same or decreases after each operation.Find how the string will look like after Petya performs all m operations.

The first string contains two integers n and m (1 ≤ n, m ≤ 2·105) — the length of the string and the number of operations. The second line contains the string of length n, consisting of small and large English letters and digits. Positions in the string are enumerated from 1. Each of the next m lines contains two integers l and r (1 ≤ l ≤ r), followed by a character c, which is a small or large English letter or a digit. This line describes one operation. It is guaranteed that r doesn't exceed the length of the string s before current operation.

Print the string Petya will obtain after performing all m operations. If the strings becomes empty after all operations, print an empty line.

9 5
aAAaBBccD
1 4 a
5 6 c
2 3 B
4 4 D
2 3 A

NoteIn the first example during the first operation both letters 'a' are removed, so the string becomes "bc". During the second operation the letter 'c' (on the second position) is removed, and the string becomes "b".In the second example during the first operation Petya removes '0' from the second position. After that the string becomes "Az". During the second operations the string doesn't change.

package main

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

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

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

type Node struct {
	position            int
	c                   byte
	left, right, parent *Node
}

type SplayTree struct {
	root *Node
	bit  *BIT
}

type BIT struct {
	bits []int
	n    int
}

func NewBIT(n int) *BIT {
	return &BIT{
		bits: make([]int, n+2),
		n:    n + 2,
	}
}

func (p *BIT) update(x int) {
	for ; x < p.n; x += x & (-x) {
		p.bits[x]++
	}
}

func (p *BIT) query(x int) (res int) {
	for ; x > 0; x -= x & (-x) {
		res += p.bits[x]
	}

	return
}

func NewSplayTree(n int) *SplayTree {
	return &SplayTree{
		root: nil,
		bit:  NewBIT(n),
	}
}

func (p *SplayTree) rotateLeft(node *Node) {
	parentNode := node.parent
	parentNode.right = node.left
	if node.left != nil {
		node.left.parent = parentNode
	}

	node.left = parentNode
	if parentNode.parent != nil {
		if parentNode.parent.left == parentNode {
			parentNode.parent.left = node
		} else {
			parentNode.parent.right = node
		}
	}

	parentNode.parent, node.parent = node, parentNode.parent
}

func (p *SplayTree) rotateRight(node *Node) {
	parentNode := node.parent
	parentNode.left = node.right
	if node.right != nil {
		node.right.parent = parentNode
	}

	node.right = parentNode
	if parentNode.parent != nil {
		if parentNode.parent.left == parentNode {
			parentNode.parent.left = node
		} else {
			parentNode.parent.right = node
		}
	}

	parentNode.parent, node.parent = node, parentNode.parent
}

func (p *SplayTree) splay(node *Node) {
	for node.parent != nil {
		parentNode := node.parent

		if parentNode.parent == nil { // zig
			if parentNode.left == node {
				p.rotateRight(node)
			} else {
				p.rotateLeft(node)
			}
		} else if parentNode.parent.left == parentNode && parentNode.left == node { // zig-zig
			p.rotateRight(node.parent)
			p.rotateRight(node)
		} else if parentNode.parent.right == parentNode && parentNode.right == node {
			p.rotateLeft(node.parent)
			p.rotateLeft(node)
		} else if parentNode.parent.left == parentNode && parentNode.right == node {
			p.rotateLeft(node)
			p.rotateRight(node)
		} else {
			p.rotateRight(node)
			p.rotateLeft(node)
		}
	}
	p.root = node
}

func (p *SplayTree) insert(c byte, position int) {
	if p.root == nil {
		p.root = &Node{c: c, position: position}
		return
	}

	newNode := &Node{c: c, position: position}
	for node := p.root; node != nil; {
		if less(c, position, node.c, node.position) {
			if node.left == nil {
				node.left = newNode
				newNode.parent = node
				break
			} else {
				node = node.left
			}
		} else if node.right == nil {
			node.right = newNode
			newNode.parent = node
			break
		} else {
			node = node.right
		}
	}

	p.splay(newNode)
}

func (p *SplayTree) searchHelper(position int, c byte) (nodeC byte, nodePoistion, realPosition int, isRightMost bool) {
	node := p.root
	for node != nil {
		nodeC, nodePoistion = node.c, node.position-p.bit.query(node.position)
		if c == nodeC && nodePoistion == position {
			break
		}

		if less(c, position, nodeC, nodePoistion) {
			if node.left == nil {
				break
			} else {
				node = node.left
			}
		} else if node.right == nil {
			break
		} else {
			node = node.right
		}
	}

	p.splay(node)
	return nodeC, nodePoistion, node.position, node.right == nil
}

func (p *SplayTree) removeOnRoot() {
	leftRoot, rightRoot := p.root.left, p.root.right
	p.root.left, p.root.right = nil, nil

	if leftRoot != nil {
		leftRoot.parent = nil
	}
	if rightRoot != nil {
		rightRoot.parent = nil
	}
	p.join(leftRoot, rightRoot)
}

func (p *SplayTree) join(nodeLeft *Node, nodeRight *Node) {
	if nodeLeft == nil {
		p.root = nodeRight
		return
	}

	if nodeRight == nil {
		p.root = nodeLeft
		return
	}

	rightMost := getRightMost(nodeLeft)
	p.splay(rightMost)

	rightMost.right, nodeRight.parent = nodeRight, rightMost
}

func (p *SplayTree) walk(node *Node, arr *[]*Node) {
	*arr = append(*arr, node)

	if node.left != nil {
		p.walk(node.left, arr)
	}
	if node.right != nil {
		p.walk(node.right, arr)
	}
}

func (p *SplayTree) printTree() {
	queue, first := []*Node{p.root}, 0
	fmt.Printf("%d ", p.root.position)
	for first < len(queue) {
		node := queue[first]
		first++

		if node.left != nil {
			queue = append(queue, node.left)
			fmt.Printf("%d ", node.left.position)
		} else {
			fmt.Print("NULL ")
		}

		if node.right != nil {
			queue = append(queue, node.right)
			fmt.Printf("%d ", node.right.position)
		} else {
			fmt.Print("NULL ")
		}
	}

	fmt.Println()
}

func (p *SplayTree) printCurrentString() string {
	if p.root == nil {
		return ""
	}

	arr := []*Node{}
	p.walk(p.root, &arr)
	res := make([]byte, len(arr))
	sort.Slice(arr, func(i, j int) bool {
		return arr[i].position < arr[j].position
	})

	for i, c := range arr {
		res[i] = c.c
	}

	return (string)(res)
}

func getRightMost(node *Node) *Node {
	for node.right != nil {
		node = node.right
	}

	return node
}

func less(c byte, position int, c1 byte, position2 int) bool {
	if c == c1 {
		return position < position2
	}

	return c < c1
}

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

	return b
}

func (p *SplayTree) doQuery(l, r int, c byte) {
	i, positions := l, []int{}
	for i <= r {
		nodeC, nodePoistion, realPosition, isRightMost := p.searchHelper(i, c)
		// fmt.Printf("%c %d %c %d\n", nodeC, nodePoistion, c, i)
		// if c == byte('t') {
		// 	c = byte('t')
		// }
		if nodeC > c || (nodeC == c && nodePoistion > r) {
			break
		}

		if nodeC != c || nodePoistion < i {
			i++
			if isRightMost {
				break
			}
			continue
		}

		// if c == byte('c') {
		// 	c = byte('c')
		// }

		// p.printTree()

		p.removeOnRoot()
		i = nodePoistion + 1
		// p.printTree()
		positions = append(positions, realPosition)
	}

	for _, position := range positions {
		p.bit.update(position)
	}
	// fmt.Println(p.printCurrentString())
}

func main() {
	// f, _ := os.Open("in")
	// reader = bufio.NewReader(f)
	// defer f.Close()
	defer writer.Flush()
	var (
		n, m int
		s    string
	)
	scanf("%d %d\n%s\n", &n, &m, &s)

	splayTree := NewSplayTree(n)
	for i, c := range s {
		splayTree.insert(byte(c), i+1)
	}

	var (
		l, r int
		c    byte
	)

	for i := 0; i < m; i++ {
		scanf("%d %d %c\n", &l, &r, &c)
		splayTree.doQuery(l, r, c)
	}

	printf("%s\n", splayTree.printCurrentString())
}

package main

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

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

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

type Node struct {
	value               int
	parent, left, right *Node
}

type SplayTree struct {
	root                  *Node
	zig, zig_zig, zig_zag int
}

func (p *SplayTree) splay(node *Node) {
	for node.parent != nil {
		parentNode := node.parent
		if parentNode.parent == nil {
			p.zig++

			if parentNode.left == node {
				p.rotateRight(node)
			} else {
				p.rotateLeft(node)
			}
		} else if parentNode.left == node && parentNode.parent.left == parentNode {
			p.zig_zig++
			p.rotateRight(parentNode)
			p.rotateRight(node)
		} else if parentNode.right == node && parentNode.parent.right == parentNode {
			p.zig_zig++
			p.rotateLeft(parentNode)
			p.rotateLeft(node)
		} else if parentNode.right == node && parentNode.parent.left == parentNode {
			p.zig_zag++
			p.rotateLeft(node)
			p.rotateRight(node)
		} else {
			p.zig_zag++
			p.rotateRight(node)
			p.rotateLeft(node)
		}
	}

	p.root = node
}

func (p *SplayTree) rotateRight(node *Node) {
	parentNode := node.parent
	parentNode.left = node.right

	if parentNode.parent != nil {
		if parentNode.parent.left == parentNode {
			parentNode.parent.left = node
		} else {
			parentNode.parent.right = node
		}
	}

	if node.right != nil {
		node.right.parent = parentNode
	}

	node.right = parentNode
	node.parent, parentNode.parent = parentNode.parent, node
}

func (p *SplayTree) rotateLeft(node *Node) {
	parentNode := node.parent
	parentNode.right = node.left
	if parentNode.parent != nil {
		if parentNode.parent.left == parentNode {
			parentNode.parent.left = node
		} else {
			parentNode.parent.right = node
		}
	}

	if node.left != nil {
		node.left.parent = parentNode
	}
	node.left = parentNode

	node.parent, parentNode.parent = parentNode.parent, node
}

// func (p *SplayTree) remove(x int) {
// 	if p.root == nil {
// 		return
// 	}

// 	node := p.removeHelper(p.root, x)
// 	if node.value != x {
// 		p.splay(node)
// 		return
// 	}

// 	parentNode := node.parent
// 	if node.left != nil {
// 		leftNode := getRightMost(node.left)
// 		node.value = leftNode.value
// 		if leftNode == node.left {
// 			node.left = nil
// 		} else {
// 			leftNode.right = nil
// 		}
// 	} else if node.right != nil {
// 		if parentNode == nil {
// 			p.root = node.right
// 		} else if parentNode.left == node {
// 			parentNode.left = node.right
// 		} else {
// 			parentNode.right = node.right
// 		}
// 		node.right.parent, node = parentNode, nil
// 	} else if parentNode == nil {
// 		p.root = nil
// 	}

// 	if parentNode != nil {
// 		p.splay(parentNode)
// 	}
// }

func (p *SplayTree) remove(x int) {
	node := p.searchHelper(p.root, x)
	p.splay(node)

	if node.value != x {
		return
	}

	p.join(node.left, node.right)
	if p.root != nil {
		p.root.parent = nil
	}
}

func (p *SplayTree) join(nodeLeft, nodeRight *Node) {
	if nodeLeft == nil {
		p.root = nodeRight
		return
	} else if nodeRight == nil {
		p.root = nodeLeft
		return
	}

	nodeLeft.parent, nodeRight.parent = nil, nil
	rightMost := getRightMost(nodeLeft)
	p.splay(rightMost)

	rightMost.right, nodeRight.parent = nodeRight, rightMost
}

func getRightMost(node *Node) *Node {
	for node.right != nil {
		node = node.right
	}

	return node
}

func (p *SplayTree) removeHelper(node *Node, x int) *Node {
	if node.value == x {
		return node
	}

	if node.value < x {
		if node.right == nil {
			return node
		}

		return p.removeHelper(node.right, x)
	}

	if node.left == nil {
		return node
	}

	return p.removeHelper(node.left, x)
}

func (p *SplayTree) insert(x int) {
	if p.root == nil {
		p.root = &Node{value: x}
		return
	}
	node := p.insertHelper(p.root, x)
	p.splay(node)
}

func (p *SplayTree) insertHelper(node *Node, x int) *Node {
	if node.value < x {
		if node.right == nil {
			node.right = &Node{parent: node, value: x}
			return node.right
		}
		return p.insertHelper(node.right, x)
	}

	if node.left == nil {
		node.left = &Node{parent: node, value: x}
		return node.left
	}

	return p.insertHelper(node.left, x)
}

func (p *SplayTree) search(x int) *Node {
	node := p.searchHelper(p.root, x)

	if node != nil {
		p.splay(node)
	}
	return node
}

func (p *SplayTree) searchHelper(node *Node, x int) *Node {
	if node.value == x {
		return node
	}

	if node.value > x {
		if node.left == nil {
			return node
		}
		return p.searchHelper(node.left, x)
	}

	if node.right == nil {
		return node
	}

	return p.searchHelper(node.right, x)
}

func (p *SplayTree) printBFS() {
	queue, first := []*Node{p.root}, 0
	printf("%d ", p.root.value)
	for first < len(queue) {
		node := queue[first]
		first++

		if node.left != nil {
			printf("%d ", node.left.value)
			queue = append(queue, node.left)
		} else {
			printf("NULL ")
		}

		if node.right != nil {
			printf("%d ", node.right.value)
			queue = append(queue, node.right)
		} else {
			printf("NULL ")
		}
	}
	printf("\n")
}

func walk(node *Node, position int, arr *[]int) {
	if position == 1 {
		*arr = append(*arr, node.value)
	}

	if node.left != nil {
		walk(node.left, position, arr)
	}

	if position == 2 {
		*arr = append(*arr, node.value)
	}

	if node.right != nil {
		walk(node.right, position, arr)
	}

	if position == 3 {
		*arr = append(*arr, node.value)
	}
}

func (p *SplayTree) printout(position int) {
	arr := []int{}
	if p.root != nil {
		walk(p.root, position, &arr)
	}

	if len(arr) > 0 {
		for i := 0; i < len(arr)-1; i++ {
			printf("%d ", arr[i])
		}
		printf("%d", arr[len(arr)-1])
	}

	printf("\n")
}

func main() {
	f, _ := os.Open("in")
	defer f.Close()
	reader = bufio.NewReader(f)
	var n int
	scanf("%d\n", &n)

	var (
		c   byte
		key int
	)
	splayTree := &SplayTree{}
	for i := 0; i < n; i++ {
		scanf("%c %d\n", &c, &key)
		switch c {
		case 'i':
			splayTree.insert(key)
			break
		case 'd':
			splayTree.remove(key)
			break
		default:
			splayTree.search(key)
			break
		}
	}

	for i := 1; i <= 3; i++ {
		splayTree.printout(i)
	}

	// splayTree.printBFS()
	printf("%d\n%d\n%d\n", splayTree.zig, splayTree.zig_zig, splayTree.zig_zag)
	writer.Flush()
}

package main

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

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

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

type Node struct {
	position            int
	c                   byte
	left, right, parent *Node
}

type SplayTree struct {
	root *Node
	bit  *BIT
}

type BIT struct {
	bits []int
	n    int
}

func NewBIT(n int) *BIT {
	return &BIT{
		bits: make([]int, n+2),
		n:    n + 2,
	}
}

func (p *BIT) update(x int) {
	for ; x < p.n; x += x & (-x) {
		p.bits[x]++
	}
}

func (p *BIT) query(x int) (res int) {
	for ; x > 0; x -= x & (-x) {
		res += p.bits[x]
	}

	return
}

func NewSplayTree(n int) *SplayTree {
	return &SplayTree{
		root: nil,
		bit:  NewBIT(n),
	}
}

func (p *SplayTree) rotateLeft(node *Node) {
	parentNode := node.parent
	parentNode.right = node.left
	if node.left != nil {
		node.left.parent = parentNode
	}

	node.left = parentNode
	if parentNode.parent != nil {
		if parentNode.parent.left == parentNode {
			parentNode.parent.left = node
		} else {
			parentNode.parent.right = node
		}
	}

	parentNode.parent, node.parent = node, parentNode.parent
}

func (p *SplayTree) rotateRight(node *Node) {
	parentNode := node.parent
	parentNode.left = node.right
	if node.right != nil {
		node.right.parent = parentNode
	}

	node.right = parentNode
	if parentNode.parent != nil {
		if parentNode.parent.left == parentNode {
			parentNode.parent.left = node
		} else {
			parentNode.parent.right = node
		}
	}

	parentNode.parent, node.parent = node, parentNode.parent
}

func (p *SplayTree) splay(node *Node) {
	for node.parent != nil {
		parentNode := node.parent

		if parentNode.parent == nil { // zig
			if parentNode.left == node {
				p.rotateRight(node)
			} else {
				p.rotateLeft(node)
			}
		} else if parentNode.parent.left == parentNode && parentNode.left == node { // zig-zig
			p.rotateRight(node.parent)
			p.rotateRight(node)
		} else if parentNode.parent.right == parentNode && parentNode.right == node {
			p.rotateLeft(node.parent)
			p.rotateLeft(node)
		} else if parentNode.parent.left == parentNode && parentNode.right == node {
			p.rotateLeft(node)
			p.rotateRight(node)
		} else {
			p.rotateRight(node)
			p.rotateLeft(node)
		}
	}
	p.root = node
}

func (p *SplayTree) insert(c byte, position int) {
	if p.root == nil {
		p.root = &Node{c: c, position: position}
		return
	}

	newNode := &Node{c: c, position: position}
	for node := p.root; node != nil; {
		if less(c, position, node.c, node.position) {
			if node.left == nil {
				node.left = newNode
				newNode.parent = node
				break
			} else {
				node = node.left
			}
		} else if node.right == nil {
			node.right = newNode
			newNode.parent = node
			break
		} else {
			node = node.right
		}
	}

	p.splay(newNode)
}

func (p *SplayTree) searchHelper(position int, c byte) (nodeC byte, nodePoistion, realPosition int) {
	node := p.root
	for node != nil {
		nodeC, nodePoistion = node.c, node.position-p.bit.query(node.position)
		if c == nodeC && nodePoistion == position {
			break
		}

		if less(c, position, nodeC, nodePoistion) {
			if node.left == nil {
				break
			} else {
				node = node.left
			}
		} else if node.right == nil {
			break
		} else {
			node = node.right
		}
	}

	p.splay(node)
	return nodeC, nodePoistion, node.position
}

func (p *SplayTree) removeOnRoot() {
	leftRoot, rightRoot := p.root.left, p.root.right
	p.root.left, p.root.right = nil, nil

	if leftRoot != nil {
		leftRoot.parent = nil
	}
	if rightRoot != nil {
		rightRoot.parent = nil
	}
	p.join(leftRoot, rightRoot)
}

func (p *SplayTree) join(nodeLeft *Node, nodeRight *Node) {
	if nodeLeft == nil {
		p.root = nodeRight
		return
	}

	if nodeRight == nil {
		p.root = nodeLeft
		return
	}

	rightMost := getRightMost(nodeLeft)
	p.splay(rightMost)

	rightMost.right, nodeRight.parent = nodeRight, rightMost
}

func (p *SplayTree) walk(node *Node, arr *[]*Node) {
	*arr = append(*arr, node)

	if node.left != nil {
		p.walk(node.left, arr)
	}
	if node.right != nil {
		p.walk(node.right, arr)
	}
}

func (p *SplayTree) printTree() {
	queue, first := []*Node{p.root}, 0
	fmt.Printf("%d ", p.root.position)
	for first < len(queue) {
		node := queue[first]
		first++

		if node.left != nil {
			queue = append(queue, node.left)
			fmt.Printf("%d ", node.left.position)
		} else {
			fmt.Print("NULL ")
		}

		if node.right != nil {
			queue = append(queue, node.right)
			fmt.Printf("%d ", node.right.position)
		} else {
			fmt.Print("NULL ")
		}
	}

	fmt.Println()
}

func (p *SplayTree) printCurrentString() string {
	if p.root == nil {
		return ""
	}

	arr := []*Node{}
	p.walk(p.root, &arr)
	res := make([]byte, len(arr))
	sort.Slice(arr, func(i, j int) bool {
		return arr[i].position < arr[j].position
	})

	for i, c := range arr {
		res[i] = c.c
	}

	return (string)(res)
}

func getRightMost(node *Node) *Node {
	for node.right != nil {
		node = node.right
	}

	return node
}

func less(c byte, position int, c1 byte, position2 int) bool {
	if c == c1 {
		return position < position2
	}

	return c < c1
}

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

	return b
}

func (p *SplayTree) doQuery(l, r int, c byte) {
	i, positions := l, []int{}
	for i <= r {
		nodeC, nodePoistion, realPosition := p.searchHelper(i, c)
		// fmt.Printf("%c %d %c %d\n", nodeC, nodePoistion, c, i)
		if nodeC > c || nodePoistion > r {
			break
		}

		if nodeC != c || nodePoistion < i {
			i++
			continue
		}

		// if c == byte('c') {
		// 	c = byte('c')
		// }

		// p.printTree()

		p.removeOnRoot()
		i = nodePoistion + 1
		// p.printTree()
		positions = append(positions, realPosition)
	}

	for _, position := range positions {
		p.bit.update(position)
	}
	// fmt.Println(p.printCurrentString())
}

func main() {
	// f, _ := os.Open("in")
	// reader = bufio.NewReader(f)
	// defer f.Close()
	defer writer.Flush()
	var (
		n, m int
		s    string
	)
	scanf("%d %d\n%s\n", &n, &m, &s)

	splayTree := NewSplayTree(n)
	for i, c := range s {
		splayTree.insert(byte(c), i+1)
	}

	var (
		l, r int
		c    byte
	)

	for i := 0; i < m; i++ {
		scanf("%d %d %c\n", &l, &r, &c)
		splayTree.doQuery(l, r, c)
	}

	printf("%s\n", splayTree.printCurrentString())
}


You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints:  The first team should consist of students with distinct skills (i.e. all skills in the first team are unique).  The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given):  $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same;  $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills;  $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills;  $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams;  $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.

NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a int
		fmt.Fscan(in, &n)
		d := make(map[int]int, n)
		max := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a)
			d[a] += 1
			if max == 0 {
				max = a
			}
			if d[a] > d[max] {
				max = a
			}
		}
		first := len(d) - 1
		if first < d[max] {
			first += 1
			d[max] -= 1
		}
		if first < d[max] {
			fmt.Fprintln(out, first)
		} else {
			fmt.Fprintln(out, d[max])
		}
	}
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func findKey(m map[int]int, val int) []int {
	res := make([]int, 0)
	for k, v := range m {
		if v == val {
			res = append(res, k)
		}
	}
	return res
}

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

func uniquesWithoutXN(m map[int]int, key int, times int) int {
	uniqCounter := 0

	for k, v := range m {
		if k == key {
			if (v - times) > 0 {
				uniqCounter++
			}
		} else {
			uniqCounter++
		}
	}
	return uniqCounter
}

func solve() {
	var n int
	scanf("%d\n", &n)
	data := make([]int, n)
	counts := make(map[int]int)
	var totalUniques int
	for i := 0; i < n; i++ {
		var tmp int
		scanf("%d", &tmp)
		data[i] = tmp

		if _, ok := counts[tmp]; ok {
			counts[tmp] = counts[tmp] + 1
		} else {
			counts[tmp] = 1
			totalUniques++
		}
	}
	scanf("\n")
	//fmt.Println("data loaded: ", data)
	//fmt.Println(counts)

	countsRvals := make([]int, 0)
	uniquenessCheck := make(map[int]bool)

	for _, v := range counts {
		if _, ok := uniquenessCheck[v]; !ok {

			countsRvals = append(countsRvals, v)
			uniquenessCheck[v] = true
		}

	}
	//fmt.Println(countsRvals)

	sort.Ints(countsRvals)

	//fmt.Println("total uniques:", totalUniques)

	maxi := 0
	for k, c := range counts {
		if c > maxi {
			for i := 0; i < (c - maxi); i++ {
				c2 := c - i
				//fmt.Println("DEBUG:", c2, uniquesWithoutXN(counts, k, c2))
				//fmt.Println("DEBUG2:", uniquesWithoutXN(counts, 1, 2))
				res := minOfTwo(c2, uniquesWithoutXN(counts, k, c2))
				if res > maxi {
					maxi = res
				}

			}

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

func main() {
	defer fflush()

	var T, i uint64
	scanf("%d\n", &T)
	for i = 0; i < T; i++ {
		solve()
	}

}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

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

func exec() {
	var n uint64
	scanf("%d %d\n", &n)

	arrA, err := scanIntArr()
	if err != nil {
		fmt.Println(err.Error())
		panic(err)
	}

	diffs := 0
	maxI := 0
	mp := map[int]int{}
	for _, a := range arrA {
		if _, ok := mp[a]; !ok {
			diffs++
		}
		mp[a]++
		if a != maxI && mp[a] > mp[maxI] {
			maxI = a
		}
	}

	var result int
	switch {
	case diffs-mp[maxI] > 0:
		result = mp[maxI]
	case diffs-mp[maxI] == 0:
		result = diffs - 1
	case diffs-mp[maxI] < 0:
		result = diffs
	}

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

//Codeforces Round #633 (Div. 2)
//https://codeforces.com/contest/1339/problem/C

package main

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

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

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

var db bool = true
// var db bool = false

//const maxn int = 1e5

func main() {
	defer writer.Flush()

    var t, n int
	scanf("%d\n", &t)

	for tc := 1; tc <= t; tc++ {
		scanf("%d\n", &n)
		m := make(map[int]int)
		mxc := 0
		for i := 0; i < n; i++ {
		    var v int
		    scanf("%d", &v)
		    if i != n-1 {
		        scanf(" ")
		    } else {
		        scanf("\n")
		    }

		    m[v] += 1
		    if m[v] > mxc {
		        mxc = m[v]
		    }
	    }
	    if n == 1 {
		    printf("0\n")
		    continue
		}

	    ta  := len(m)
	    tb  := mxc
	    ans := ta
	    if tb < ans {
	        ans = tb
	    }
	    if ta == tb {
	        ans--
	    }
	    printf("%v\n", ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscanf(in, "%d\n", &T)

	for ; T > 0; T-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		mp := make(map[int]int)
		var val, mval int
		mval = 0

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d ", &val)
			mp[val]++
			mval = max(mval, mp[val])
		}
		fmt.Fscanf(in, "%d\n", &val)

		fmt.Println(max(min(len(mp)- 1, mval), min(len(mp), mval - 1)))
	}

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

package main

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

func main() {

	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	maxV = len(bytes) - 1

	t := fastScan()

	for ; t > 0; t-- {
		n := fastScan()
		mp := make(map[int]int)
		var val, mval int
		mval = 0

		for i := 0; i < n; i++ {
			val = fastScan()
			mp[val]++
			mval = max(mval, mp[val])
		}
		fmt.Println(max(min(len(mp)-1, mval), min(len(mp), mval-1)))

	}
}

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 bytes []byte
var l, maxV int

func fastScan() int {
	b := bytes[l]

	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > maxV {
			return result
		}
		b = bytes[l]
	}
	return result
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscanf(in, "%d\n", &T)

	for ; T > 0; T-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		mp := make(map[int]int)
		var val, mval int
		mval = 0

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d ", &val)
			mp[val]++
			mval = max(mval, mp[val])
		}
		fmt.Fscanf(in, "%d ", &val)

		fmt.Println(max(min(len(mp)- 1, mval), min(len(mp), mval - 1)))
	}

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

package main

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

func solve(n int, m map[int]int) int {
	max := 0

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

	if len(m) == max {
		return max - 1
	}

	return findMin(len(m), max)
}

func findMin(n1 int, n2 int) int {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var t, n, a int
	fmt.Fscanf(r, "%d\n", &t)

	for tc := 0; tc < t; tc++ {
		fmt.Fscanf(r, "%d\n", &n)
		m := map[int]int{}

		for i := 0; i < n; i++ {
			fmt.Fscanf(r, "%d", &a)
			m[a]++
		}
		fmt.Fscanln(r)
		fmt.Fprintf(os.Stdout, "%d\n", solve(n, m))
	}
}

// https://serhatgiydiren.github.io

package main

import "fmt"
import "os"
import "bufio"

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

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

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

func solve(test_id int) {
 defer writer.Flush()
 var n,q int
 fmt.Fscanf(reader, "%d\n", &n)
 m := make(map[int]int)
 for i := 0 ; i < n ; i++ {
  fmt.Fscanf(reader, "%d", &q)
  m[q]++
 }
 c := 0
 for _,v := range(m) {
  c = max(c , v)
 }
 res := min(c , min(len(m) , n / 2))
 if res == c && res == len(m) {
  res--
 }
 fmt.Fscanf(reader, "\n")
 fmt.Fprintf(writer, "%d\n", res)
}

func solve_cases() {
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

// https://serhatgiydiren.github.io

package main

import "fmt"
import "os"
import "bufio"

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

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

func solve(test_id int) {
 defer writer.Flush()
 var n,q int
 fmt.Fscanf(reader, "%d\n", &n)
 m := make(map[int]int)
 for i := 0 ; i < n ; i++ {
  fmt.Fscanf(reader, "%d", &q)
  m[q]++
 }
 c := 0
 for _,v := range(m) {
  if v > c {
   c = v
  }
 }
 res := min(c , min(len(m) , n / 2))
 if res == c && res == len(m) {
  res--
 }
 fmt.Fscanf(reader, "\n")
 fmt.Fprintf(writer, "%d\n", res)
}

func solve_cases() {
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

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

func main() {
	var truncator string
	if runtime.GOOS == "windows" {
		truncator = "\r\n"
	} else {
		truncator = "\n"
	}

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, truncator)
	testcase, _ := strconv.ParseInt(text, 10, 64)

	var i int64
	numSlice := make([]int64, testcase)
	stdSlice := make([][]int64, testcase)
	calSlice := make([][]int64, testcase)
	resSlice := make([]string, testcase)
	for i = 0; i < testcase; i++ {
		text, _ = reader.ReadString('\n')
		text = strings.TrimSuffix(text, truncator)
		numSlice[i], _ = strconv.ParseInt(text, 10, 64)
		stdSlice[i] = readInt(numSlice[i], reader)
		calSlice[i] = make([]int64, numSlice[i])
		for _, v := range stdSlice[i] {
			calSlice[i][v-1]++
		}
		rep := isMax(calSlice[i])
		nzr := countNzero(calSlice[i])
		resSlice[i] = fmt.Sprintf("%d", max(min(rep, nzr-1), min(rep-1, nzr)))
	}

	result := strings.Join(resSlice, "\n")
	fmt.Printf("%s\n", result)
}

func isMax(a []int64) int64 {
	if len(a) == 1 {
		return a[0]
	}
	result := a[0]
	for _, v := range a {
		if result < v {
			result = v
		}
	}
	return result
}

func countNzero(a []int64) int64 {
	var result int64 = 0
	for _, v := range a {
		if v != 0 {
			result++
		}
	}
	return result
}

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

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

func readInt(size int64, reader *bufio.Reader) []int64 {
	text, _ := reader.ReadString('\n')
	split := strings.Fields(text)
	result := make([]int64, len(split))
	var i int64
	for i = 0; i < size; i++ {
		result[i], _ = strconv.ParseInt(split[i], 10, 64)
	}
	return result
}

package main

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

/*
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3
*/

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

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

		target := make(map[int]int)
		for Fscan(in, &R); R > 0; R-- {
			var data int
			Fscan(in, &data)
			target[data] ++
		}

		if len(target) == 0 {
			Fprintln(out, 0)
			continue
		}

		var sumTwo int
		for _, v := range target {
			if v != 1 {
				if sumTwo < v {
					sumTwo = v
				}
			}
		}

		Fprintln(out, TTCMin(len(target), sumTwo))

	}
}

func TTCMin(len, two int) int {
	if len == 1 {
		if two == 0 {
			return 0
		}
		return 1
	}else {
		if two == 0 {
			return 1
		}
	}

	if two-len+1 > 1 {
		return len
	}

	if two-len+1 > 0 {
		return len - 1
	}

	return two
}

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

// Author: sighduck
// URL: https://codeforces.com/contest/1335/problem/C

package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func Solve(n int, a []int) int {
	count := make(map[int]int)
	for _, elem := range a {
		count[elem] += 1
	}
	maxCount := 0
	for _, v := range count {
		if v > maxCount {
			maxCount = v
		}
	}
	distinct := len(count) - 1
	if distinct+1 < maxCount {
		return distinct+1
	}
	return min(distinct, maxCount)
}

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

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		am := map[int64]int64{}
		maxSoFar := int64(0)
		for i := int64(0); i < n; i++ {
			a := reader.NextInt64()
			am[a]++
			maxSoFar = max(maxSoFar, am[a])
		}
        if int64(len(am)) == maxSoFar {
            writer.Printf("%d\n", min(n/2, maxSoFar-1))
        } else {
            writer.Printf("%d\n", min(n/2, int64(len(am)), maxSoFar))
        }
	}
}

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

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

package main

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

func main() {

	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("input.txt")
	var T int
	fmt.Fscanf(in, "%d\n", &T)

	for k := 0; k < T; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		mp := make(map[int]int)
		var val, mval int
		mval = 0

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d\n", &val)
			mp[val]++
			mval = max(mval, mp[val])
		}
		p := len(mp)
		fmt.Println(max(min(p-1, mval), min(p, mval-1)))
	}

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

package main

import (
	"fmt"
)

func main() {

	var T int
	fmt.Scanf("%d\n", &T)

	for k := 0; k < T; k++ {
		var n int
		fmt.Scanf("%d", &n)

		mp := make(map[int]int)
		var val, mval int
		mval = 0

		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &val)
			mp[val]++
			mval = max(mval, mp[val])
		}
		p := len(mp)
		fmt.Println(max(min(p-1, mval), min(p, mval-1)))
	}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscanf(in, "%d\n", &T)

	for ; T > 0; T-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		mp := make(map[int]int)
		var val, mval int
		mval = 0

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d ", &val)
			mp[val]++
			mval = max(mval, mp[val])
		}

		fmt.Println(max(min(len(mp)- 1, mval), min(len(mp), mval - 1)))
	}

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

package main

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

func solve(n int, m map[int]int) int {
	max := 0

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

	return findMin(findMin(max, len(m)), n/2)
}

func findMin(n1 int, n2 int) int {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var t, n, a int
	fmt.Fscanf(r, "%d\n", &t)

	for tc := 0; tc < t; tc++ {
		fmt.Fscanf(r, "%d\n", &n)
		m := map[int]int{}

		for i := 0; i < n; i++ {
			fmt.Fscanf(r, "%d", &a)
			m[a]++
		}
		fmt.Fscanln(r)
		fmt.Fprintf(os.Stdout, "%d\n", solve(n, m))
	}
}

// https://serhatgiydiren.github.io

package main

import "fmt"

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

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

func solve(test_id int) {
 var n,q int
 fmt.Scan(&n)
 m := make(map[int]int)
 for i := 0 ; i < n ; i++ {
  fmt.Scan(&q)
  m[q]++
 }
 c := 0
 for _,v := range(m) {
  c=max(c,v)
 }
 fmt.Println(min(len(m),min(c,n/2)))
}

func solve_cases() {
 t := 1
 fmt.Scan(&t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

// https://serhatgiydiren.github.io

package main

import "fmt"

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

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

func solve(test_id int) {
 var n,q int
 fmt.Scan(&n)
 m := make(map[int]int)
 for i := 0 ; i < n ; i++ {
  fmt.Scan(&q)
  m[q]++
 }
 c := 0
 for _,v := range(m) {
  c=max(c,v)
 }
 res := min(c,min(len(m),n/2))
 if res == c {
  res--
 }
 fmt.Println(res)
}

func solve_cases() {
 t := 1
 fmt.Scan(&t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

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

/*
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3
*/

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

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

		target := make(map[int]int)
		for Fscan(in, &R); R > 0; R-- {
			var data int
			Fscan(in, &data)
			target[data] ++
		}

		if len(target) == 0 {
			Fprintln(out, 0)
			continue
		}

		var sumTwo int
		for _, v := range target {
			if v != 1 {
				if sumTwo < v {
					sumTwo = v
				}
			}
		}

		Fprintln(out, TTCMin(len(target), sumTwo))

	}
}

func TTCMin(len, two int) int {
	if len == 1 {
		return 0
	}

	if two == 0 {
		return 1
	}

	if two-len+1 > 1 {
		return len
	}

	if two-len+1 > 0 {
		return len - 1
	}

	return two
}

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

// Author: sighduck
// URL: https://codeforces.com/contest/1335/problem/C

package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func Solve(n int, a []int) int {
	count := make(map[int]int)
	for _, elem := range a {
		count[elem] += 1
	}
	maxCount := 0
	for _, v := range count {
		if v > maxCount {
			maxCount = v
		}
	}
	distinct := len(count) - 1
	if distinct+1 < maxCount {
		return maxCount - 1
	}
	return min(distinct, maxCount)
}

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

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		am := map[int64]int64{}
		maxSoFar := int64(0)
		for i := int64(0); i < n; i++ {
			a := reader.NextInt64()
			am[a]++
			maxSoFar = max(maxSoFar, am[a])
		}
		writer.Printf("%d\n", min(n/2, maxSoFar))
	}
}

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

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		am := map[int64]int64{}
		maxSoFar := int64(0)
		for i := int64(0); i < n; i++ {
			a := reader.NextInt64()
			am[a]++
			maxSoFar = max(maxSoFar, am[a])
		}
		writer.Printf("%d\n", min(n/2, int64(len(am)), maxSoFar))
	}
}

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

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