Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $n$ types of candies, there are $a_i$ candies of the type $i$ ($1 \le i \le n$).

Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose any of them). To get the maximum pleasure from eating, Vlad does not want to eat two candies of the same type in a row.

Help him figure out if he can eat all the candies without eating two identical candies in a row.


-----Input-----

The first line of input data contains an integer $t$ ($1 \le t \le 10^4$) — the number of input test cases.

The following is a description of $t$ test cases of input, two lines for each.

The first line of the case contains the single number $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of types of candies in the package.

The second line of the case contains $n$ integers $a_i$ ($1 \le a_i \le 10^9$) — the number of candies of the type $i$.

It is guaranteed that the sum of $n$ for all cases does not exceed $2 \cdot 10^5$.


-----Output-----

Output $t$ lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).


-----Examples-----

Input
6
2
2 3
1
2
5
1 6 2 4 3
4
2 2 2 1
3
1 1000000000 999999999
1
1
Output
YES
NO
NO
YES
YES
YES


-----Note-----

In the first example, it is necessary to eat sweets in this order:

a candy of the type $2$, it is the most frequent, now $a = [2, 2]$;

a candy of the type $1$, there are the same number of candies of the type $2$, but we just ate one, now $a = [1, 2]$;

a candy of the type $2$, it is the most frequent, now $a = [1, 1]$;

a candy of the type $1$, now $a = [0, 1]$;

a candy of the type $2$, now $a = [0, 0]$ and the candy has run out.

In the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.

In the third example, first of all, a candy of the type $2$ will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type $2$ again.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		n = int(sys.stdin.readline())
		arr = list(map(int, sys.stdin.readline().split()))
		val = sum(arr) / n
		if n == 1:
			if arr[0] > 1:
				print('NO')
			else:
				print('YES')
		else:
			mx1 = mx2 = -sys.maxsize
			for i in arr:
				if i >= mx1:
					mx2 = mx1
					mx1 = i
				elif i >= mx2:
					mx2 = i
			if mx1 - mx2 > 1:
				print('NO')
			else:
				print('YES')
main()


t = int(input())
p = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		if a[0] > 1:
			p.append('NO')
		else:
			p.append('YES')
	else:
		s = max(a)
		a.remove(s)
		l = max(a)
		if abs(l - s) > 1:
			p.append('NO')
		else:
			p.append('YES')
print(*p, sep='\n')


import sys, math
input = sys.stdin.readline
for t in range(int(input())):
	u = int(input())
	arr = list(map(int, input().split()))
	x = max(arr)
	if x - 1 in arr or x - 1 == 0 or arr.count(x) > 1:
		print('YES')
	else:
		print('NO')


t = int(input())
ans = []
for i in range(int(t)):
	n = int(input())
	a = list(map(int, input().strip().split()))
	a.append(0)
	l = max(a)
	a.remove(max(a))
	sl = max(a)
	d = int(l) - int(sl)
	if l == sl or d == 1:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = max(l)
	if x - 1 in l or x - 1 == 0 or l.count(x) > 1:
		print('YES')
	else:
		print('NO')


n = int(input())
c = [0 for i in range(n)]
for i in range(n):
	a = int(input())
	b = sorted(map(int, input().split()))
	if a > 1:
		c[i] = b[a - 1] - b[a - 2]
	else:
		c[i] = b[0]
for i in range(n):
	if c[i] < 2:
		print('YES')
	else:
		print('NO')


t = int(input())
cases = []
numberofcan = []
for i in range(t):
	numberofcan.append(int(input()))
	cases.append(list(map(int, input().strip().split())))
for i in range(len(numberofcan)):
	types = numberofcan[i]
	candies = cases[i]
	if types == 1 and candies[0] > 1:
		print('NO')
	elif types == 1 and candies[0] == 1:
		print('YES')
	else:
		candies.sort()
		if len(candies) > 1:
			if candies[-1] - candies[-2] > 1:
				print('NO')
			else:
				print('YES')


def solve(arr):
	if len(arr) == 1:
		if arr[0] > 1:
			return False
		else:
			return True
	arr = sorted(arr, reverse=True)
	if arr[0] - arr[1] > 1:
		return False
	return True
t = int(input())
cases = []
for i in range(t):
	input()
	cases.append(list(map(int, input().split(' '))))
ans = []
for case in cases:
	ans.append(solve(case))
for answer in ans:
	print('YES' if answer else 'NO')


from sys import stdin
import math

def main():
	t = int(stdin.readline())
	for i in range(t):
		types = int(stdin.readline())
		A = list(map(int, stdin.readline().split()))
		if types <= 1 and A[0] > 1:
			print('NO')
			continue
		if types == 1 and A[0] == 1:
			print('YES')
			continue
		A.sort()
		if A[-1] - A[-2] > 1:
			print('NO')
		else:
			print('YES')
main()


for s in [*open(0)][2::2]:
	l = sorted(map(int, s.split()))
	if len(l) < 2:
		print('YNEOS'[l[0] > 1::2])
		continue
	print('YNEOS'[l[-1] - l[-2] > 1::2])


numberTestCase = int(input())
resultList = []
for turnCaseTest in range(numberTestCase):
	numberTypeCandies = int(input())
	typeCandies = input()
	typeCandies = typeCandies.split(' ')
	typeCandies = [int(element) for element in typeCandies]
	if numberTypeCandies == 1:
		if typeCandies[0] == 1:
			resultList.append('YES')
		else:
			resultList.append('NO')
		continue
	biggestElement = max(typeCandies)
	typeCandies.remove(biggestElement)
	secondLargestElement = max(typeCandies)
	if biggestElement - secondLargestElement <= 1:
		resultList.append('YES')
	else:
		resultList.append('NO')
for result in resultList:
	print(result)


t = int(input())
op = []
for i in range(t):
	n = int(input())
	s = list(map(int, input().split(' ')))
	if n == 1 and s[0] > 1:
		op.append('NO')
	elif n == 1 and s[0] == 1:
		op.append('YES')
	elif n > 1:
		s = sorted(s)
		m = s[-1]
		max_2 = s[-2]
		diff = m - max_2
		if diff == 1 or diff == 0:
			op.append('YES')
		else:
			op.append('NO')
for i in op:
	print(i)


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	flag = False
	row = False
	n = int(input())
	lst = sorted(list(map(int, input().split())), reverse=True)
	if n == 1:
		if lst[0] > 1:
			flag = True
	elif lst[0] - 1 > lst[1]:
		flag = True
	if flag or row:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def solve(n, arr):
	if n == 1:
		print('YES') if arr[0] <= 1 else print('NO')
		return
	mv = max(arr)
	count = {}
	for num in arr:
		if num not in count:
			count[num] = 0
		count[num] += 1
	if count[mv] > 1:
		print('YES')
	elif mv - 1 in count:
		print('YES')
	else:
		print('NO') if len(count) > 1 else print('YES')
	return
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(n, arr)


def ispossible(arr, size):
	if size >= 2 and arr[-1] - arr[-2] >= 2 or (size == 1 and arr[0] != 1):
		return False
	else:
		return True
n = int(input())
l = []
for i in range(n):
	s = int(input())
	arr = list(map(int, input().split(' ')))
	l.append(arr)
for i in range(n):
	l[i].sort()
	if ispossible(l[i], len(l[i])):
		print('YES')
	else:
		print('NO')


T = int(input())
q = []
for i in range(T):
	n = int(input())
	a = [int(i) for i in input().split()]
	q.append((n, a))

def solve(n, a):
	if n == 1:
		if a[0] > 1:
			print('NO')
		else:
			print('YES')
		return
	m1 = max(a)
	a.remove(m1)
	m2 = max(a)
	if m1 - m2 <= 1:
		print('YES')
	else:
		print('NO')
for (n, a) in q:
	solve(n, a)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	max1 = max2 = 0
	if l != []:
		max1 = max(l)
	l.remove(max1)
	if l != []:
		max2 = max(l)
	if max1 - max2 <= 1:
		print('YES')
	else:
		print('NO')


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(0, t):
	n = inp()
	middle_index = math.floor(n / 2)
	arr = inlt()
	arr.sort()
	if n == 1:
		if arr[0] == 1:
			print('YES')
		else:
			print('NO')
	else:
		(a, b) = arr[-2:]
		if b - a <= 1:
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	u = int(input())
	l = list(map(int, input().split()))
	x = max(l)
	if x - 1 in l or x - 1 == 0 or l.count(x) > 1:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline

def get_string():
	return stdin.readline().strip()

def main():
	for _ in range(int(input())):
		n = int(input())
		c = list(map(int, input().split()))
		c.sort(reverse=True)
		if n == 1:
			if c[0] == 1:
				print('YES')
			else:
				print('NO')
		elif c[0] - c[1] <= 1:
			print('YES')
		else:
			print('NO')
main()


import sys
input = sys.stdin.readline

def ii():
	return int(input())

def iit():
	return map(int, input().split())

def iil():
	return list(map(int, input().split()))

def si():
	return input()[:-1]

def solve():
	n = ii()
	a = iil()
	if n == 1:
		print('YES' if a[0] == 1 else 'NO')
		return
	a.sort()
	(x, y) = (a[-1], a[-2])
	if abs(x - y) > 1:
		print('NO')
		return
	print('YES')
t = ii()
for i in range(t):
	solve()


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	candies = list(map(int, sys.stdin.readline().strip().split()))
	candies.sort()
	if n == 1:
		print('YES') if candies[0] == 1 else print('NO')
	else:
		print('YES') if candies[n - 1] - candies[n - 2] <= 1 else print('NO')


import sys
from os import path
try:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
	tests = int(sys.stdin.readline().strip('\n '))
	for i in range(tests):
		n = int(sys.stdin.readline().strip('\n '))
		plan = False
		nums = list(map(int, sys.stdin.readline().strip('\n ').split(' ')))
		if len(nums) == 1:
			if nums[0] == 1:
				plan = True
		else:
			nums.sort()
			if nums[-1] <= nums[-2] + 1:
				plan = True
		if plan:
			print('YES')
		else:
			print('NO')
except Exception as e:
	print(e)


for s in [*open(0)][2::2]:
	(*_, x, y) = (0, *sorted(map(int, s.split())))
	print('YNEOS'[y > x + 1::2])


t = int(input())
cases = []
for i in range(t):
	input()
	s = [int(i) for i in input().split(' ')]
	cases.append(s)
for case in cases:
	max_1 = 0
	max_2 = 0
	for v in case:
		if v > max_1:
			max_2 = max_1
			max_1 = v
		elif v > max_2:
			max_2 = v
	if max_1 - max_2 > 1:
		print('NO')
	else:
		print('YES')


t = int(input())
output = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	max = 0
	max2 = 0
	for j in range(n):
		if arr[j] > max:
			max2 = max
			max = arr[j]
		elif arr[j] > max2:
			max2 = arr[j]
	if max - 1 > max2:
		output.append('NO')
	else:
		output.append('YES')
for i in range(t):
	print(output[i])


test = eval(input())
final = []
for i in range(test):
	num = input()
	candy = list(map(int, input().split()))
	if len(candy) == 1:
		if candy[0] > 1:
			final.append('NO')
			continue
		else:
			final.append('YES')
			continue
	candy.sort()
	if candy[-1] - candy[-2] > 1:
		final.append('NO')
	else:
		final.append('YES')
for item in final:
	print(item)


n = int(input())
ans = []
da = 'YES'
no = 'NO'
for i in range(n):
	s = []
	r = int(input())
	s = list(map(int, input().split()))
	s = sorted(s)
	if len(s) >= 2 and s[-1] - s[-2] >= 2:
		ans.append(no)
	elif len(s) == 1:
		if s[0] == 1:
			ans.append(da)
		else:
			ans.append(no)
	else:
		ans.append(da)
for i in range(len(ans)):
	print(ans[i])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if N == 1 and arr[0] >= 2:
		print('NO')
	elif N == 1 and arr[0] == 1:
		print('YES')
	elif N >= 2 and arr[0] - arr[1] >= 2:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	c = int(input())
	a = sorted(list(map(int, input().split())))
	if c == 1:
		if a[0] == 1:
			print('YES')
		else:
			print('NO')
	elif a[-1] - a[-2] > 1:
		print('NO')
	else:
		print('YES')


t = int(input())
lst = []
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if n == 1 and a[0] != 1:
		lst.append('NO')
	elif n == 1 and a[0] == 1:
		lst.append('YES')
	elif a[-1] - a[-2] < 2:
		lst.append('YES')
	else:
		lst.append('NO')
for i in lst:
	print(i)


from sys import stdin, setrecursionlimit
from itertools import *
from collections import *
lines = stdin.readlines()
lines.reverse()
setrecursionlimit(10 ** 8)

def input():
	return lines.pop().strip('\n')
t = int(input())
while t:
	n = int(input())
	can = list(map(int, input().split()))
	can.sort(reverse=True)
	if n == 1 and can[0] > 1:
		print('NO')
	elif n > 1 and can[0] > can[1] + 1:
		print('NO')
	else:
		print('YES')
	t -= 1


numQ = int(input())
for _ in range(numQ):
	n = int(input())
	a_i = list(map(int, input().split()))
	a_i.sort()
	foo = True
	if n > 1:
		if a_i[n - 1] - a_i[n - 2] > 1:
			foo = False
	elif n == 1:
		if a_i[0] != 1:
			foo = False
	if foo:
		print('YES')
	else:
		print('NO')


def p_no():
	print('NO')

def p_yes():
	print('YES')
for _ in range(int(input())):
	n = int(input())
	cip_virkne = list(map(int, input().split()))
	cip_virkne.sort()
	if n == 1:
		if cip_virkne[0] > 1:
			p_no()
		else:
			p_yes()
	elif cip_virkne[-1] - cip_virkne[-2] > 1:
		p_no()
	else:
		p_yes()


import sys
import math
from sys import stdin, stdout

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

def get_int():
	return int(input())

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

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def main():
	for t in range(get_int()):
		n = int(input())
		arr = get_ints_in_list()
		if n == 1:
			if arr[0] == 1:
				print('YES')
			else:
				print('NO')
			continue
		arr.sort()
		if arr[n - 1] > arr[n - 2] + 1:
			print('NO')
		else:
			print('YES')
main()


for x in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.sort()
	if len(ls) == 1:
		if ls[0] == 1:
			print('YES')
		else:
			print('NO')
	elif ls[-1] - ls[-2] > 1:
		print('NO')
	else:
		print('YES')


def is_candies(input_: str):
	arr = input_.split(' ')
	arr = sorted([int(i) for i in arr], reverse=True)
	if len(arr) == 1 and arr[0] == 1:
		print('YES')
	elif len(arr) <= 1 or arr[0] - arr[1] >= 2:
		print('NO')
	else:
		print('YES')
	return None
t = int(input())
list_inputs = []
while t > 0:
	n = input()
	arr_str = input()
	list_inputs.append(arr_str)
	t -= 1
for input_ in list_inputs:
	is_candies(input_)


def answer(n, lt):
	lt = sorted(lt)
	if n == 1:
		if lt[0] == 1:
			return 'YES'
		else:
			return 'NO'
	if lt[n - 1] - lt[n - 2] > 1:
		return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	txt = input()
	lt = list(map(int, txt.split(' ')))
	print(answer(n, lt))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	if len(arr) == 1:
		if arr[0] == 1:
			print('YES')
		else:
			print('NO')
	if n >= 2:
		a = arr[-1]
		b = arr[-2]
		if a - b == 1 or a - b == -1 or a - b == 0:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if len(a) == 1 and a[0] >= 2:
		print('NO')
	elif len(a) == 1 and a[0] == 1:
		print('YES')
	elif a[-1] - a[-2] <= 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for m in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if n != 1:
		if l[n - 1] - l[n - 2] <= 1:
			print('YES')
		else:
			print('NO')
	elif l[0] > 1:
		print('NO')
	else:
		print('YES')


for t in range(int(input())):
	n = int(input())
	lks = list(map(int, input().split()))
	lks.append(0)
	lks.sort()
	print('YES') if lks[-1] - lks[-2] <= 1 else print('NO')


def helper(a, b):
	if abs(a - b) == 1:
		print('Yes')
	else:
		print('No')
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	a = sorted(arr)
	ans = 'NO'
	if n == 1 and a[0] > 1:
		ans = 'NO'
	elif a[n - 1] - 2 >= a[n - 2]:
		ans = 'NO'
	else:
		ans = 'YES'
	print(ans)


t = int(input())
while t:
	l = int(input())
	s = list(map(int, input().split()))
	s.sort()
	if l == 1 and s[0] > 1 or (l > 1 and s[-1] - s[-2] >= 2):
		print('NO')
	else:
		print('YES')
	t = t - 1


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if n == 1 and a[n - 1] > 1:
		print('NO')
	elif a[n - 1] - a[n - 2] > 1:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for i in range(0, t):
	n = int(input())
	c = list(map(int, input().split()))
	c.append(0)
	c.sort()
	if c[-1] - c[-2] >= 2:
		print('NO')
		continue
	print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		if a[0] == 1:
			print('YES')
		else:
			print('NO')
	else:
		a.sort()
		if a[-1] - a[-2] <= 1:
			print('YES')
		else:
			print('NO')


def vlad_can_eat(arr):
	high1 = 0
	high2 = 0
	for a in arr:
		if a > high1:
			high2 = high1
			high1 = a
		elif a > high2:
			high2 = a
	if high1 - high2 > 1:
		return 'NO'
	return 'YES'

def main():
	num_in = int(input())
	for _ in range(num_in):
		input()
		nums = [int(i) for i in input().split(' ')]
		print(vlad_can_eat(nums))
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if n == 1:
		if a[0] > 1:
			print('NO')
		else:
			print('YES')
	else:
		a.sort(reverse=True)
		if a[0] - a[1] >= 2:
			print('NO')
		else:
			print('YES')


p = int(input())
for _ in range(p):
	num = int(input())
	li = list(map(int, input().split()))
	li.sort()
	if num == 1:
		if li[0] == 1:
			print('YES')
		else:
			print('NO')
	elif li[num - 1] - li[num - 2] > 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if n == 1:
		if a[0] == 1:
			print('YES')
			continue
		else:
			print('NO')
			continue
	if a[0] - a[1] > 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	b.sort()
	if len(b) == 1:
		if b[0] == 1:
			print('YES')
		else:
			print('NO')
	elif b[-1] - b[-2] <= 1:
		print('YES')
	else:
		print('NO')


def solve(n, arr):
	if n == 1:
		if arr[0] > 1:
			return 'NO'
		else:
			return 'YES'
	diff = arr.pop(arr.index(max(arr))) - max(arr)
	if diff > 1:
		return 'NO'
	else:
		return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	print(solve(n, a))


testCases = int(input())
for i in range(testCases):
	types = int(input())
	candies = [int(x) for x in input().split()]
	candies.sort()
	if types == 1:
		if candies[0] > 1:
			print('NO')
		else:
			print('YES')
		continue
	if candies[-2] + 1 < candies[-1]:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	data = list(map(int, input().split()))
	if n <= 1 and data[0] != 1:
		print('NO')
		continue
	elif n <= 1 and data[0] == 1:
		print('YES')
		continue
	max1 = max(data)
	data.remove(max1)
	max2 = max(data)
	if max1 - max2 >= 2:
		print('NO')
	else:
		print('YES')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		if n == 1:
			if a[0] == 1:
				print('YES')
			else:
				print('NO')
		else:
			a = sorted(a)
			if a[-1] - a[-2] > 1:
				print('NO')
			else:
				print('YES')
main()


def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())

def printYES():
	print('YES')

def printNO():
	print('NO')
for t in range(int(input())):
	n = ni()
	a = li()
	if n == 1:
		if a[0] == 1:
			printYES()
		else:
			printNO()
		continue
	a.sort()
	if a[-1] - a[-2] > 1:
		printNO()
	else:
		printYES()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if n == 1 and l[0] > 1 or (n > 1 and l[-1] - l[-2] > 1):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	if n == 1:
		if arr[0] >= 2:
			print('NO')
		else:
			print('YES')
	elif arr[-1] - arr[-2] >= 2:
		print('NO')
	else:
		print('YES')


import math as m
i = input()
inp = []
for a in range(0, int(i)):
	input()
	inp.append([int(x) for x in input().split()])
for arr in inp:
	arr.sort()
	if len(arr) == 1:
		if arr[0] < 2:
			print('YES')
		else:
			print('NO')
	elif arr[-1] - arr[-2] < 2:
		print('YES')
	else:
		print('NO')


import sys
inputt = sys.stdin.readline
t = int(inputt())
for _ in range(t):
	n = int(inputt())
	candies = list(map(int, inputt().split()))
	can_eat = True
	while max(candies):
		idx = candies.index(max(candies))
		candies.sort()
		if len(candies) == 1:
			if candies[0] >= 2:
				can_eat = False
				break
			else:
				can_eat = True
				break
		elif len(candies) == 2:
			if abs(candies[0] - candies[1]) >= 2:
				can_eat = False
				break
			else:
				can_eat = True
				break
		else:
			max1 = candies[-1]
			max2 = candies[-2]
			if max1 - max2 >= 2:
				can_eat = False
				break
			else:
				can_eat = True
				break
	if can_eat:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1 and l[0] > 1:
		print('NO')
	elif n == 1 and l[0] == 1:
		print('YES')
	else:
		t = max(l)
		if t - 1 in l:
			print('YES')
		elif l.count(t) > 1:
			print('YES')
		else:
			print('NO')


cases = int(input(''))
for i in range(cases):
	types = int(input(''))
	candies = list(map(int, input().split()))
	candies.sort()
	if types == 1:
		if candies[0] > 1:
			print('NO')
			continue
	if candies[types - 1] - candies[types - 2] > 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	input()
	one = list(map(int, input().split()))
	one.append(0)
	one.sort(reverse=True)
	print('YES' if one[0] - one[1] < 2 else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	if n == 1:
		if a[0] > 1:
			print('NO')
		else:
			print('YES')
		continue
	if a[-2] + 1 < a[-1]:
		print('NO')
	else:
		print('YES')


import math
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	if len(A) > 2:
		A.sort()
		if abs(A[-1] - A[-2]) > 1:
			print('NO')
		else:
			print('YES')
	else:
		if len(A) == 2:
			if abs(A[0] - A[1]) > 1:
				print('NO')
			else:
				print('YES')
		if len(A) == 1:
			if A[0] > 1:
				print('NO')
			else:
				print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	if len(a) == 1:
		if a[0] == 1:
			print('YES')
		else:
			print('NO')
	elif a[-1] == a[-2] or a[-1] - a[-2] == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
A = []
for i in range(t):
	n = int(input())
	a = [int(p) for p in input().split()]
	A.append(a)
for i in range(t):
	arr = A[i]
	if len(arr) == 1:
		if arr[0] == 1:
			print('YES')
		else:
			print('NO')
	else:
		arr.sort()
		if arr[len(arr) - 1] - arr[len(arr) - 2] <= 1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		if l[0] > 1:
			print('NO')
		else:
			print('YES')
		continue
	l.sort()
	if l[-1] - l[-2] > 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if n == 1 and sum(l) >= 2:
		print('NO')
	elif n == 1 and sum(l) == 1:
		print('YES')
	else:
		c1 = l[-1]
		c2 = l[-2]
		if abs(c1 - c2) >= 2:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		if a[0] == 1:
			print('YES')
		else:
			print('NO')
		continue
	a = sorted(a, reverse=True)
	f = False
	if a[0] == a[1] or a[0] - 1 == a[1]:
		print('YES')
	else:
		print('NO')


t1 = int(input())
for i in range(t1):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	b = 0
	if a[n - 1] - a[n - 2] > 1 or (len(a) < 2 and a[0] > 1):
		print('NO')
	else:
		print('YES')