The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:

The MEX of [2, 2, 1] is 0 because 0 does not belong to the array.
The MEX of [3, 1, 0, 1] is 2 because 0 and 1 belong to the array, but 2 does not.
The MEX of [0, 3, 1, 2] is 4 because 0, 1, 2 and 3 belong to the array, but 4 does not.

You're given an array A containing 2\cdot N integers where 0 ≤ A_{i} ≤ N. Is it possible to reorder the elements of the array in such a way that the MEX of the first N elements is equal to the MEX of the last N elements?

------ Input Format ------ 

- The first line contains T denoting the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer N.
- The second line contains 2\cdot N space-separated integers A_{1}, A_{2}, \dots, A_{2\cdot N}.

------ Output Format ------ 

For each test case, print YES if there is a valid reordering of the given array and NO otherwise. 

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------ 

$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ A_{i} ≤ N$
- Sum of $N$ over all test cases does not exceed $2\cdot 10^{5}$.

----- Sample Input 1 ------ 
4
2
0 0 0 1
2
0 0 1 1
3
1 3 2 3 3 2
3
0 0 1 1 1 2

----- Sample Output 1 ------ 
NO
YES
YES
NO

----- explanation 1 ------ 
Test case $1$: There is no way to reorder the elements of the array $[0,0,0,1]$ which satisfies the given conditions.

Test case $2$: One possible reordering is $[0,1,0,1]$. Here the MEX of the first half is MEX$([0,1])=2$ and the MEX of the second half is MEX$([0,1])=2$. 

Test case $3$: The given array already satisfies the conditions. Here the MEX of the first half is MEX$([1,3,2])=0$ and the MEX of the second half is MEX$([3,3,2])=0$.

Difficulty: MEDIUM
Tags: Constructive algorithms

Ad-hoc

Starter code:

Solutions:
from collections import Counter
t = int(input())
for djhdf in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = {i: 0 for i in range(0, max(a) + 1)}
	for i in a:
		x[i] += 1
	ans = 'YES'
	for j in x.values():
		if j == 0:
			break
		if j == 1:
			ans = 'NO'
			break
	print(ans)


T = int(input())
for i in range(T):
	N = int(input())
	A = [int(x) for x in input().split()]
	counts = {}
	counts = {i: 0 for i in range(0, max(A) + 1)}
	for i in A:
		counts[i] += 1
	flag = 0
	for i in counts.values():
		if i == 0:
			break
		if i == 1:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


from collections import Counter
n_cases = int(input())
for _ in range(n_cases):
	input()
	arr = [int(x) for x in input().split()]
	ctr = Counter(arr)
	skeys = sorted((x for x in ctr.keys()))
	gap_marker = 0
	splittable = True
	for k in skeys:
		if k != gap_marker:
			splittable = True
			break
		if ctr[k] == 1:
			splittable = False
			break
		gap_marker += 1
	print('YES' if splittable else 'NO')


for _ in range(int(input())):
	n = int(input())
	l = [int(a) for a in input().split()]
	l.sort()
	if l[0] > 0:
		print('YES')
		continue
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	for i in range(l[-1] + 2):
		if i not in d.keys():
			mex = i
			break
	for j in range(n + 2):
		if j in d.keys() and j < mex and (d[j] == 1):
			print('NO')
			break
		elif j > mex:
			print('YES')
			break


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ANS = [0 for i in range(0, max(A) + 1)]
	for j in A:
		ANS[j] += 1
	ans = 1
	for j in ANS:
		if j == 0:
			break
		if j == 1:
			ans = 0
			break
	if ans == 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	l1 = [0 for i in range(0, max(l) + 1)]
	for i in l:
		l1[i] += 1
	t = 1
	for i in l1:
		if i == 0:
			break
		if i == 1:
			t = 0
			break
	if t == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
for i in range(int(input())):
	a = int(input())
	lst = list(map(int, input().split()))
	lst1 = [0 for i in range(0, max(lst) + 1)]
	for i in lst:
		lst1[i] += 1
	t = 1
	for i in lst1:
		if i == 0:
			break
		if i == 1:
			t = 0
			break
	if t == 1:
		print('YES')
	else:
		print('NO')


def Solve(l, n):
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	i = 0
	while i <= n:
		if i not in d:
			return 'YES'
		elif d[i] == 1:
			return 'NO'
		i += 1
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(Solve(l, n))


from collections import Counter

def solve():
	n = int(input())
	A = Counter([int(x) for x in input().split()])
	for i in range(n):
		if A[i] == 0:
			return 'YES'
		elif A[i] < 2:
			return 'NO'
	return 'YES'
t = int(input())
while t:
	print(solve())
	t -= 1


def mex(arr):
	if arr[0] != 0:
		return 0
	j = 0
	for i in arr:
		if i == j or i == j - 1:
			j = i + 1
		else:
			return j
	return arr[-1] + 1

def solve(arr, n):
	(a1, a2) = ([], [])
	for i in range(1, n * 2, 2):
		a1.append(arr[i])
		a2.append(arr[i - 1])
	if mex(a1) == mex(a2):
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	a = int(input())
	arr = sorted(list(map(int, input().split())))
	print(solve(arr, a))


t = int(input())

def get_missing(arr):
	x = 0
	arr = list(set(arr))
	for a in arr:
		if a != x:
			break
		x += 1
	return x
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	(a1, a2) = ([], [])
	for i in range(0, n * 2 - 1, 2):
		a1.append(arr[i])
		a2.append(arr[i + 1])
	res1 = get_missing(a1)
	res2 = get_missing(a2)
	if res2 != res1:
		print('NO')
	else:
		print('YES')


from collections import Counter
import math
op = int(input())
for _ in range(op):
	n = int(input())
	a = list(map(int, input().split()))
	r = Counter(a)
	e = True
	for i in range(n + 1):
		if i not in r:
			print('YES')
			e = False
			break
		elif r[i] == 1:
			print('NO')
			e = False
			break
	if e:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = Counter(a)
	ans = 'YES'
	for i in range(n + 2):
		if b[i] == 0:
			break
		elif b[i] == 1:
			ans = 'NO'
	print(ans)


from collections import Counter
for q in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = Counter(l)
	i = 0
	while True:
		if x[i] == 0:
			print('YES')
			break
		elif x[i] == 1:
			print('NO')
			break
		i += 1


for i in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	d = {}
	for ii in range(2 * n):
		if k[ii] in d:
			d[k[ii]] += 1
		else:
			d[k[ii]] = 1
	ff = 0
	for u in range(max(k) + 1):
		if u in d:
			if d[u] < 2:
				ff = 1
				break
		else:
			ff = 0
			break
	if ff == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for j in l:
		if j not in d:
			d[j] = 1
		else:
			d[j] += 1
	ch = [k for k in range(n)]
	f = 0
	for m in ch:
		if m not in d:
			print('YES')
			f = 1
			break
		elif d[m] == 1:
			print('NO')
			f = 1
			break
	if f == 0:
		print('YES')


from collections import defaultdict
for _ in range(int(input())):
	N = 2 * int(input())
	A = sorted(list(map(int, input().split())))
	cnt = i = 0
	while i < N:
		cn = 0
		while i < N and A[i] == cnt:
			cn += 1
			i += 1
		if cn == 1:
			print('NO')
			break
		if cn == 0:
			print('YES')
			break
		cnt += 1
	else:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = Counter(l)
	temp = True
	for i in range(n + 1):
		a = x[i]
		if a == 1:
			print('NO')
			temp = False
			break
		elif a == 0:
			break
	else:
		print('YES')
	if temp:
		print('YES')


from collections import Counter
for _ in range(int(input())):
	flag = 1
	n = int(input())
	list1 = [int(x) for x in input().split()]
	x = Counter(list1)
	i = 0
	while True:
		if x[i] == 0:
			print('YES')
			break
		elif x[i] == 1:
			print('NO')
			break
		i += 1


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split(' ')))
	c = Counter(x)
	i = 0
	while True:
		if c[i] == 0:
			print('YES')
			break
		if c[i] == 1:
			print('NO')
			break
		i += 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	helper = {}
	helper = [0] * (n + 2)
	for i in arr:
		helper[i] += 1
	for i in range(n + 2):
		if helper[i] == 0:
			print('YES')
			break
		elif helper[i] == 1:
			print('NO')
			break


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	helper = {}
	helper = [0] * (n + 2)
	for i in arr:
		helper[i] += 1
	for i in range(n + 2):
		if helper[i] == 0:
			print('YES')
			break
		elif helper[i] == 1:
			print('NO')
			break


def sol(n, a):
	d = {}
	for i in range(2 * n):
		if a[i] in d:
			d[a[i]] += 1
		else:
			d[a[i]] = 1
	for i in range(n + 1):
		if i not in d:
			return 'YES'
		if d[i] == 1:
			return 'NO'
	return 'YES'
for tc in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(sol(n, a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	integer = -1
	count = 0
	p = 0
	for i in a:
		if i != integer:
			if count == 1:
				p = 1
				break
			if i - integer == 1:
				integer = i
				count = 1
			else:
				break
		else:
			count += 1
	if count == 1:
		p = 1
	if p == 1:
		print('NO')
	else:
		print('YES')


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(a) for a in input().split()]
	L = set(l)
	mex = 0
	flag = 0
	c = Counter(l)
	while mex in L:
		if c[mex] < 2:
			flag = 1
		mex += 1
	if mex == 0:
		print('YES')
	elif flag == 0:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	a1 = []
	a2 = []
	for i in range(n * 2):
		if i % 2 == 0:
			a1.append(a[i])
		else:
			a2.append(a[i])
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	for i in range(n):
		d1[a1[i]] += 1
		d2[a2[i]] += 1
	me1 = max(a1) + 2
	me2 = max(a2) + 2
	for i in range(me1):
		if d1[i] == 0:
			mex1 = i
			break
	for i in range(me2):
		if d2[i] == 0:
			mex2 = i
			break
	if mex1 == mex2:
		print('YES')
	else:
		print('NO')


from collections import Counter

def check(data):
	data1 = Counter(data)
	for i in range(max(data) + 1):
		if data1[i] == 0:
			print('YES')
			return
		if data1[i] == 1:
			print('NO')
			return
	print('YES')
	return
t = int(input())
for index in range(t):
	n = int(input())
	data = list(map(int, input().split()))
	check(data)


T = int(input())
while T > 0:
	n = int(input())
	n *= 2
	arr = list(map(int, input().split()))
	n = n % 2 + n // 2
	dic = dict()
	for i in arr:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	flag = True
	for i in range(n):
		if i in dic:
			f = dic[i]
		else:
			f = 0
		if f == 0:
			print('YES')
			flag = False
			break
		elif f == 1:
			print('NO')
			flag = False
			break
	if flag:
		print('YES')
	T -= 1


from collections import Counter
numTest = int(input())
for _ in range(numTest):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = Counter(arr)
	ans = True
	for i in range(n):
		if cnt[i] == 0:
			break
		if cnt[i] == 1:
			ans = False
			break
	print('YES' if ans else 'NO')


T = int(input())
for test_case in range(T):
	input()
	A = list(map(int, input().split(' ')))
	freq = [0] * (max(A) + 2)
	for i in A:
		freq[i] += 1
	for i in freq:
		if i == 0:
			print('YES')
			break
		if i == 1:
			print('NO')
			break


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {x: 0 for x in range(0, n + 1)}
	for i in l:
		if i not in d:
			d[i] = 0
		d[i] += 1
	c = 1
	for i in range(0, n + 1):
		if d[i] == 1:
			c = 0
			break
		if d[i] == 0:
			c = 1
			break
	if c == 1:
		print('YES')
	else:
		print('NO')


import collections

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	hash_ = collections.Counter(arr)
	for i in range(n):
		if i in hash_:
			if hash_[i] >= 2:
				continue
			if hash_[i] == 1:
				return 'NO'
		else:
			return 'YES'
	return 'YES'
t = int(input())
while t > 0:
	print(solve())
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for e in a:
		d[e] = d.get(e, 0) + 1
	c = 0
	while True:
		x = d.get(c, 0)
		if x == 0:
			print('YES')
			break
		if x == 1:
			print('NO')
			break
		c += 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = [0 for i in range(n + 1)]
	l1 = list(map(int, input().strip().split(' ')))
	for i in l1:
		l[i] = l[i] + 1
	val = 0
	for i in range(n + 1):
		if l[i] == 0:
			val = 1
			break
		if l[i] == 1:
			break
	if val == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter

def solve_arr(arr):
	count = Counter(arr)
	mex = 0
	for arr_elem in sorted(count.keys()):
		if mex == arr_elem:
			if count[arr_elem] < 2:
				return False
		else:
			return True
		mex += 1
	return True
T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	if solve_arr(arr):
		print('YES')
	else:
		print('NO')


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = dict(Counter(l))
	done = True
	j = 0
	for i in sorted(d.keys()):
		if i == j:
			if d[i] < 2:
				print('NO')
				done = False
				break
		else:
			print('YES')
			done = False
			break
		j += 1
	if done:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split(' ')))
	f = [0] * (n + 1)
	for x in s:
		f[x] += 1
	valid = False
	for i in range(n + 1):
		if f[i] == 0:
			valid = True
			break
		if f[i] == 1:
			break
	print('YES') if valid else print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	f = [0] * (n + 2)
	for i in arr:
		f[i] += 1
	ok = False
	ok2 = True
	for i in range(n + 2):
		if f[i] == 0:
			if ok2:
				ok = True
		if f[i] < 2:
			ok2 = False
	if ok:
		print('YES')
	else:
		print('NO')


def equalMEX(n, arr):
	lookup = {}
	for k in arr:
		lookup[k] = lookup.get(k, 0) + 1
	if 0 not in lookup:
		return True
	for x in range(n):
		if x in lookup:
			if lookup[x] == 1:
				return False
		else:
			return True
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	print('YES') if equalMEX(n, arr) else print('NO')


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(0) == 0:
		return 'YES'
	elif arr.count(0) == 1:
		return 'NO'
	m = {}
	for i in arr:
		if i not in m:
			m[i] = 0
		m[i] += 1
	for i in range(1, max(arr) + 2):
		if i not in m:
			if arr.count(i - 1) > 1:
				return 'YES'
			return 'NO'
		if m[i] <= 1:
			return 'NO'
	return 'NO'
tc = int(input())
for t in range(tc):
	print(solve())


import math
t = int(input())
while t > 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	memo = {}
	for i in range(n + 1):
		memo[i] = 0
	for x in arr:
		memo[x] += 1
	b = 0
	for i in range(n + 1):
		if memo[i] == 0:
			break
		elif memo[i] == 1:
			b = 1
	print('NO' if b else 'YES')
	t -= 1


from collections import Counter

def solve(n, arr):
	counts = Counter(arr)
	for i in range(max(arr) + 1):
		if counts[i] == 0:
			return 'YES'
		if counts[i] == 1:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	mx = max(a)
	count = [0] * (mx + 1)
	for i in a:
		count[i] += 1
	Flag = 0
	for i in range(len(count)):
		if count[i] == 0:
			break
		if count[i] == 1:
			Flag = 1
			break
	if Flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	l = [int(c) for c in input().split()]
	maxi = max(l)
	count = [0] * (max(l) + 1)
	for i in l:
		count[i] += 1
	Flag = 0
	for i in range(len(count)):
		if count[i] == 0:
			break
		if count[i] == 1:
			Flag = 1
			break
	if Flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n + 1):
		d[i] = 0
	for i in a:
		d[i] = d[i] + 1
	if d[0] == 0:
		print('YES')
	elif d[0] == 1:
		print('NO')
	else:
		c = 0
		for i in range(n + 1):
			if d[i] == 0:
				print('YES')
				c = 1
				break
			elif d[i] == 1:
				print('NO')
				c = 1
				break
		if c == 0:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = [0] * (2 * n)
	for j in x:
		y[j] += 1
	flag = True
	for j in range(n):
		if y[j] == 0:
			break
		elif y[j] == 1:
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	req = [0] * (n + 1)
	l = list(map(int, input().split()))
	for i in l:
		req[i] += 1
	for i in range(0, n + 1):
		if req[i] == 0:
			print('YES')
			break
		elif req[i] == 1:
			print('NO')
			break


t = int(input())
for i in range(t):
	N = int(input())
	arr = [int(i) for i in input().split()]
	dict = {}
	for i in arr:
		if i not in dict.keys():
			dict[i] = 1
		else:
			dict[i] += 1
	ans = 'YES'
	for i in range(N):
		if i not in dict.keys():
			break
		elif dict[i] == 1:
			ans = 'NO'
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = max(l)
	arr = [0] * (m + 1)
	for i in l:
		arr[i] += 1
	f = 1
	for i in arr:
		if i == 0:
			break
		elif i == 1:
			f = 0
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
T = int(input())
for i in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	max_ele = max(A)
	arr = [0] * (max_ele + 1)
	for p in A:
		arr[p] = arr[p] + 1
	flag = True
	for i in arr:
		if i == 0:
			break
		elif i == 1:
			flag = False
	if flag is True:
		print('YES')
	else:
		print('NO')


t = int(input())
for r in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[0] != 0:
		print('YES')
		continue
	if a[0] == 0 and a[1] != 0:
		print('NO')
		continue
	occurencies = {x: 0 for x in a}
	for x in range(len(a)):
		occurencies[a[x]] += 1
	y = True
	for x in range(n):
		if x not in occurencies:
			if occurencies[x - 1] < 2:
				y = False
			break
		if occurencies[x] < 2:
			y = False
			break
	if y:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	f = [0] * (2 * n + 1)
	for i in l:
		f[i] += 1
	mex = n + 1
	for i in range(2 * n + 1):
		if f[i] == 0:
			mex = i
			break
	if mex == 0:
		print('YES')
	else:
		flag = True
		for j in range(mex - 1, -1, -1):
			if f[j] == 1:
				flag = False
				break
		if flag:
			print('YES')
		else:
			print('NO')


num_tc = int(input())
for _ in range(num_tc):
	N = int(input())
	A = list(map(int, input().split()))
	if 0 not in A:
		print('YES')
	else:
		flag = True
		count_dict = [0] * (N + 1)
		for val in A:
			count_dict[val] += 1
		for val in range(N + 1):
			if count_dict[val] == 0:
				print('YES')
				break
			elif count_dict[val] == 1:
				print('NO')
				break


T = int(input())
for _ in range(T):
	N = int(input())
	count = [0 for _ in range(N + 1)]
	nums = [int(x) for x in input().split()]
	for n in nums:
		count[n] += 1
	answer = next((x for x in range(N) if count[x] < 2), None)
	if answer == None or count[answer] == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	max1 = max(list1)
	counts = {}
	for count in list1:
		counts[count] = counts.get(count, 0) + 1
	loda = 'YES'
	for i in range(max1 + 1):
		try:
			if counts[i] > 1:
				pass
			else:
				loda = 'NO'
				break
		except:
			loda = 'YES'
			break
	print(loda)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	count = {i: 0 for i in range(0, N + 1)}
	for i in range(2 * N):
		count[A[i]] += 1
	B = True
	for i in range(len(A)):
		if count[i] == 1:
			B = False
			break
		elif count[i] == 0:
			break
	if B == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	f = [0] * (2 * n)
	for i in range(2 * n):
		f[arr[i]] += 1
	k = 0
	for i in f:
		if i == 0:
			break
		elif i == 1:
			k = 1
			break
	if k == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	p = [0 for i in l]
	for i in range(len(p)):
		p[l[i]] += 1
	bol = 1
	for i in range(n * 2):
		if p[i] == 0:
			break
		if p[i] == 1:
			bol = 0
			break
	if bol:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	l = [0] * n
	for i in lst:
		if i < n:
			l[i] += 1
	for i in l:
		if i == 0:
			print('YES')
			break
		if i == 1:
			print('NO')
			break
	else:
		print('YES')