Problem:
 Score : 700 points    Problem Statement There are N cats.
We number them from 1 through N .  Each of the cats wears a hat.
Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."  Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.      Constraints  2 ≤ N ≤ 10^5  1 ≤ a_i ≤ N-1         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_N       Output Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.        Sample Input 1 3
1 2 2      Sample Output 1 Yes  For example, if cat 1 , 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.       Sample Input 2 3
1 1 2      Sample Output 2 No  From the remark of cat 1 , we can see that cat 2 and 3 wear hats of the same color.
Also, from the remark of cat 2 , we can see that cat 1 and 3 wear hats of the same color.
Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3 .       Sample Input 3 5
4 3 4 3 4      Sample Output 3 No       Sample Input 4 3
2 2 2      Sample Output 4 Yes       Sample Input 5 4
2 2 2 2      Sample Output 5 Yes       Sample Input 6 5
3 3 3 3 3      Sample Output 6 No

Solution (Python):
N = int( input())
A = list( map( int, input().split()))
K = max(A)
L = min(A)
if K == L:
    if K == N-1 or 2*K <= N:
        print('Yes')
    else:
        print('No')
elif abs(K-L) == 1:
    x = K*N - sum(A)
    if 2*K - x <= N and x < K:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ma = max(A)
mi = min(A)
if ma-mi > 1:
    print("No")
    exit()
if ma-mi == 0 and N-1 == ma:
    print("Yes")
    exit()
d = N-ma
cma = A.count(ma)
if d+1 <= cma <= d*2:
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    if (max(a) - min(a)) > 1:
        print("No")
        return 0
    minor = a.count(min(a))
    if n != minor:
        major = n-minor

        mini = minor+1
        maxi = minor + (major//2)
        if mini <= max(a) and max(a) <= maxi:
            print("Yes")
        else:
            print("No")
    else:
        mini = 1
        maxi = minor//2
        if mini <= max(a) and max(a) <= maxi or max(a) == n-1:
            print("Yes")
        else:
            print("No")


main()

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = Counter(a)
if len(c)>2 or a[0]+1<a[-1]: print("No")
elif len(c)==1:
	if a[0]+1==n or n>=2*a[0]: print("Yes")
	else: print("No")
else:
	x,y = c[a[-1]],c[a[0]]
	if y+1<=a[-1]<=x//2+y: print("Yes")
	else: print("No")

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = inpl()
MIN = min(aa)
MAX = max(aa)

if MAX-MIN > 1:
	print('No')
elif MAX == MIN:
	if MAX == N-1:
		print('Yes')
	elif MAX <= N//2:
		print('Yes')
	else:
		print('No')
else: 
	n_MIN = n_MAX = 0
	for a in aa:
		if a == MIN: n_MIN += 1
		if a == MAX: n_MAX += 1
	x_min = n_MIN + 1
	x_max = n_MIN + n_MAX//2
	if x_min <= MAX <= x_max:
		print('Yes')
	else:
		print('No')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
sa = max(a)-min(a)
if sa>1:
  print("No")
  exit()
elif sa == 0:
  if max(a) == n-1:
    print("Yes")
  elif max(a) <= n//2:
    print("Yes")
  else:
    print("No")
else:
  alone = a.count(min(a))
  pair = a.count(max(a))
  ceil = alone + pair//2
  floor = alone + 1
  if floor <= max(a) and max(a)<=ceil:
    print("Yes")
  else:
    print("No")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
Min = min(a)
Max = max(a)
if Max - Min > 1:
	print("No")
elif Max == Min:
	if a[0] == n - 1 or a[0] <= n // 2:
		print("Yes")
	else:
		print("No")
else:
	c_M = a.count(Max)
	c_m = n - c_M
	if c_m < Max <= c_m + c_M // 2:
		print("Yes")
	else:
		print("No")

Solution (Python):
n=int(input())
s=input().split()
l=[int(s[i]) for i in range(n)]
l.sort()
if l[0]==l[-1]:
    if l[0]<=n//2 or l[0]==n-1:
        print("Yes")
    else:
        print("No")
elif l[-1]-l[0]>1:
    print("No")
else:
    a=l.count(l[0])
    b=l.count(l[-1])
    if a+1<=l[-1]<=a+b//2:
        print("Yes")
    else:
        print("No")

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
ma=max(A)
mi=min(A)
ans=True

if ma-mi > 1:
  ans=False
elif ma==mi:
  if ma!=N-1 and ma*2 > N:
    ans=False
else:
  uniq=ma*N - sum(A)
  no_uni=N-uniq
  if no_uni==1:
    ans=False
  else:
    if uniq >= ma or 2*(ma-uniq) > no_uni:
      ans=False
if ans:
  print("Yes")
else:
  print("No")

Solution (Python):

import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

N = int(input())
a = list(map(int, input().split()))

min_ = min(a)
max_ = max(a)

if max_ > min_ + 1:
    print("No")
    exit()

if min_ == max_:
    if min_ == N-1:
        print("Yes")
        exit()
    if 2*min_ <= N:
        print("Yes")
        exit()
    print("No")
    exit()
else:
    
    count_min = a.count(min_)
    count_max = a.count(max_)
    if count_min >= max_:
        print("No")
        exit()
    if count_min + 2*(max_ - count_min) <= N:
        debug("hoge")
        print("Yes")
        exit()
    print("No")

Solution (Python):
n = int(input())
cats = list(map(int,input().split()))
flag = True
p, q = max(cats), min(cats)
x = cats.count(p)
y = cats.count(q)
if p - q >= 2:
    flag = False
elif p == q:
    if p != n - 1 and p * 2 > n:
        flag = False
else:
    if y >= p or (p-y) * 2 > x:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):

from collections import Counter
def inpl(): return map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

C = Counter(A)

if len(C) >= 3:
    print("No")
elif len(C) == 1:
    for k, v in C.items():
        if k == N-1 or N >= 2*k:
            print("Yes")
        else:
            print("No")
else:
    k = sorted(C.keys())[0]
    v = C[k]
    X = N - v
    if (k+1-v) * 2 <= C[k+1] and v <= k:
        print("Yes")
    else:
        print("No")

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

if len(set(A)) == 1:
    if A[0] == N-1 or A[0] <= N // 2:
        print("Yes")
    else:
        print("No")
elif len(set(A)) == 2:
    M = max(A)
    m = min(A)
    if M-m != 1:
        print("No")
    else:
        if A.count(m) < M and 2*(M-A.count(m)) <= A.count(M):
            print("Yes")
        else:
            print("No")
else:
    print("No")

Solution (Python):


import sys, math, copy




HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    ma = max(ai)
    k = 0
    for a in ai:
        if a < ma - 1:
            return False
        if a == ma:
            k += 1

    if k == n:
        if ma + 1 == n:
            return True
        elif 1 <= ma <= n // 2:
            return True
        else:
            return False

    if k >= 2 and 1 <= ma - n + k <= k // 2:
        return True
    return False

print("Yes" if main() else "No")

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

if len(set(a))>=3:
  print('No')
elif len(set(a))==1:
  if a[0]==n-1 or 1 <= a[0] <=n//2:
    print('Yes')
  else:
    print('No')
else:
  m=max(a)
  s=min(a)
  c=sum([1 for i in a if i==m])
  if n-m+1<=c<=n-(m-(n-m)) and s==m-1:
    print('Yes')
  else:
    print('No')

Solution (Python):
N = int(input())
*A, = map(int, input().split())
B = {}
for a in A:
    B[a] = B.get(a, 0) + 1
if len(B) == 2:
    p, q = sorted(B)
    if p+1 == q:
        if B[q] != 1 and B[p] + 1 <= q <= B[p] + B[q] // 2:
            print('Yes')
            exit(0)
elif len(B) == 1:
    p, = B
    if p <= N // 2 or p == N-1:
        print('Yes')
        exit(0)
print('No')

Solution (Python):
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

if len(ctr) > 2:
    print('No')
    exit()

if len(ctr) == 1:
    k = src[0]
    print('Yes' if 2*k <= N or k == N-1 else 'No')
    exit()

min_k, max_k = min(ctr.keys()) ,max(ctr.keys())
min_v, max_v = ctr[min_k], ctr[max_k]
if min_v > min_k:
    print('No')
else:
    print('Yes' if (max_k - min_v)*2 <= max_v else 'No')

Solution (Python):
from collections import Counter


def solve(n, cnt):
    if len(cnt) == 1:
        a = next(iter(cnt))
        return (a == n - 1) or (1 <= a <= n // 2)
    a1, a2 = min(cnt), max(cnt)
    if a2 - a1 > 1:
        return False
    c1, c2 = cnt[a1], cnt[a2]
    return c1 < a2 and a2 - c1 <= c2 // 2


n = int(input())
cnt = Counter(map(int, input().split()))

print('Yes' if solve(n, cnt) else 'No')

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def solve(N, l):
    a, b = min(l), max(l)
    if b - a > 1:
        return False
    if a == b:
        if a == N - 1:
            return True
        return N >= (a * 2)

    num_a = l.count(a)

    return num_a < b and num_a + 2 * (b - num_a) <= N


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    print("Yes" if solve(N, a_list) else "No")

if __name__ == '__main__':
    main()

Solution (Python):

def solve(a):
    a = sorted(a)
    if a[0] + 2 <= a[-1]:
        return False
    if a[0] == a[-1]:
        return a[0] + 1 == len(a) or 2 * a[-1] <= len(a)
    x = a.count(a[0])
    return x < a[-1] and x + 2 * (a[-1] - x) <= len(a)
n = int(input())
a = list(map(int, input().split()))
print(['No', 'Yes'][solve(a)])

Solution (Python):
n=int(input())
a=map(int,input().split())
c=[0]*n
col=0
mx=0
for i in a:
	if c[i]==0:
		col+=1
	c[i]+=1
	mx=max(mx,i)
if col>2:
	print("No")
elif col==1:
	if mx==n-1 or 2*mx<=n:
		print("Yes")
	else:
		print("No")
else:
	x,y=c[mx-1],c[mx]
	if x+1<=mx and mx<=x+y/2:
		print("Yes")
	else:
		print("No")

Solution (Python):
N = int(input())
ls = list(map(int, input().split()))
o = max(ls)
p = min(ls)


if (o == p):
    if (o == (N - 1) or (N >= 2 * o)):
        print('Yes')
    else:
        print('No')
elif ((o - p) == 1):
    u = len([ x for x in ls if x == p])
    if ((o - u) > 0 and 2 * (o - u) <= (N - u)):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
import sys
if __name__ == "__main__":
    N = int(input())
    evidences = list(map(int, input().split()))
    evidences = list(sorted(evidences))
    unique_evidence = set(evidences)
    if (evidences[-1] - evidences[0] > 1):
        print ("No")
        sys.exit()
    if (len(unique_evidence) == 1):
        group = evidences[0];
        
        if (group == N - 1):
            print ("Yes")
            sys.exit()
        if (N - 2 * group < 0):
            print ("No")
            sys.exit()
        print ("Yes")
        sys.exit()
    
    min_val = min(evidences)
    max_val = max(evidences)

    min_val_cnt = 0
    max_val_cnt = 0
    for val in evidences:
        if (val == min_val):
            min_val_cnt += 1
        else:
            max_val_cnt += 1
    
    if (max_val_cnt <= 1):
        print ("No")
        sys.exit()
    
    rest = N
    rest -= min_val_cnt

    min_group = min_val_cnt + 1
    max_group = min_val_cnt + (max_val_cnt // 2)
    if min_group <= evidences[-1] and evidences[-1] <= max_group:
        print ("Yes")
        sys.exit()
    print ("No")

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

mx = max(a)
mn = min(a)
if (mx-mn) >= 2 :
    print('No')
elif mx == mn == N-1 :
    print('Yes')
elif mx == mn :
    if N >= mx*2 :
        print('Yes')
    else :
        print('No')
elif (mx-mn) == 1 :
    mx_cnt = 0
    mn_cnt = 0
    for i in range(N) :
        if a[i] == mx :
            mx_cnt += 1
        else :
            mn_cnt += 1

    if mn < mn_cnt :
        print('No')
    elif mx_cnt >= (mx-mn_cnt)*2:
        print('Yes')
    else :
        print('No')

Solution (Python):
N = int(input())
A = [int(x) for x in input().split(' ')]
maxA = max(A)
minA = min(A)

if maxA - minA > 1:
    print('No')
elif maxA == minA:
    if (N >= 2 * maxA) or maxA == N - 1:
        print('Yes')
    else:
        print('No')
else:
    sum = 0
    for i in A:
        if i == minA:
            sum += 1
    if sum >= maxA:
        print('No')
    elif 2 * (maxA - sum) <= N - sum:
        print('Yes')
    else:
        print('No')

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mina=min(a)
maxa=max(a)
if mina == maxa:
    if 2*maxa <= n or maxa == n-1:
        print('Yes')
    else:
        print('No')
elif maxa - mina == 1:
    cntmin = a.count(mina)
    if maxa - cntmin <= 0:
        print('No')
    elif n + cntmin >= 2 * maxa:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Solution (Python):
import numpy as np

N=int(input())
line=input()
arr=np.array([int(ai) for ai in line.split()])

maxNum=np.max(arr)
minNum=np.min(arr)

if maxNum==minNum:
    if maxNum==(N-1):
        print("Yes")
    else:
        C=maxNum
        numUniq=0
        if numUniq>=2*C-N and numUniq<C:
            print("Yes")
        else:
            print("No")
elif maxNum==minNum+1:
    C=maxNum
    numUniq=(arr==minNum).sum()
    if numUniq>=2*C-N and numUniq<C:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

A_set = sorted(set(A))
if len(A_set) == 1:
    print("Yes" if A_set[0] <= N // 2 or A_set[0] == N - 1 else "No")
elif len(A_set) == 2 and A_set[0] + 1 == A_set[1]:
    cnt_min = A.count(A_set[0])
    cnt_max = N - cnt_min
    if cnt_min <= A_set[0] and cnt_min + 1 <= A_set[1] <= cnt_min + cnt_max // 2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
import sys

if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    min_num = min(a)
    max_num = max(a)

    if max_num - min_num >= 2:
        print("No")
    elif max_num == min_num :
        if max_num == N -1 or 2*max_num <= N:
            print("Yes")
        else:
            print("No")
    else:
        x = a.count(min_num)
        y = a.count(max_num)
        if x < max_num and 2 * (max_num - x) <= y:
            print("Yes")
        else:
            print("No")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
dic = {}
amin = n - 1
amax = 1
for ai in a:
    if ai in dic:
        dic[ai] += 1
    else:
        dic[ai] = 1
    amin = min(amin, ai)
    amax = max(amax, ai)

if 1 < amax - amin:
    print('No')
elif amin == amax:
    if a[0] == n - 1 or 2 * a[0] <= n:
        print('Yes')
    else:
        print('No')
else:
    if dic[amax] == 1:
        print('No')
    elif dic[amin] + 1 <= amax <= dic[amin] + dic[amax] // 2:
        print('Yes')
    else:
        print('No')

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c] += 1
    t = sorted(list(d.keys()))
    if t[-1] - t[0] > 1:
        return 'No'
    if len(t) == 1:
        if t[0] == n - 1:
            return 'Yes'
        if t[0] > n / 2.0:
            return 'No'
        return 'Yes'
    b = t[1] - d[t[0]]
    n2 = d[t[1]]
    if n2 == 2 and b == n2 - 1:
        return 'Yes'
    if b < 1:
        return 'No'
    if b >= n2 - 2:
        return 'No'
    if b > n2 / 2.0:
        return 'No'

    return 'Yes'


print(main())

Solution (Python):

import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return (N, a)


def solve(N, a):
    a_max = max(a)
    a_min = min(a)
    ans = ""
    if a_max - a_min > 1:
        ans = "No"
    elif a_max - a_min == 1:
        n_alone = a.count(a_min)
        n_group = a.count(a_max)
        if n_alone < a_max and 2 * (a_max - n_alone) <= n_group:
            ans = "Yes"
        else:
            ans = "No"
    elif a_max - a_min == 0:
        if a[0] == N - 1 or a[0] * 2 <= N:
            ans = "Yes"
        else:
            ans = "No"

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):
length = int(input())
target = [int(n) for n in input().split(" ")]
if max(target) - min(target) > 1:
    print("No")
elif max(target) >= length:
    print("No")
elif max(target) - min(target) == 1 and (target.count(min(target)) == min(target) and target.count(max(target)) > 1 or (target.count(min(target)) <= min(target) and target.count(max(target)) // 2 >= max(target) - target.count(min(target)) )  ):
    print("Yes")
elif max(target) - min(target) == 0 and ( (length % 2 == 0 and min(target) * 2 <= length) or (length % 2 == 1 and 2 * (min(target) - 1) + 3 <= length)  or min(target) + 1 == length):
    print("Yes")
else:
    print("No")

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(): return "".join(list(map(str, ans)))
 
 
N = ri()
a = rli()
ma = max(a)
mi = min(a)
if(ma - mi > 1):
    print("No")
elif(ma - mi == 1):
    l_ma = a.count(ma)
    l_mi = a.count(mi)
    if(ma <= l_mi):
        print("No")
    elif(l_mi + l_ma/2 >= ma):
        print("Yes")
    else:
        print("No")
else:
    if(a[0] == N-1):
        print("Yes")
    elif(N/a[0] >= 2):
        print("Yes")
    else:
        print("No")

Solution (Python):
import collections as co
n = int(raw_input())
aa = map(int, raw_input().split())

c = co.Counter(aa).most_common()

if len(c) > 2:
  print 'No'
  exit()

if len(c) == 1:
  cc = c[0][0]
  if cc == n-1:
    print 'Yes'
  elif cc*2 <= n:
    print 'Yes'
  else:
    print 'No'
  exit()

l = c[0]
s = c[1]
if l[0] < s[0]:
  l,s = s,l

if l[0] != s[0] + 1:
  print 'No'
  exit()

if (n-l[0])+1 <= l[1] <= (n-l[0])*2:

  print 'Yes'
else:
  print 'No'

Solution (Python):
n=int(raw_input())
a=map(int,raw_input().split())
if max(a)-min(a)>=2:
    print "No"
    exit()
if max(a)==min(a):
    if max(a)==n-1:
        print "Yes"
    elif max(a)*2>n :
        print "No"
    else:
        print "Yes"
    exit()
cntmx=a.count(max(a))
cntmn=a.count(min(a))
if cntmn>=max(a):
    print "No"
elif (max(a)-cntmn)*2>n-cntmn:
    print "No"
else:
    print "Yes"

Solution (Python):
N = int(input())
la = list(map(int, input().split()))

m = max(la)
if (m == N - 1) and (len(set(la)) == 1):
    print('Yes')
else:
    d = N - m
    cnt = la.count(m)
    if ((cnt >= d + 1) and (cnt <= 2 * d)):
        if cnt < N:
            if (len(set(la)) == 2) and min(la) == m - 1:
                print('Yes')
            else:
                print('No')
        else:
            print('Yes')
    else:
        print('No')

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
C = max(a)
ans = ""

if C - min(a) > 1:
	ans = "No"
elif C == min(a):
	if N >= 2 * C or N == C + 1:
		ans = "Yes"
	else:
		ans = "No"
else:
	if C - a.count(C - 1) > 0 and N - a.count(C - 1) >= 2 * (C - a.count(C - 1)):
		ans = "Yes"
	else:
		ans = "No"
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))

l.sort()
ans = "Yes"
count = 1
if l[0] == l[-1]:
  if ((n // 2) < l[0]) and (l[0] != 1) and (l[0] != n - 1):
    ans = "No"
elif l[-1] - l[0] >= 2:
    ans = "No"
else:
  for i in range(n-1):
    if l[i+1] - l[i] == 0:
      count += 1
    elif l[i+1] - l[i] == 1:
      break
  umax = count + (n - count) // 2
  if (l[-1] > umax) or (l[-1] <= count):
    ans = "No"

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

seta = set(a)
if len(seta) == 1:
    if a[0] in (0, N-1) or a[0] <= N // 2:
        print("Yes")
    else:
        print("No")
elif len(seta) == 2:
    a1 = min(seta)
    a2 = max(seta)
    counta1 = a.count(a1)
    if a2 != a1 + 1:
        print("No")
    elif counta1 < a2 and counta1 + 2 * (a2 - counta1) <= N:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

is_ok = True

color_num = a[0]
unique = []
for i, a_i in enumerate(a[1:], 1):
    if a_i < len(unique):
        is_ok = False
        break
    if a_i == color_num - 1:
        unique.append(i)
    elif a_i != color_num:
        is_ok = False
        break
if len(unique) >= color_num:
    if len(unique) == color_num and len(unique) == N:
        is_ok = True
    else:
        is_ok = False
if N // color_num == 1:
    unique_num_min = color_num - (N % color_num)
    if len(unique) < unique_num_min:
        is_ok = False

color_num = a[0] + 1
unique = [0]
if not is_ok:
    is_ok = True
    for i, a_i in enumerate(a[1:], 1):
        if a_i < len(unique):
            is_ok = False
            break
        if a_i == color_num - 1:
            unique.append(i)
        elif a_i != color_num:
            is_ok = False
            break
    if len(unique) >= color_num:
        if len(unique) == color_num and len(unique) == N:
            is_ok = True
        else:
            is_ok = False
    if N // color_num == 1:
        unique_num_min = color_num - (N % color_num)
        if len(unique) < unique_num_min:
            is_ok = False

if is_ok:
    print('Yes')
else:
    print('No')

Solution (Python):
N=int(input())

a=[int(i) for i in input().split()]
a.sort()



if a[-1]-a[0]>1:
	print("No")
else:
	
	for i in range(1,N):
		
		if a[i]!=a[0]:
			if 1<=a[-1]-i<=int((N-i)/2):
				print("Yes")
			else:
				print("No")
			break
	else:
		
		if 1<=a[0]<=int(N/2) or a[0]==N-1:
			print("Yes")
		else:
			print("No")

Solution (Python):
import sys
N=int(input())
a=[int(i) for i in input().split()]
a.sort()

if a[N-1]-a[0]>1:
  print("No")
  sys.exit()
if a[0]==N-1:
  print("Yes")
  sys.exit()
if a[N-1]==1:
  print("Yes")
  sys.exit()
if a[0]==a[N-1]:
  if 2*a[0]<=N:
    print("Yes")
  else:
    print("No")
  sys.exit()

count=a.index(a[N-1])
if count+1<=a[N-1] and a[N-1]<=count+int((N-count)/2):
  print("Yes")
else:
  print("No")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()

cnt = 0
for i in range(n):
    if a[i] == a[0]:
        cnt = i+1
    else:
        break

if a[-1] - a[0] > 1:
    print('No')
    exit()
elif a[-1] - a[0] == 1:
    actual = a[-1]
    if actual >= n:
        print('No')
    elif cnt <= actual - 1 and actual <= cnt  + (n - cnt) // 2:
        print('Yes')
    else:
        print('No')
    exit()
elif a[-1] - a[0] == 0:
    solve = False
    actual = a[0]
    if n >= actual * 2 or n-1 == actual:
        solve = True
    if solve:
        print('Yes')
    else:
        print('No')
    exit()
else:
    print('No')

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())
As = list(map(int, input().split()))

mn = min(As)
mx = max(As)
if mx > mn + 1:
    print('No')
elif mx == mn:
    if 1 <= mx <= N // 2 or mx == N - 1:
        print('Yes')
    else:
        print('No')
else:
    mn_num = As.count(mn)
    mx_num = As.count(mx)
    k = mn + 1 - mn_num
    
    if mx_num == 0:
        if k == 0:
            print('Yes')
        else:
            print('No')
    else:
        if 1 <= k <= (mx_num // 2):
            print('Yes')
        else:
            print('No')

Solution (Python):
import sys

N=int(raw_input())
a=map(int,raw_input().split())

T=0
for i in a:
    if i != a[0]:
        if i - a[0] >= 2 or a[0] - i >= 2:
            print "No"
            sys.exit()
        T=max(i,a[0])
        break

if T == 0:
    if a[0] <= N/2 or a[0] == N-1:
        print "Yes"
    else:
        print "No"
    sys.exit()

uni=0
nu=0
for i in a:
    if i==T:
        nu+=1
    else:
        uni+=1

if T>=uni+1 and T<=uni+nu/2:
    print "Yes"
else:
    print "No"

Solution (Python):


import sys
import math

N, = map(int, sys.stdin.readline().rstrip().split())
a_s = list(map(int, sys.stdin.readline().rstrip().split()))

mina = min(a_s)
maxa = max(a_s)
if (maxa - mina > 1):
    print("No")
    exit(0)
if(maxa == mina):
    if(maxa <= N//2 or N == (maxa+1)):
        print("Yes")
    else:
        print("No")
    exit(0)
if maxa - mina == 1:
    alones = sum(a == mina for a in a_s)
    
    
    
    if  (N-alones) >= (maxa - alones) * 2 and alones < maxa:
        print("Yes")
    else:
        print("No")
    exit(0)

raise Exception()
exit(0)

Solution (Python):
import sys
from collections import Counter




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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


yes, no = 'Yes', 'No'


def solve(n, a):
    s = set(a)
    c = Counter(a)
    if len(s) == 1:
        a = list(s)[0]
        n_colors = a + 1
        if n_colors == n:
            return yes
        n_colors = a
        if 2 * n_colors <= n:
            return yes
    if len(s) == 2:
        a, b = sorted(s)
        if a + 1 == b:
            n_colors = b
            appear_once = c[a]
            appear_twice_or_more = n_colors - appear_once
            if appear_once < n_colors:
                if c[b] >= 2 * appear_twice_or_more:
                    return yes
    return no

n = read_int()
a = read_int_list()
res = solve(n, a)
print(res)

Solution (Python):
import sys

n = int(raw_input())
a = list(map(int, raw_input().split()))

def no():
	print "No"
	exit(0)

def yes():
	print 'Yes'
	exit(0)

a = list(sorted(a))
if a[0] == a[-1] and a[0] == n - 1:
	yes()

X = max(a)
alone = 0
many = 0

for e in a:
	if e != X and e != X - 1:
		no()
	if e == X - 1:
		alone += 1
	else:
		many += 1

rest = X - alone

if rest < 0:
	no()

if rest == 0 and many > 0:
	no()

if rest * 2 > many:
	no()

yes()

Solution (Python):
from collections import Counter
N = int(input())

a= list(map(int,input().split()))


X = Counter(a)

min_val = min(a)
max_val = max(a)
if not min_val == max_val-1 and not min_val==max_val:
    print("No")
    exit()
if max_val==min_val and max_val == N-1:
    
    print("Yes")
    exit()


unique_cat = X[min_val] if min_val!=max_val else 0


last_cat =  N- unique_cat
last_colors = max_val - unique_cat



if last_cat>0 and last_colors <=0:
    print("No")
elif  0< 2*last_colors <= last_cat:
    print("Yes")

else:
    print("No")

Solution (Python):
n = int(input())
array = [int(x) for x in input().split(' ')]
maxa = max(array)
mina = min(array)
if maxa - mina > 1:
    print('No')
elif maxa == mina:
    if n >= 2 * maxa:
        print('Yes')
    elif maxa == n-1:
        print('Yes')
    else:
        print('No')
else:
    sum = 0
    for j in array:
        if j == mina:
            sum += 1
    if sum >= maxa:
        print('No')
        exit()
    if 2*(maxa - sum) <= n - sum:
        print('Yes')
    else:
        print('No')

Solution (Python):

def read_data():
    N = int(input())
    As = list(map(int, input().split()))
    return N, As

def solve(N, As):
    x = max(As)
    y = min(As)
    if x - y > 1:
        return False
    if x == y:
        if x == N - 1:
            return True
        if x * 2 <= N:
            return True
        return False
    n_solo = As.count(y)
    if x < n_solo + 1:
        return False
    n_group = x - n_solo
    if n_group * 2 <= N - n_solo:
        return True
    return False

N, As = read_data()
if solve(N, As):
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(raw_input())
a = map(int, raw_input().split())
b = max(a)
c = min(a)
if b - c > 1:
    print "No"
elif b == c:
    print "Yes" if b == n - 1 or 2 * b <= n else "No"
else:
    t = sum(c == x for x in a)
    if t >= b:
        print "No"
    else:
        print "Yes" if (b - t) * 2 <= n - t else "No"