Sho has an array $a$ consisting of $n$ integers. An operation consists of choosing two distinct indices $i$ and $j$ and removing $a_i$ and $a_j$ from the array.

For example, for the array $[2, 3, 4, 2, 5]$, Sho can choose to remove indices $1$ and $3$. After this operation, the array becomes $[3, 2, 5]$. Note that after any operation, the length of the array is reduced by two.

After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible.

More formally, the array after Sho has made his operations respects these criteria:

No pairs such that ($i < j$) and $a_i = a_j$ exist.

The length of $a$ is maximized.

Output the length of the final array.


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 50$) — the length of the array.

The second line of each test case contains $n$ integers $a_i$ ($1 \leq a_i \leq 10^4$) — the elements of the array.


-----Output-----

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.


-----Examples-----

Input
4
6
2 2 2 3 3 3
5
9 1 9 9 1
4
15 16 16 15
4
10 100 1000 10000
Output
2
1
2
4


-----Note-----

For the first test case Sho can perform operations as follows:

Choose indices $1$ and $5$ to remove. The array becomes $[2, 2, 2, 3, 3, 3] \rightarrow [2, 2, 3, 3]$.

Choose indices $1$ and $4$ to remove. The array becomes $[2, 2, 3, 3] \rightarrow [2, 3]$.

The final array has a length of $2$, so the answer is $2$. It can be proven that Sho cannot obtain an array with a longer length.

For the second test case Sho can perform operations as follows:

Choose indices $3$ and $4$ to remove. The array becomes $[9, 1, 9, 9, 1] \rightarrow [9, 1, 1]$.

Choose indices $1$ and $3$ to remove. The array becomes $[9, 1, 1] \rightarrow [1]$.

The final array has a length of $1$, so the answer is $1$. It can be proven that Sho cannot obtain an array with a longer length.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Greedy algorithms


Solutions:
for i in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	s = len(set(a))
	if (x - s) % 2 != 0:
		s = s - 1
		print(s)
	else:
		print(s)


def AllDistinct(arr):
	distinct = set(arr)
	to_remove = len(arr) - len(distinct)
	if to_remove % 2:
		to_remove += 1
	return len(arr) - to_remove
output = []
for _ in range(int(input())):
	N = int(input())
	arr = [int(x) for x in input().split()]
	output.append(AllDistinct(arr))
for _ in output:
	print(_)


for s in [*open(0)][2::2]:
	a = s.split()
	m = len({*a})
	print(m - (len(a) - m) % 2)


n = int(input())
mas = []
m = []
for i in range(n):
	m.append(int(input()))
	mas.append(list(map(int, input().split())))
for i in range(n):
	d = m[i] - len(set(mas[i]))
	if d % 2 == 0:
		print(len(set(mas[i])))
	else:
		print(len(set(mas[i])) - 1)


t = int(input())
for test in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	numbers_set = set(numbers)
	m = len(numbers_set)
	if (n - m) % 2 == 0:
		print(m)
	else:
		print(m - 1)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	k = set(arr)
	if (len(arr) - len(k)) % 2 == 0:
		print(len(k))
	else:
		print(len(k) - 1)


t = int(input())
for _ in range(t):
	a = int(input())
	l = [int(x) for x in input().split()]
	b = set(l)
	if (a - len(b)) % 2 == 1:
		print(len(b) - 1)
	else:
		print(len(b))


for _ in range(int(input())):
	n = int(input())
	l = [*map(int, input().split())]
	a = len(set(l))
	print(a - (n - a) % 2)


t = int(input())
for ii in range(t):
	a = int(input())
	l = list(map(int, input().split()))
	x = len(set(l))
	if (a - x) % 2 == 0:
		print(x)
	else:
		print(x - 1)


test = int(input())
ans = []
for i in range(test):
	length = int(input())
	a = [int(item) for item in input().split()]
	b = set()
	for j in a:
		b.add(j)
	if len(a) % 2 == len(b) % 2:
		ans.append(len(b))
	else:
		ans.append(len(b) - 1)
for i in ans:
	print(i, sep=' ')


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	a = set(lst)
	p = len(lst)
	if len(a) % 2 == 0 and p % 2 == 0:
		print(len(a))
	elif len(a) % 2 == 1 and p % 2 == 1:
		print(len(a))
	else:
		print(len(a) - 1)


import sys
I = sys.stdin.readline
O = sys.stdout.write
t = int(I())
for _ in range(t):
	n = int(I())
	arr = list(map(int, I().split()))
	x = set(arr)
	if (n - len(x)) % 2 == 0:
		O(str(len(x)) + '\n')
	else:
		O(str(len(x) - 1) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	seta = set(a)
	ans = len(seta)
	if (n - ans) % 2 == 0:
		print(ans)
	else:
		print(ans - 1)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(set(l))
	l = len(s)
	if l == n:
		print(l)
	elif (n - l) % 2 == 0:
		print(l)
	else:
		print(l - 1)


n = int(input())
for j in range(n):
	m = int(input())
	c = []
	b = input()
	b = b.split()
	for i in range(m):
		if b[i] not in c:
			c.append(b[i])
	if len(c) == m:
		print(m)
	elif m % 2 == 0 and len(c) % 2 == 0:
		print(len(c))
	elif m % 2 == 0 and len(c) % 2 != 0:
		print(len(c) - 1)
	elif m % 2 != 0 and len(c) % 2 == 0:
		print(len(c) - 1)
	else:
		print(len(c))


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	l = 0
	arr2 = set(arr1)
	if n % 2 != 0:
		if len(arr2) == n or len(arr2) % 2 != 0:
			print(len(arr2))
		else:
			print(len(arr2) - 1)
	elif len(arr2) % 2 == 0:
		print(len(arr2))
	else:
		print(len(arr2) - 1)


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	l2 = list(set(l))
	if len(l) % 2 == len(l2) % 2:
		print(len(l2))
	else:
		print(len(l2) - 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = set(map(int, input().split()))
	ans = len(a)
	if n % 2 != ans % 2:
		ans -= 1
	print(ans)


import math

def solve(n, ar):
	a = set(ar)
	if len(ar) - len(a) & 1:
		return len(a) - 1
	return len(a)
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	print(solve(n, ar))


x = int(input())
for _ in range(x):
	l = int(input())
	a = [int(i) for i in input().split()]
	s = set(a)
	l1 = len(s)
	r = l - l1
	if r % 2 == 0:
		print(l1)
	else:
		print(l1 - 1)


for _ in range(int(input())):
	a = int(input())
	b = set(input().split())
	if (a - len(b)) % 2:
		print(len(b) - 1)
	else:
		print(len(b))


for s in [*open(0)][2::2]:
	a = s.split()
	n = len({*a})
	print(n - (len(a) - n) % 2)


t = int(input())
arrow = []
while t > 0:
	n = int(input())
	a = input()
	a = a.split()
	a = list(set(a))
	if (n - len(a)) % 2 == 0:
		ans = len(a)
	else:
		ans = len(a) - 1
	arrow.append(ans)
	t -= 1
for i in range(len(arrow)):
	print(arrow[i])


for _ in range(int(input())):
	n = int(input())
	nums = set(map(int, input().split()))
	print(len(nums) - int((n - len(nums)) % 2))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = len(set(l))
	dif = len(l) - x
	x -= dif % 2
	print(x)


for s in [*open(0)][2::2]:
	n = len(s.split())
	k = len(set(s.split()))
	print(k if k % 2 == n % 2 else k - 1)


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = len(a)
	y = len(set(a))
	z = x - y
	if z % 2 == 0:
		print(y)
	else:
		print(y - 1)


import collections
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = collections.Counter(a)
	l = len(d.keys())
	if (n - l) % 2 == 0:
		print(l)
	else:
		print(l - 1)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	s = set(lst)
	l = len(s)
	if n % 2 == 0:
		if l % 2 == 0:
			print(l)
		else:
			print(l - 1)
	elif l % 2 == 0:
		print(l - 1)
	else:
		print(l)


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
from collections import Counter
for _ in range(I()):
	n = I()
	arr = L()
	C = Counter(arr)
	deleted = n - len(C)
	if deleted % 2 == 0:
		ans = len(C)
		print(ans)
	else:
		ans = len(C) - 1
		print(ans)


for h in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	m = len(set(x))
	if (n - m) % 2 == 1:
		print(m - 1)
	else:
		print(m)


def func():
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	if (len(l) - len(s)) % 2 == 0:
		print(len(s))
	else:
		print(len(s) - 1)
t = int(input())
for _ in range(t):
	func()


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().strip().split()]
	s = set()
	for x in a:
		s.add(x)
	if len(s) == n:
		print(n)
	else:
		left = n - len(s)
		if left % 2 == 0:
			print(len(s))
		else:
			print(len(s) - 1)


t = int(input())
for i in range(t):
	a = int(input())
	array = list(map(int, input().split()))
	d = len(set(array))
	if (a - d) % 2 == 0:
		print(d)
	else:
		print(d - 1)


t = int(input())
for tt in range(t):
	n = int(input())
	a = input().split()
	b = len(set(a))
	if n - b & 1 == 0:
		print(b)
	else:
		print(b - 1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	if (n - len(s)) % 2 == 0:
		print(len(s))
	else:
		print(len(s) - 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(set(a))
	print(len(a) - (len(a) - len(b) + (len(a) - len(b)) % 2))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = n - len(set(arr))
	print(n - 2 * ((m + 1) // 2))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = set(map(int, input().split()))
	m = a.__len__()
	if m & 1 and n & 1:
		print(m)
	elif not m & 1 and (not n & 1):
		print(m)
	else:
		print(m - 1)


from collections import Counter
from itertools import count
for s in [*open(0)][2::2]:
	l = Counter(map(int, s.split()))
	print(len(l) - (sum(l.values()) - len(l) & 1))


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	d = {}
	for i in lst:
		if d.get(i, -1) == -1:
			d[i] = 1
		else:
			d[i] += 1
	dups = 0
	for key in d.keys():
		dups += d[key] - 1
	ans = n - dups
	if dups % 2 == 1:
		ans -= 1
	print(ans)
	return
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	size = int(input())
	L = list(map(int, input().split()))
	s = set(L)
	sized = len(s)
	if (size - sized) % 2 == 0:
		print(sized)
	else:
		print(sized - 1)


def solve_B(a):
	count = dict()
	for num in a:
		count[num] = count.get(num, 0) + 1
	counts = count.values()
	nums = len(counts)
	diff = sum(counts) - nums
	if diff % 2 == 0:
		return nums
	else:
		return nums - 1
n = int(input().strip())
for _ in range(n):
	_ = input()
	a = list(map(int, input().strip().split()))
	print(solve_B(a))


import sys, math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_ls():
	return list(map(int, sys.stdin.readline().strip().split()))

def main():
	for _ in range(int(input())):
		n = int(input())
		a = get_ls()
		d = dict()
		for x in a:
			if x in d:
				d[x] += 1
			else:
				d[x] = 1
		ln = len(d)
		rem = 0
		for x in d.values():
			if x > 1:
				rem += x - 1
		if rem % 2 == 1:
			rem += 1
		if ln == n:
			print(n)
		else:
			print(n - rem)
main()


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
for i in range(int(input())):
	length = int(input())
	arr = LI()
	set_arr = set(arr)
	no_Of_Copy = length - len(set_arr)
	if len(arr) == len(set_arr):
		print(length)
	elif len(arr) != len(set_arr) and no_Of_Copy % 2 == 0:
		print(length - no_Of_Copy)
	else:
		print(length - no_Of_Copy - 1)


for i in range(int(input())):
	length = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	if len(a) - len(b) == 0:
		print(length)
	elif (len(a) - len(b)) % 2 == 0:
		print(len(b))
	else:
		print(len(b) - 1)


import math
for i in range(int(input())):
	n = int(input())
	x = input().split()
	l1 = []
	c = 0
	for j in x:
		if j not in l1:
			l1.append(j)
		else:
			c += 1
	print(n - 2 * math.ceil(c / 2))


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	distinct = set(nums)
	if (len(nums) - len(distinct)) % 2 == 0:
		print(len(distinct))
	else:
		print(len(distinct) - 1)


from collections import defaultdict, deque
import sys
input = lambda : sys.stdin.readline().strip()
for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	if (n - len(set(a))) % 2 == 0:
		print(len(set(a)))
	else:
		print(len(set(a)) - 1)


test = int(input())
while test:
	n = int(input())
	A = list(map(int, input().split()))
	s = list(set(A))
	m = {}
	h = n
	for i in A:
		if i not in m:
			m[i] = 1
		else:
			m[i] += 1
	s.sort()
	for i in s:
		n -= m[i] - 1
	if (h - n) % 2 == 1:
		n -= 1
	print(n)
	test -= 1


t = int(input())
ns = []
strIn = []
for _ in range(t):
	ns.append(input())
	strIn.append(input())
for i in range(t):
	n = ns[i]
	inp = strIn[i]
	nums = [int(p) for p in inp.split()]
	num_set = set(nums)
	rem_len = len(nums)
	while rem_len > len(num_set):
		rem_len -= 2
	print(rem_len)


for _ in range(int(input())):
	test = int(input())
	l = list(map(int, input().split()))
	setlis = set(l)
	ans = len(setlis)
	if (test - ans) % 2 == 0:
		print(ans)
	else:
		print(ans - 1)


t = int(input())
while t > 0:
	n = int(input())
	arr = []
	arr = list(map(int, input().split()))
	unqArr = list(set(arr))
	res = 0
	if n % 2 == 0:
		if len(unqArr) % 2 == 0:
			res = len(unqArr)
		else:
			res = len(unqArr) - 1
	elif len(unqArr) % 2 == 0:
		res = len(unqArr) - 1
	else:
		res = len(unqArr)
	print(res)
	t -= 1


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	arr = list(map(int, input().split()))
	a = len(set(arr))
	b = len(arr)
	c = b - a
	if c % 2 == 0:
		print(a)
	else:
		print(a - 1)


import sys
for _ in range(int(sys.stdin.readline().strip())):
	n = int(sys.stdin.readline().strip())
	arr = list(map(int, input().strip().split()))
	newarr = list(set(arr))
	t = len(arr) - len(newarr)
	if t % 2 == 0:
		print(len(newarr))
	else:
		print(len(newarr) - 1)


for _ in range(int(input())):
	n = int(input()) % 2
	ls = len(set(input().split()))
	print(ls - n ^ ls % 2)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	set_a = set(a)
	if (n - len(set_a)) % 2 == 0:
		print(len(set_a))
	else:
		print(len(set_a) - 1)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = set(arr)
	if len(l) % 2 == 0 and len(arr) % 2 == 0:
		print(len(l))
	elif len(l) % 2 == 1 and len(arr) % 2 == 1:
		print(len(l))
	else:
		print(len(l) - 1)


n = int(input())
for i in range(n):
	m1 = int(input())
	a = list(map(int, input().split()))
	a.sort()
	se = set(a)
	if (m1 - len(se)) % 2 == 0:
		print(len(se))
	else:
		print(len(se) - 1)


t = int(input())
while t:
	n = int(input())
	a = map(int, input().split())
	b = set(a)
	if (n - len(b)) % 2 != 0:
		print(len(b) - 1)
	elif (n - len(b)) % 2 == 0:
		print(len(b))
	elif len(b) == n:
		print(len(a))
	t -= 1


def solve(n, a):
	s = set()
	num_dels = 0
	for v in a:
		if v in s:
			num_dels += 1
		else:
			s.add(v)
	return n - (num_dels + num_dels % 2)
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(v) for v in input().split()]
	print(solve(n, a))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = len(set(l))
	while True:
		l.sort()
		if len(l) <= k:
			break
		l.pop(0)
		if l:
			l.pop()
	print(len(l))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	setarr = set(arr)
	diff = len(arr) - len(setarr)
	if diff % 2 == 0:
		print(len(setarr))
	else:
		print(len(setarr) - 1)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = set(A)
	if abs(len(A) - len(B)) % 2 == 0:
		print(len(B))
	else:
		print(len(B) - 1)


for i in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	t_s = set(t)
	lt = len(t)
	while len(t_s) < lt:
		lt -= 2
	print(lt)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = set()
	for i in l:
		l1.add(i)
	k = len(l)
	j = len(l1)
	if (k - j) % 2 == 0:
		print(j)
	else:
		print(j - 1)


numCases = int(input())
for case in range(numCases):
	input()
	array = input().split(' ')
	numDuplicates = len(array) - len(set(array))
	elementsRemoved = numDuplicates
	if elementsRemoved % 2 == 1:
		elementsRemoved += 1
	print(len(array) - elementsRemoved)


for e in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	print(n - 2 * ((len(a) - len(b) + 1) // 2))


for _ in range(int(input())):
	count = int(input())
	numb = input().split()
	l = len(numb)
	tmp_dict = dict.fromkeys(numb)
	unique = len(tmp_dict)
	if (l - unique) % 2 == 0 or l - unique == 0:
		print(unique)
	else:
		print(unique - 1)


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = list(set(arr))
	dist = len(ans)
	if dist % 2 == 0 and n % 2 != 0 or (dist % 2 != 0 and n % 2 == 0):
		print(dist - 1)
	else:
		print(dist)
	t -= 1


t = int(input())
for T in range(t):
	n = int(input())
	inp = input()
	array = list(map(int, inp.split()))
	els = {}
	for el in array:
		els[el] = els.get(el, 0) + 1
	l = list(els.values())
	if l == [1] * n:
		print(n)
		continue
	if n == 1:
		print(1)
		continue
	if n == 2:
		if array[0] == array[1]:
			print(0)
			continue
		else:
			print(1)
			continue
	rep_count = 0
	for v in l:
		if v == 1:
			pass
		else:
			rep_count += v - 1
	if rep_count % 2 == 0:
		print(n - rep_count)
	else:
		print(n - rep_count - 1)


for i in range(int(input())):
	x = input()
	l = list(map(int, input().split()))
	s = set(l)
	lenl = len(l)
	lens = len(s)
	if lenl % 2 == 0 and lens % 2 == 0:
		print(lens)
	elif lenl % 2 != 0 and lens % 2 != 0:
		print(lens)
	else:
		print(lens - 1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = list(dict.fromkeys(a))
	if (n - len(a)) % 2 == 0:
		print(len(a))
	else:
		print(len(a) - 1)


for _ in range(int(input())):
	a = int(input())
	arr = list(map(int, input().split()))
	ar = set(arr)
	if (len(arr) - len(ar)) % 2 == 0:
		print(len(ar))
	else:
		print(len(ar) - 1)


t = int(input())
while t != 0:
	n = int(input())
	t -= 1
	mylist = list(map(int, input().split()))
	myset = set()
	for i in mylist:
		myset.add(i)
	if n % 2 == 1:
		if len(myset) % 2 == 0:
			print(len(myset) - 1)
		else:
			print(len(myset))
	elif len(myset) % 2 == 1:
		print(len(myset) - 1)
	else:
		print(len(myset))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = len(set(l))
	print([x - 1, x][n % 2 == x % 2])