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



Sample input:
3
1 2 2


Sample output:
Yes

Submission status: Wrong Answer

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

if len(set(As)) >= 3:
    print("No")
    exit()
elif len(set(As)) == 1:
    print("Yes" if 1 <= As[0] <= N // 2 else "No")
    exit()
else:
    p, q = sorted(set(As))
    if p + 1 != q:
        print("No")
        exit()
    t = As.count(p)
    u = N - t
    if t + 1 <= q <= t + u // 2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
a = LIST()

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
a = LIST()

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:
	p, q = sorted(list(set(a)))
	if a.count(p) == p and q == p+1 and p <= N-2:
		print("Yes")
	else:
		print("No")

else:
	print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = [[a[0], 0]]
for i in a:
    if cnt[0][0] == i:
        cnt[0][1] += 1
    else:
        if len(cnt) == 1:
            cnt.append([i, 1])
        else:
            if cnt[1][0] == i:
                cnt[1][1] += 1
            else:
                print("No")
                exit()
cnt.sort()
if len(cnt) == 1:
    print("Yes" if cnt[0][0] <= cnt[0][1] // 2 or cnt[0][0] + 1 == n else "No")
else:
    print("Yes" if 1 <= cnt[1][0] - cnt[0][1] <= cnt[1][1] // 2 else "No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    M, m = max(a), min(a)
    c = a.count(m)
    C = a.count(M)
    
    if M == m:
        if n//2 >= m or m == n-1:
            judge = True
        else:
            judge = False
    else:
        if M - m > 1:
            judge = False
        elif m == 1 and c == 1:
            judge = True
        elif (n-c) >= C*2:
            judge = True
        else:
            judge = False
        
    
    print("Yes" if judge else "No")
    
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    M, m = max(a), min(a)
    c = a.count(m)
    C = a.count(M)
    
    if M == m:
        if n//2 >= m:
            judge = True
        else:
            judge = False
    else:
        if (n-c) >= C*2:
            judge = True
        else:
            judge = False
        
    
    print("Yes" if judge else "No")
    
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n=II()
	A=LI()


	A.sort()

	a=A[0]
	b=A[-1]

	ans="No"

	if b-a==0:
		if n==a+1 or n>=a*2:
			ans="Yes"

	elif b-a==1:
		aa=A.count(a)
		if 2*a-aa+2<=n:
			ans="Yes"




	print(ans)




















if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n=II()
	A=LI()


	A.sort()

	a=A[0]
	b=A[-1]

	ans="No"

	if b-a==0:
		if n==a+1 or n>=a*2:
			ans="Yes"

	elif b-a==1:
		if A[1]==b and n>=2*a+1:
			ans="Yes"
		else:
			aa=A.count(a)
			if aa==a and n>=a+2:
				ans="Yes"
			elif aa==a-1 and n>=a+3:
				ans="Yes"

	print(ans)




















if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n=II()
	A=LI()


	A.sort()

	a=A[0]
	b=A[-1]

	ans="No"

	if b-a==0:
		if n==a+1 or n>=a*2:
			ans="Yes"

	elif b-a==1:
		if A[1]==b and n>=2*a+1:
			ans="Yes"
		else:
			aa=A.count(a)
			if aa==a and n>=a+2:
				ans="Yes"

	print(ans)




















if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n=II()
	A=LI()


	A.sort()

	a=A[0]
	b=A[-1]

	ans="No"

	if b-a==0:
		if n==a+1 or n>=a*2:
			ans="Yes"

	elif b-a==1:
		if A[1]==b and n>=2*a+1:
			ans="Yes"

	print(ans)




















if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
if max(a) - min(a) >= 2:
    print("No")
    exit()
else:
    M = max(a)
    m = min(a)
    if M == m:
        if m <= N / 2 or m == N - 1:
            print("Yes")
        else:
            print("No")
    else:
        if a.count(m) >= M or a.count(M) < 2 * a.count(m):
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
amax=max(a)
amin=min(a)
if amax-amin>=2:
    print("No")
    exit()
elif amax==amin:
    if amax==n-1:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
ac=a.count(amin)
ad=n-ac
if (amax-ac)*2<=ad:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
M = max(a)
m = min(a)
if M > m + 1:
    print("No")
else:
    if M == m:
        if M == N-1:
            print("Yes")
        elif M*2 <= N:
            print("Yes")
        else:
            print("No")

    else:
        if a.count(M) > 2:
            print('No')
        else:
            # ai == m　ならば、ai以外にその色はない
            c = a.count(m)
            if (M - c) * 2 <= N-c and c < M:  # (M-c) -> 一人だけではない色の種類一人だけではないはずなので*2 したものよりも残りの人数が多いはず
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
M = max(a)
m = min(a)
if M > m + 1:
    print("No")
else:
    if M == m:
        if M == N-1:
            print("Yes")
        elif M*2 <= N:
            print("Yes")
        else:
            print("No")

    else:
        if a.count(M) > 2:
            print('No')
        else:
            # ai == m　ならば、ai以外にその色はない
            c = a.count(m)
            if (M - c) * 2 < N-c and c < M:  # (M-c) -> 一人だけではない色の種類一人だけではないはずなので*2 したものよりも残りの人数が多いはず
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(int(x) for x in input().split())

ma = max(A)
mi = min(A)

if ma - mi > 1:
    print("No")
    exit()

if ma == mi:
    if n >= ma * 2 or n == ma + 1:
        print("Yes")
    else:
        print("No")
    exit()

# ma = mi + 1
if A.count(mi) <= mi and A.count(ma) >= ma * 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ca=dict(Counter(a))
if len(ca.keys())>2:
  print('No')
elif len(ca.keys())==1:
  if 2*a[0]<=n or a[0]==n-1:
    print('Yes')
  else:
    print('No')
else:
  c=max(ca.keys())
  d=min(ca.keys())
  if c!=d+1:
    print('No')
  elif 2*(c-1)<=n-1 and ca[d]==1: #if 2*(ca[c]-1)<=n-1 and ca[d]==1:
    print('Yes')
  elif ca[d]==d:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ca=dict(Counter(a))
if len(ca.keys())>2:
  print('No')
elif len(ca.keys())==1:
  if 2*a[0]<=n:
    print('Yes')
  else:
    print('No')
else:
  c=max(ca.keys())
  d=min(ca.keys())
  print('y')
  """

  if 2*(c-1)<=n-1 and ca[d]==1: #if 2*(ca[c]-1)<=n-1 and ca[d]==1:
    print('Yes')
  else:
    print('No')
  """

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ca=dict(Counter(a))
if len(ca.keys())>2:
  print('No')
elif len(ca.keys())==1:
  if 2*a[0]<=n:
    print('Yes')
  else:
    print('No')
else:
  c=max(ca.keys())
  d=min(ca.keys())
  if 2*(c-1)<=n-1 and ca[d]==1:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ca=dict(Counter(a))
if len(ca.keys())>2:
  print('No')
elif len(ca.keys())==1:
  if 2*a[0]<=n:
    print('Yes')
  else:
    print('No')
else:
  c=max(ca.keys())
  d=min(ca.keys())
  if 2*(ca[c]-1)<=n-1 and ca[d]==1:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
#たかだか2通りの値のみ
#1通りならば、全員違うかどの色も二匹以上
#2通りならば、小さい値の猫の防止は唯一
#大きい値の猫の防止は2匹以上

from collections import Counter
ac = Counter(a)
if len(ac)>2:
    print("No")
    exit()
if len(ac)==1:
    for k in ac:
        if k==n-1 or 2*k<=n:#ac[k]ではない
            print("Yes")
        else:
            print("No")
    exit()

cl = [ac[k] for k in ac]

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
#ac[mx]がy、ac[mn]がx、mxがA
#たぶん//2をやるのが割り切れない場合の処理が煩雑になってよくないのでやめ
if 2*(mx-ac[mn])>ac[mx] or ac[mn]>=mx:##等号ないらしい
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
#たかだか2通りの値のみ
#1通りならば、全員違うかどの色も二匹以上
#2通りならば、小さい値の猫の防止は唯一
#大きい値の猫の防止は2匹以上

from collections import Counter
ac = Counter(a)
if len(ac)>2:
    print("No")
    exit()
if len(ac)==1:
    for k in ac:
        if k==n-1 or 2*k<=n:#ac[k]ではない
            print("Yes")
        else:
            print("No")
    exit()

cl = [ac[k] for k in ac]

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
#ac[mx]がy、ac[mn]がx、mxがA
#たぶん//2をやるのが割り切れない場合の処理が煩雑になってよくないのでやめ
if 2*(mx-ac[mn])>ac[mx] or ac[mx]>=mx:##等号ないらしい
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
#たかだか2通りの値のみ
#1通りならば、全員違うかどの色も二匹以上
#2通りならば、小さい値の猫の防止は唯一
#大きい値の猫の防止は2匹以上

from collections import Counter
ac = Counter(a)
if len(ac)>2:
    print("No")
    exit()
if len(ac)==1:
    for k in ac:
        if k==n-1 or 2*k<=n:#ac[k]ではない
            print("Yes")
        else:
            print("No")
    exit()

cl = [ac[k] for k in ac]

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
#ac[mx]がy、ac[mn]がx、mxがA
#たぶん//2をやるのが割り切れない場合の処理が煩雑になってよくないのでやめ
if 2*(mx-ac[mn])>ac[mx] or ac[mx]<=mx:##等号ないらしい,mxのほう
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
#たかだか2通りの値のみ
#1通りならば、全員違うかどの色も二匹以上
#2通りならば、小さい値の猫の防止は唯一
#大きい値の猫の防止は2匹以上

from collections import Counter
ac = Counter(a)
if len(ac)>2:
    print("No")
    exit()
if len(ac)==1:
    for k in ac:
        if k==n-1 or 2*k<=n:#ac[k]ではない
            print("Yes")
        else:
            print("No")
    exit()

cl = [ac[k] for k in ac]

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
#ac[mx]がy、ac[mn]がx、mxがA
#たぶん//2をやるのが割り切れない場合の処理が煩雑になってよくないのでやめ
if 2*(mx-ac[mn])>ac[mx] or ac[mx]<=mn:##等号ないらしい
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
#たかだか2通りの値のみ
#1通りならば、全員違うかどの色も二匹以上
#2通りならば、小さい値の猫の防止は唯一
#大きい値の猫の防止は2匹以上

from collections import Counter
ac = Counter(a)
if len(ac)>2:
    print("No")
    exit()
if len(ac)==1:
    for k in ac:
        if k==n-1 or k<=n//2:#ac[k]ではない
            print("Yes")
        else:
            print("No")
    exit()

cl = [ac[k] for k in ac]

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
#ac[mx]がy、ac[mn]がx、mxがA
#たぶん//2をやるのが割り切れない場合の処理が煩雑になってよくないのでやめ
if 2*(mx-ac[mn])>ac[mx] or ac[mx]<=mn:##等号ないらしい
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
#たかだか2通りの値のみ
#1通りならば、全員違うかどの色も二匹以上
#2通りならば、小さい値の猫の防止は唯一
#大きい値の猫の防止は2匹以上

from collections import Counter
ac = Counter(a)
if len(ac)>2:
    print("No")
    exit()
if len(ac)==1:
    for k in ac:
        if k==n-1 or k<=n//2:#ac[k]ではない
            print("Yes")
        else:
            print("No")
    exit()

cl = [ac[k] for k in ac]

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
#ac[mx]がy、ac[mn]がx、mxがA
#たぶん//2をやるのが割り切れない場合の処理が煩雑になってよくないのでやめ
if 2*(mx-ac[mn])>=ac[mx] or ac[mx]<=mn:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
def answer(x):
  print(x)
  exit()

N=int(input())
A=list(map(int,input().split()))
if len(set(A))>=3:
  answer('No')
if len(set(A))==1:
  if N//2>=A[0] or A[0]==N-1:
    answer('Yes')
  else:
    answer('No')
A.sort()
if A[0]+1<A[-1]:
  answer('No')
X=1
for i in range(N-1):
  if A[i]==A[i+1]:
    X+=1
  else:
    break
if X==N-1:
  answer('No')
if X+1<=A[-1]<=X+(N-X+1)//2:
  answer('Yes')
else:
  answer('No')

Submission status: Wrong Answer

Solution code:
print('No')

Submission status: Wrong Answer

Solution code:
def answer(x):
  print(x)
  exit()

N=int(input())
A=list(map(int,input().split()))
if len(set(A))>=3:
  answer('Yes')
if len(set(A))==1:
  if N//2>=A[0] or A[0]==N-1:
    answer('Yes')
  else:
    answer('No')
A.sort()
if A[0]+1<A[-1]:
  answer('No')
X=1
for i in range(N-1):
  if A[i]==A[i+1]:
    X+=1
  else:
    break
if X==N-1:
  answer('No')
if X+1<=A[-1]<=X+(N-X+1)//2:
  answer('Yes')
else:
  answer('No')

Submission status: Wrong Answer

Solution code:
def answer(x):
  print(x)
  exit()

N=int(input())
A=list(map(int,input().split()))
if len(set(A))>=3:
  answer('Yes')
if len(set(A))==1:
  if N//2>=A[0] or A[0]==N-1:
    answer('Yes')
  else:
    answer('No')
A.sort()
if A[0]+1<A[-1]:
  answer('No')
X=1
for i in range(N-1):
  if A[i]==A[i+1]:
    X+=1
  else:
    break
if X==N-1:
  answer('No')
if X+1<=A[-1]<=X+(N-X-1)//2:
  answer('Yes')
else:
  answer('No')

Submission status: Wrong Answer

Solution code:
def answer(x):
  print(x)
  exit()

N=int(input())
A=list(map(int,input().split()))
if len(set(A))>=3:
  answer('Yes')
if len(set(A))==1:
  if N//2>=A[0] or A[0]==N-1:
    answer('Yes')
  else:
    answer('No')
A.sort()
if A[0]+1<A[-1]:
  answer('No')
X=1
for i in range(N-1):
  if A[i]==A[i+1]:
    X+=1
  else:
    break
if X==N-1:
  answer('No')
if X+1<=A[-1]<=X+(N-X)//2:
  answer('Yes')
else:
  answer('No')

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
A.sort()


def solve():
    K = A[-1]
    if A[0] == K:
        return K == N - 1 or (K >= 1 and 2 * K <= N)
    if A[0] != K - 1:
        return False
    counter = collections.Counter(A)
    d = counter[K - 1]
    if K < d:
        return False
    if N - d <= 1:
        return False
    return 2 * (K - d) <= N - d


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

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
A.sort()


def solve():
    K = A[-1]
    if A[0] == K:
        return K == N - 1 or 2 * K <= N

    if A[0] != K - 1:
        return False
    counter = collections.Counter(A)
    d = counter[K - 1]
    if K < d:
        return False
    if N - d <= 1:
        return False
    return 2 * (K - d) <= N - d


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

Submission status: Wrong Answer

Solution code:
yes="Yes"
no="No"
n=int(input())
a=list(map(int,input().split()))
if max(a)-min(a)>1:exit(print(no))
if a==[a[0]]*n:
  if a[0]==n-1:print(yes)
  elif 2*a[0]<=n:print(yes)
  else:print(no)
else:
  mi=a.count(min(a))
  ma=n-mi
  if mi<max(a):print(yes)
  elif 2*(max(a)-mi)<=ma:print(yes)
  else:print(no)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
if len(cnt)>2:
    print("No")
    quit()
if len(cnt)==1:
    if n==a[0]+1 or a[0]*2<=n:
        print("Yes")
    else:
        print("No")
    quit()
a.sort()
syo=cnt[a[0]]
dai=cnt[a[-1]]
maru=a[-1]-syo
if maru<=0:
    print("No")
elif maru*2<=dai:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = sorted(map(int, readline().split()))

def main(A):
    N = len(A)
    if A[0] == A[-1]:
        x = A[0]
        return x == N - 1 or 2 * x <= N
    if A[0] + 1 != A[-1]:
        return False
    a, b = A[0], A[-1]
    full = b
    unique = A.count(a)
    people, color = N - unique, A[-1] - unique
    return color > 1 and 2 * color <= people

print('Yes' if main(A) else 'No')

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = sorted(map(int, readline().split()))

def main(A):
    N = len(A)
    if A[0] == A[-1]:
        x = A[0]
        return x == N - 1 or 2 * x <= N
    if A[0] + 1 != A[-1]:
        return False
    a, b = A[0], A[-1]
    full = b
    unique = sum(x == a for x in A)
    return N - unique >= 2 * a

print('Yes' if main(A) else 'No')

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
s=max(a)-min(a)
if s>=2:
    print("No")
elif s==0:
    if a[0]==n-1 or n//a[0]>=2:
        print("Yes")
    else:
        print("No")
else:
    a.sort()
    x=bisect.bisect_right(a,a[0])
    if x<=a[-1]<=x+(n-x)//2 and n-x>=2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
s=max(a)-min(a)
if s>=2:
    print("No")
elif s==0:
    if a[0]==n-1 or n/a[0]>=2:
        print("Yes")
    else:
        print("No")
else:
    a.sort()
    x=bisect.bisect_right(a,a[0])
    if x==a[-1] or (x<=a[-1]<=x+(n-x)//2 and n-x>=2):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
s=max(a)-min(a)
if s>=2:
    print("No")
elif s==0:
    if a[0]==n-1 or n/a[0]>=2:
        print("Yes")
    else:
        print("No")
else:
    a.sort()
    x=bisect.bisect_right(a,a[0])
    if x<=a[-1]<=x+(n-x)//2 and n-x>=2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ma, mi = max(a), min(a)
if ma - mi > 1:
    print(-1)
elif ma - mi == 1:
    z, o = 0, 0
    for i in range(n):
        if a[i] == ma - 1:
            z += 1
        else:
            o += 1
    if z < ma and ma - z <= o / 2:
        print("Yes")
    else:
        print("No")
else:
    if ma == n - 1 or ma <= n / 2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if max(a)-1<min(a):exit(print("No"))
if len(set(a))==1:
  m=a[0]
  if m==n-1 or 2*m<=n:print("Yes")
  else:print("No")
else:
  x=a.count(min(a))
  y=n-x
  if x<max(a) and 2*(max(a)-x)<=y:print("Yes")
  else:print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if max(a)-2<=min(a):exit(print("No"))
if len(set(a))==1:
  m=a[0]
  if m==n-1 or 2*m<=n:print("Yes")
  else:print("No")
else:
  x=a.count(min(a))
  y=n-x
  if x<max(a) and 2*(max(a)-x)<=y:print("Yes")
  else:print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
*a, = map(int, input().split())
v = sum(a)

for n in range(N+1)[::-1]:
    if v-(N-1)*n>=0 and (v-(N-1)*n)%N==0:
        k = (v-(N-1)*n)//N
        if (k==0 and n==N) or (k and (N-n)%k==0 and (N-n)//k>1):
            print("Yes")
            break
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
*a, = map(int, input().split())
v = sum(a)

for n in range(N+1)[::-1]:
    if v-(N-1)*n>=0 and (v-(N-1)*n)%N==0:
        k = (v-(N-1)*n)//N
        if (k==0 and n==N) or (k and (N-n)%k==0):
            print("Yes")
            break
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
m, n = max(a), min(a)
if m - n > 1 or m >= N:
    print('No')
elif m - n == 0:
    print('Yes' if n == N - 1 or n * 2 <= N else 'No')
else:
    print('No' if a.count(n) == n else 'Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
m, n = max(a), min(a)
if m - n > 1 or m >= N:
    print('No')
elif m - n == 0:
    print('No' if n == N - 1 or n * 2 <= N else 'Yes')
else:
    print('Yes' if a.count(n) == n else 'No')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
m, n = max(a), min(a)
if m - n > 1 or m >= N:
    print('No')
elif m - n == 0:
    if n == N - 1 or n * 2 <= N:
        print('Yes')
    else:
        print('No')
elif m - n == 1:
    if a.count(n) == 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + 1) == p2 and p2 <= N - 2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + 1) == p2 and A[p1] <= N - 2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + 1) == p2 and A[p2] >= 2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + 1) == p2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + 1) >= p2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if p2 - p1 == 1 and (A[p1] + A[p2] // 2) >= p2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if [p1, p2] == [1, 2] and A[p1] + A[p2] * 2 <= N else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    p = list(A.keys())[0]
    print('Yes' if 2 * p <= N or p == N - 1 else 'No')
    exit()

p1, p2 = sorted(A.keys())
print('Yes' if [p1, p2] == [1, 2] and A[1] == 1 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    print('Yes' if list(A.keys())[0] == N - 1 or list(A.keys())[0] == 2 else 'No')
    exit()

p1, p2 = A.keys()
assert -1
print('Yes' if abs(p1 - p2) == 1 and max(p1, p2) <= N - 1 and A[min(p1, p2)] == 1 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))

if len(A.keys()) >= 3:
    print('No')
    exit()

if len(A.keys()) == 1:
    print('Yes' if list(A.keys())[0] == N - 1 or list(A.keys())[0] == 2 else 'No')
    exit()

p1, p2 = A.keys()
print('Yes' if abs(p1 - p2) == 1 and max(p1, p2) <= N - 1 and A[min(p1, p2)] == 1 else 'No')