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())
A=list(map(int,input().split()))
min_,max_=min(A),max(A)

def f(n,k):
    return n%k==2 if k>0 else False

ans=None
if max_-min_ > 1:
    ans=False
elif max_-min_ == 1:
    k=max_
    nk=len([a for a in A if a==max_])
    nk1=N-nk
    ans=f(nk,k-nk1)
else:
    ans=f(N,min_)
print("Yes" if ans is True else "No")

Submission status: Wrong Answer

Solution code:
N=int(input())
*A, = map(int,input().split())
B = {}
for a in A: B[a] = B.get(a,0)+1
m = min(B)
M = max(B)
if m+1<M:
    print("NO")
    exit()
def check(n):
    b0 = B.setdefault(n-1,0)
    b1 = B.setdefault(n,0)
    if b1==0:
        return b0==n
    else:
        return 1<= n-b0 <= b1//2
if m+1==M:
    ans = check(M)
else:
    ans = check(m) or check(m+1)
print("YES" if ans else "NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
amax=max(arr)
amin=min(arr)
if amax-amin>=2:
  print('No')
elif amax-amin==0:
  flag=False
  for i in range(n):
    if arr[i]!=n-1:
      break
  else:
    flag=True
  for i in range(n):
    if 2*arr[i]>n:
      break
  else:
    flag=True
  if flag==True:
    print('Yes')
  else:
    print('No')
elif amax-amin==1:
  cnt1=0
  cnt2=0
  for i in range(n):
    if arr[i]==amax:
      cnt1+=1
    else:
      cnt2+=1
  if cnt1<amax and 2*(amax-cnt1)<=cnt2:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
amax=max(arr)
amin=min(arr)
if amax-amin>=2:
  print('No')
elif amax-amin==0:
  flag=False
  for i in range(n):
    if arr[i]!=n-1:
      break
  else:
    flag=True
  for i in range(n):
    if 2*arr[i]>n:
      break
  else:
    flag=True
  if flag==True:
    print('Yes')
  else:
    print('No')
elif amax-amin==1:
  cnt1=0
  cnt2=0
  for i in range(n):
    if arr[i]==amax-1:
      cnt1+=1
    else:
      cnt2+=1
  if cnt1<amax and 2*(amax-cnt1)<cnt2:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
amax=max(arr)
amin=min(arr)
if amax-amin>=2:
  print('No')
elif amax-amin==0:
  flag=False
  for i in range(n):
    if arr[i]!=n-1:
      break
  else:
    flag=True
  for i in range(n):
    if 2*arr[i]>n:
      break
  else:
    flag=True
  if flag==True:
    print('Yes')
  else:
    print('No')
elif amax-amin==1:
  cnt1=0
  cnt2=0
  for i in range(n):
    if arr[i]==amax:
      cnt1+=1
    else:
      cnt2+=1
  if cnt1<amax and 2*(amax-cnt1)<cnt2:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

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

# Yesならば aの任意の2要素の差は高々1である
# 小さい方の値を発言している猫はそれぞれ異なる帽子を被る必要がある
# 大きい方の値を発言している猫は同じ帽子を被る猫が少なくとも他に一匹存在する必要がある
m = len(set(a))
k = min(a)
ans = (
    'Yes' if m == 1 and (N >= 2 * k or N == k + 1) or
    m == 2 and 2 * (k + 1) - N <= sum(x == k for x in a) <= k else
    'No'
)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = [ int(it) for it in input().split() ]
pma = max(li)
pmi = min(li)

def chk(n):
  import collections as col
  pn = sum([1 if it==n else 0 for it in li])
  pm = sum([1 if it==n-1 else 0 for it in li])
  x = n-pm
  if ( pn//2 >= x and x>=0 and pn != 1):
    return True
  else:
    return False
  
flag = False
if ( pma - pmi > 1 ):
  flag =False
elif (pma == pmi):
  flag = chk(pma) | chk(pma+1)
else:
  flag = chk(pma)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
li = [ int(it) for it in input().split() ]
pma = max(li)
pmi = min(li)

def chk(n):
  import collections as col
  pn = sum([1 if it==n else 0 for it in li])
  pm = sum([1 if it==n-1 else 0 for it in li])
  x = n-pm
  print (n,pn,pm,x)
  if ( pn//2 >= x and x>=0 and pn != 1):
    return True
  else:
    return False
  
flag = False
if ( pma - pmi > 1 ):
  flag =False
elif (pma == pmi):
  flag = chk(pma) | chk(pma+1)
else:
  flag = chk(pma)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if max(a)-min(a)>1:
    print("No")
else:
    b=a.count(max(a))
    c=n-b
    if c==0:
        if max(a)==n-1 or max(a)>=2*b:
            print("Yes")
        else:
            print("No")
    else:
        if c<max(a) and 2*(max(a)-c)<=b:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]

cnt = Counter(a)
if len(cnt) == 1:
    if 1 in cnt or n-1 in cnt:
        print("Yes")
    else:
        print("No")
elif len(cnt) == 2:
    color_num = max(cnt)
    # Cout can be 2 sequential number
    if color_num - 1 not in cnt:
        print("No") 
        exit()
    if cnt[color_num-1] <= color_num - 1 and cnt[color_num-1] >= 2*color_num - n:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]

cnt = Counter(a)
if len(cnt) == 1:
    if 1 in cnt or n-1 in cnt:
        print("Yes")
    else:
        print("No")
elif len(cnt) == 2:
    color_num = max(cnt)
    # Cout can be 2 sequential number
    if color_num - 1 not in cnt:
        print("No") 
    if cnt[color_num-1] <= color_num - 1 and cnt[color_num-1] >= 2*color_num - n:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
K=A[0]
x=0
y=0
for i in range(N):
    if A[i]!=K and A[i]!=K+1:
        print('No')
        sys.exit()
    if A[i]==K:
        x+=1
    elif A[i]==K+1:
        y+=1

if x==N and x >=2*K:
    print('Yes')
    sys.exit()
if x==N and N==K+1:
    print('Yes')
    sys.exit()
if x==K and y>=2:
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
#https://img.atcoder.jp/agc016/editorial.pdf
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = 'YES'
  alone = 0
  group = 0
  if max(a) - min(a) >= 2: ans = 'NO'
  
  elif max(a) - min(a) == 1:
   for i in a:
     if i == max(a)-1 : alone += 1
     else: group += 1
   if alone < max(a) and 2*(max(a)-alone)<= group: pass
   else: ans = 'NO'
  
  
  elif max(a) - min(a) == 0:
    if a[0] == n-1 or 2*a[0] <= n:
      pass
    else: ans = 'NO'
  return ans

if __name__ == '__main__':
  print(solve())

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
A=list(map(int,input().split()))
a,b=max(A),min(A)
if a-b>1:
    print('No')
elif a==b:
    print('Yes' if a<=n//2 else 'No')
else:
    c=A.count(b)
    print('Yes' if 1<=a-c<=(n-c)//2 else 'No')

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

exist = True

if max(a) - min(a) > 1:
    exist = False
    
elif max(a) >= n:
    exist = False
    
elif max(a) - min(a) == 1:
    if max(a) == a.count(min(a)) + 1:
        exist = True
    else:
        exist = False
        
elif max(a) == min(a):
    if 2*a[0] <= n or a[0]+1 == n:
        exist = True
    else:
        exist = False
        
print("Yes") if exist else print("No")

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

exist = True

if max(a) - min(a) > 1:
    exist = False
    
elif max(a) >= n:
    exist = False
    
elif max(a) - min(a) == 1:
    if max(a) == a.count(min(a)) + 1:
        exist = True
    else:
        exist = False
        
elif max(a) == min(a):
    if n%a[0] == 0 or a[0]+1 == n:
        exist = True
    else:
        exist = False
        
print("Yes") if exist else print("No")

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

exist = True

if max(a) - min(a) > 1:
    exist = False
    
elif max(a) >= n:
    exist = False
    
elif max(a) - min(a) == 1:
    if max(a) == a.count(min(a)) + 1:
        pass
    else:
        exist = False
        
elif max(a) == min(a):
    if n%a[0] == 0 or a[0]+1 == n:
        pass
    else:
        exist = False
        
print("Yes") if exist else print("No")

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

exist = True

if max(a) - min(a) > 1:
    exist = False
    
elif max(a) - min(a) == 1:
    if max(a) == a.count(min(a)) + 1:
        pass
    else:
        exist = False
        
elif max(a) == min(a):
    if n%a[0] == 0 or a[0]+1 == n:
        pass
    else:
        exist = False
        
print("Yes") if exist else print("No")

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


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


def solve():
    N = int(input())
    A = inpl()

    max_a = max(A)
    min_a = min(A)
    num_cnt = Counter(A)

    if max_a - min_a > 1:
        return 'No'

    if len(num_cnt) == 1:
        if max_a == N - 1 or 2 * max_a <= N:
            return 'Yes'
        else:
            return 'No'

    not_alone = num_cnt[max_a]
    alone = num_cnt[min_a]
    if not_alone >= (max_a - alone) * 2 and alone <= not_alone:
        return 'Yes'

    return 'No'


print(solve())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


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


def solve():
    N = int(input())
    A = inpl()

    max_a = max(A)
    min_a = min(A)
    num_cnt = Counter(A)
    min_cnt = num_cnt[min_a]
    # max_cnt = num_cnt[max_a]
    # print(num_cnt)

    if max_a - min_a >= 2:
        return 'No'
    elif len(num_cnt) == 1:
        if min_a == N - 1:
            return 'Yes'
        elif min_a * 2 <= N:
            return 'Yes'
        else:
            return 'No'
    elif A.count(1) >= 2:
        return 'No'
    elif min_cnt == 2:
        return 'Yes'
    elif min_cnt == min_a:
        return 'Yes'
    else:
        return 'No'


print(solve())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


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


def solve():
    N = int(input())
    A = inpl()

    max_a = max(A)
    min_a = min(A)
    num_cnt = Counter(A)
    min_cnt = num_cnt[min_a]
    # max_cnt = num_cnt[max_a]

    if max_a - min_a >= 2:
        return 'No'
    elif len(num_cnt) == 1:
        if min_a == N - 1:
            return 'Yes'
        elif min_a * 2 <= N:
            return 'Yes'
        else:
            return 'No'
    elif A.count(1) >= 2:
        return 'No'
    elif min_cnt != min_a:
        return 'No'
    else:
        return 'Yes'


print(solve())

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


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


def solve():
    N = int(input())
    A = inpl()

    max_a = max(A)
    min_a = min(A)
    num_cnt = Counter(A)
    min_cnt = num_cnt[min_a]
    # max_cnt = num_cnt[max_a]

    if max_a - min_a >= 2:
        return 'No'
    elif A.count(1) >= 2:
        return 'No'
    elif len(num_cnt) == 1:
        if min_a == N - 1:
            return 'Yes'
        elif min_a * 2 <= N:
            return 'Yes'
        else:
            return 'No'
    elif min_cnt != min_a:
        return 'No'
    else:
        return 'Yes'


print(solve())

Submission status: Wrong Answer

Solution code:
from itertools import groupby as gb
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
if a[0]==a[-1]:
    if a[0]*2<=n or a[0]==n-1:
        print('Yes')
    else:
        print('No')
elif a[0]+1==a[-1]:
    print('Yes')
    # ｱﾋｬﾋｬﾋｬﾋｬ
else:
    print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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: #MAX-MIN == 1
	n_MIN = n_MAX = 0
	for a in aa:
		if a == MIN: n_MIN += 1
		if a == MAX: n_MAX += 1
	print(n_MIN,n_MAX)
	x_min = n_MIN + 1
	x_max = n_MIN + n_MAX//2
	if x_min <= MAX <= x_max:
		print('Yes')
	else:
		print('No')

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
l=[int(s[i]) for i in range(n)]
l.sort()
if l[0]==l[-1]:
    if 1<=l[0]<=n//2+n%2:
        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")

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().split()
l=[int(s[i]) for i in range(n)]
l.sort()
if l[0]==l[-1]:
    if 1<=l[0]<=n//2:
        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")

Submission status: Wrong Answer

Solution code:
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")

Submission status: Wrong Answer

Solution code:
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 > N or 2*(ma-uniq) > no_uni:
      ans=False
if ans:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
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
  for i in range(N):
    if A[i]==mi:
      if A[i] > (uniq-1)+(no_uni//2):
        ans=False
    else:
      if no_uni-1==1:
        if A[i] > uniq+1:
          ans=False
      else:
        if A[i] > uniq+(no_uni)//2:
          ans=False
if ans:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
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!=1:
    ans=False
else:
  uniq=ma*N - sum(A)
  no_uni=N-uniq
  if no_uni==1:
    ans=False
  for i in range(N):
    if A[i]==mi:
      if A[i] > (uniq-1)+(no_uni//2):
        ans=False
    else:
      if no_uni-1==1:
        if A[i] > uniq+1:
          ans=False
      else:
        if A[i] > uniq+(no_uni)//2:
          ans=False
if ans:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[-1] - a[0] >= 2:
    print("No")
if a[-1] == a[0]:
    if n - a[0] == 1:
        print("Yes")
    else:
        print("Yes" if n//a[0] >= 2 else "No")
else:
    lo = 0
    hi = n-1
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] == a[0]:
            lo = mid
        else:
            hi = mid
    m = lo
    print("Yes" if n-m > 2 and a[0] == m+1 else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]

amax = max(a)
aelse = list(set(a))
aelse.remove(amax)
if len(aelse) == 0:
    if 2*amax <= N:
        print('Yes')
    else:
        print('No')
    exit()
if len(aelse) != 1:
    print('No')
    exit()
if aelse[0] != amax - 1:
    print('No')
    exit()
els = aelse[0]
if els < a.count(els):
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]

amax = max(a)
aelse = list(set(a))
aelse.remove(amax)
if len(aelse) == 0:
    print('Yes')
    exit()
if len(aelse) != 1:
    print('No')
    exit()
if aelse[0] != amax - 1:
    print('No')
    exit()
els = aelse[0]
if els < a.count(els):
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]

amax = max(a)
aelse = list(set(a))
aelse.remove(amax)
if len(aelse) == 0:
    print('Yes')
    exit()
if len(aelse) != 1:
    print('No')
    exit()
if aelse[0] != amax - 1:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
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 + 1:
    flag = False
elif p == q:
    if n - p > 1 and p * 2 > n:
        flag = False
else:
    if x >= p or (p-x) * 2 > y:
        flag = False

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
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 N-m == A.count(M) or M-1 == A.count(m):
            print("Yes")
        else:
            print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(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 N-m == A.count(M):
            print("Yes")
        else:
            print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

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 ma <= n // 2:
            return True
        else:
            return False

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

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

Submission status: Wrong Answer

Solution code:
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 + (c2 + 1) // 2 <= a2


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

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

Submission status: Wrong Answer

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

max_A = max(A)
min_A = min(A)

if (max_A - min_A) > 1:
	print("NO")
elif (max_A - min_A) == 1:
	x = A.count(max_A-1)
	y = A.count(max_A)
	if x < max_A and 2*(max_A-x) <= y:
		print("YES")
	else:
		print("NO")
else:
		if max_A == (N-1) or max_A*2 <= N:
			print("YES")
		else:
			print("NO")

Submission status: Wrong Answer

Solution code:
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];
        # all unique
        if (group == N - 1):
            print ("Yes")
            sys.exit()
        if (N - 2 * group < 0):
            print ("No")
            sys.exit()
        print ("Yes")
        sys.exit()
    # evidences[-1] - evidences[0] > 1
    min_val = min(evidences)
    max_val = max(evidences)
    rest = N
    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
    # need group
    group = evidences[-1]
    group -= min_val_cnt
    rest -= min_val_cnt
    if rest < group:
        print ("No")
        sys.exit()
    print ("Yes")

Submission status: Wrong Answer

Solution code:
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()
    # evidences[-1] - evidences[0] > 1
    min_val = min(evidences)
    max_val = max(evidences)
    rest = N
    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
    rest -= max_val
    rest -= min_val_cnt
    if rest < 0:
        print ("No")
        sys.exit()
    print ("Yes")

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
    if n >= 2*a[0]:
        ans = 'Yes'
elif len(x)==2:
    if a[0]==a[-1]-1:
        if a.count(a[0])==a[0]:
            ans = 'Yes'
        elif a.count(a[0]) < a[0]:
            x = a.count(a[0])
            if x + (a[-1]-a[0])*2 <=n:
                ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
    if n >= 2*a[0]:
        ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0] and a[0]==a[-1] -1:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
    if n >= 2*a[0]:
        ans = 'Yes'
elif len(x)==2:
    if  a[0]==a[-1] -1:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
    if n >= 2*a[0]:
        ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0] and n > a[-1] and a[0]==a[-1] -1:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
    if n >= 2*a[0]:
        ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0]:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
print 'No'

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
    if n >= 2*a[0]:
        ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0] and n > a[-1] and a[0]==a[1] -1:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==2:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==1:
    while True:
        yy = 3
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0] and n > a[-1] and a[0]==a[1] -1:
        ans = 'Yes'
else:
    ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==2:
    while True:
        yy = 3
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0] and n > a[-1] and a[0]==a[1] -1:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==2:
    if a.count(a[0])==a[0] and n > a[-1]:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif n > 2 and len(x)==2:
    if a[0]==1 and a[1]==2:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==2:
    if a[0]==1 and a[1]==2:
        ans = 'Yes'
print ans

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
a.sort()
x = set(a)
if len(x)==1:
    if a[0]==n-1:
        ans = 'Yes'
    if a[0]==1:
        ans = 'Yes'
        if n >= 2*a[0]:
            ans = 'Yes'
elif len(x)==2:
    if a[0]==a[1]-1:
        ans = 'Yes'
print ans