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, *a = map(int, open(0).read().split())
M = max(a)
c = a.count(M - 1)
#c>0,M==n-1はない
if a.count(M) + c==n and ((M > c > 0 and 2 * (M - c) <= n - c) or (c==0 and M==n-1)):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
M=max(a)
c=a.count(M-1)
if a.count(M)+c==n and M>c and (2*(M-c)<=n-c or M==n-1):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter as ct
    n=int(input())
    a=ct(list(map(int,input().split())))
    if len(a.keys()) not in [1,2]:
        print("No")
        return 0
    if len(a.keys())==1:
        a=list(a.items())
        if a==[(2,3)]:
            print("Yes")
            return 0
        if 2*a[0][0]<=a[0][1]:
            print("Yes")
        else:
            print("No")
        return 0
    i=min(a.keys())
    iv=a[i]
    j=max(a.keys())
    jv=a[j]
    if j-i!=1:
        print("No")
        return 0
    if iv>i:
        print("No")
        return 0
    k=2*(i-iv+1)
    if jv>=k:
        print("Yes")
    else:
        print("No")
main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    d = A[-1] - A[0]
    if d >= 2:
        return 'No'
    elif d == 0:
        if A[0]*2 < N or A[0] == N-1:
            return 'Yes'
        else:
            return 'No'
    else:
        K = max(A)
        C = Counter(A)
        y = C[K]
        x = C[K-1]
        if x < K and 2*(K-x) <= y:
            return 'Yes'
        else:
            return 'No'

def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    d = A[-1] - A[0]
    if d >= 2:
        return 'No'
    elif d == 0:
        if A[0] == 1 or A[0] == N-1:
            return 'Yes'
        else:
            return 'No'
    else:
        K = max(A)
        C = Counter(A)
        y = C[K]
        x = C[K-1]
        if x < K and 2*(K-x) <= y:
            return 'Yes'
        else:
            return 'No'

def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    d = A[-1] - A[0]
    if d >= 2:
        return 'No'
    elif d == N - 1:
        if A[0] == 1 or A[0] == N-1:
            return 'Yes'
        else:
            return 'No'
    else:
        K = max(A)
        C = Counter(A)
        y = C[K]
        x = C[K-1]
        if x < K and 2*(K-x) <= y:
            return 'Yes'
        else:
            return 'No'

def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    d = A[-1] - A[0]
    if d > 2:
        return 'No'
    elif d == N - 1:
        if A[0] == 1 or A[0] == N-1:
            return 'Yes'
        else:
            return 'No'
    else:
        K = max(A)
        C = Counter(A)
        y = C[K]
        x = C[K-1]
        if x < K and 2*(K-x) <= y:
            return 'Yes'
        else:
            return 'No'


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

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

#処理内容
def main():
	N = int(input())
	D = defaultdict(int)
	a = getlist()
	for i in a:
		D[i] += 1
	if len(D) >= 3:
		print("No")
	elif len(D) == 1:
		if a[i] * 2 <= N:
			print("Yes")
		elif a[i] + 1 == N:
			print("Yes")
		else:
			print("No")
	else:
		L = []
		for i in D:
			L.append([i, D[i]])
		L = sorted(L)
		if L[0][0] + 1 != L[1][0]:
			print("No")
		else:
			x = L[0][1]
			y = L[1][1]
			A = L[0][0]
			if y < (A - x + 1) * 2 or A - x + 1 == 0:
				print("No")
			else:
				print("Yes")


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
if a[0] == a[-1]:
    if a[0] == N-1:
        print("Yes")
    else:
        print("No")
    exit()

if a[0] < a[-1]-1:
    print("No")
    exit()

o = 0
t = 0
for i in range(N):
    if a[i] != a[0]:
        o = i
        t = N-i
        break

if t//2 + o >= a[-1]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
if max(a)-min(a)>2:
  print("No")
  exit()
s = set(a)
lo,hi = min(s),max(s)
if lo == hi:
  if lo == n-1 or lo*2<=n:
    print("Yes")
  else:
    print("No")
else:
  d = {lo:0, hi:0}
  for x in a:
    d[x] += 1
  if d[lo] < hi and (hi-d[lo])*2 <= d[hi]:
    print("Yes")
  else:
    print("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 >= 2:
    print("No")
    exit()

if max_a == min_a:
    if max_a == n - 1:
        print("Yes")
    elif max_a <= n // 2:
        print("Yes")
    else:
        print("No")
    exit()

if min_a == a.count(min_a):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1<=b[0]<=n//2 or b[0]==n-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+1<=b[0]<=c+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1<=b[0]<=n//2 or b[0]==n-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+2<=b[0]<=c+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1<=b[0]<=n//2 or b[0]==n-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+2<=b[0]<=+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1<=b[0]<=n//2 or b[0]==n-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+1<=b[0]<=+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1==b[0] or b[0]==n-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+1<=b[0]<=+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1==b[0] or b[0]==n-1):
        print('Yes')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+1<=b[0]<=+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    if(1<=b[0]<=n//2):
        print('Yes')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+1<=b[0]<=+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
if(b[n-1]-b[0]>1):
    print('No')
elif(b[n-1]-b[0]==0):
    print('Yes')
else:
    for i in range(n-1):
        if(b[i]<b[i+1]):
            c=i
            break
    if(c==n-2):
        print('No')
    elif(c+1<=b[0]<=+1+(n-c-1)//2):
        print('Yes')        
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
ans = "Yes"

L_max = max(L)
L_min = min(L)

if L_max - L_min >= 2:
    ans = "No"
elif L_max == L_min:
    if N < L[0]*2:
        ans = "No"
else:
    num_alone = L.count(L_min)
    not_alone_L = [v-num_alone for v in L if v == L_max]
    if not_alone_L[0] <= 0 or len(not_alone_L) < not_alone_L[0]*2:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
ans = "Yes"

L_max = max(L)
L_min = min(L)

if L_max - L_min >= 2:
    ans = "No"
else:
    num_alone = L.count(L_min)
    not_alone_L = [v-num_alone for v in L if v == L_max]
    if not_alone_L[0] <= 0 or len(not_alone_L) < not_alone_L[0]*2:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
ans = "Yes"

L_max = max(L)
L_min = min(L)

if L_max - L_min >= 2:
    ans = "No"
else:
    num_alone = L.count(L_min)
    not_alone_L = [v-num_alone for v in L if v == L_max]
    if not_alone_L[0] < 0 or len(not_alone_L) < not_alone_L[0]*2:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
ans = "Yes"

L_max = max(L)
L_min = min(L)

if L_max - L_min >= 2:
    ans = "No"
else:
    num_alone = L.count(L_min)
    not_alone_L = [v-num_alone for v in L if v == L_max]
    if not_alone_L[0] > 0 and len(not_alone_L) < not_alone_L[0]*2:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
print([1/id('hoge')%4%2]*2**26**(id('fuga')%4%3)and'Yes')

Submission status: Wrong Answer

Solution code:
n,a=open(0)
n=int(n)
a=sorted(map(int,a.split()))
if a[0]==a[-1]:
  if n-1==a[0]or n//a[0]>=2:
    print('Yes')
  else:
    print('No')
else:
  x=a.count(a[0])
  if x<a[-1]and(n-x)//(a[-1]-x)>=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>=2:
    print("No")

elif M-m==0:
    for i in range(N):
        if a[i]==N-1 or a[i]<=N//2:
            continue
        else:
            print("No")
            break
    print("Yes")
else:
    q=0
    p=0
    for i in range(N):
        if a[i]==M:
            q+=1
        elif a[i]==m:
            p+=1
    if p+q//2 >= max(a) and max(a)>=p+1:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
if b[n-1]-b[0] >=2:
    print("No")
else:
    b = sum(a)%n
    c = int((sum(a)-b)/n)
    if b == 0:
        if 2*c > n:
            print("No")
        else:
            print("Yes")
    else:
        if b == 1:
            print("No")
        else:
            if n - b/2 >= c+1 and n <= c+b:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
if b[n-1]-b[0] >=2:
    print("No")
else:
    b = sum(a)%n
    c = int((sum(a)-b)/n)
    if b == 0:
        if 2*c > n:
            print("No")
        else:
            print("Yes")
    else:
        if b == 1:
            print("No")
        else:
            if n - b/2 >= c+1:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
if b[n-1]-b[0] >=2:
    print("No")
else:
    b = sum(a)%n
    c = int((sum(a)-b)/n)
    if b == 0:
        if 2*c >= n:
            print("No")
        else:
            print("Yes")
    else:
        if b == 1:
            print("No")
        else:
            if n - b/2 >= c+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
c=Counter(A).most_common()
r=0
if len(c)==2 and c[0][0]==c[1][0]+1 and 0<c[0][0]-c[1][1]<=c[0][1]//2:
    r=1
elif len(c)==1 and (c[0][0]==c[0][1]-1 or c[0][0]<=c[0][1]//2):
    r=1
print(['No','Yes'][r])

Submission status: Wrong Answer

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

def solve():
    if max(a)-min(a) > 1:
        return False
    if all(i==a[0] for i in a):
        # 全員unique or 全員 not unique
        if a[0] == n-1 or a[0] <= n//2:
            return True
        else:
            return False
    color = [0]*n
    unique = min(a)
    for i, ai in enumerate(a):
        if ai == unique:
            color[i] = 1
    s = sum(a)
    for i, ai in enumerate(a):
        if ai == unique:
            if ai != s-1:
                return False
        else:
            if ai != s:
                return False
    return True

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

Submission status: Wrong Answer

Solution code:
n=input()
m=map(int,input().split())
a=[int(i) for i in m]
d=max(a)-min(a)
if d>1:
    ans=False
elif d==0:
    if (max(a)<len(a) and max(a)*2>=len(a)):
        ans=True
    else:
        ans=False
else:
    max_num=a.count(max(a))
    min_num=a.count(min(a))
    dif=max(a)-min_num
    if (min_num<max(a) and dif*2<=max_num):
            ans=True
    else:
        ans=False
        
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
m=map(int,input().split())
a=[int(i) for i in m]
d=max(a)-min(a)
if d>1:
    ans=False
elif d==0:
    if (max(a)<len(a) and max(a)*2>=len(a)):
        ans=True
    else:
        ans=False
else:
    max_num=a.count(max(a))
    min_num=a.count(min(a))
    dif=max(a)-min_num
    if (min_num<max(a) and dif*2<=max_num):
            ans=True
    else:
        ans=False
        
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
m=map(int,input().split())
a=[int(i) for i in m]
d=max(a)-min(a)
if d>1:
    ans=False
elif d==0:
    if max(a)<len(a):
        ans=True
    else:
        ans=False
else:
    max_num=a.count(max(a))
    min_num=a.count(min(a))
    dif=max(a)-min_num
    if (min_num<max(a)):
        if dif*2<=max_num:
            ans=True
        else:
            ans=False
    else:
        ans=False
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
import collections
l1 = collections.Counter(a).most_common()
l1.sort()
if len(l1) > 2:
    print("No")
elif len(l1) == 1:#発言が１種類の場合
    if l1[0][0] * 2 <= n or l1[0][0] == n - 1:
        print("Yes")
    else:
        print("No")
else:
    if n - l1[0][1] >= (l1[1][0] - l1[0][1]) * 2 and l1[1][0] - l1[0][1] > 0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
import collections
l1 = collections.Counter(a).most_common()
l1.sort()
if len(l1) == 1:#発言が１種類の場合
    if l1[0][0] * 2 <= n or l1[0][0] == n - 1:
        print("Yes")
    else:
        print("No")
else:
    if n - l1[0][1] >= (l1[1][0] - l1[0][1]) * 2 and l1[1][0] - l1[0][1] > 0:
        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 >= 2:
  print("No")
elif M == m:
  if M == n-1 or M <= n//2:
    print("Yes")
  else:
    print("No")
else:
  alone = a.count(m)
  left = n - alone
  if alone > M:
    print("No")
  elif M - alone <= left // 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 >= 2:
  print("No")
  exit()
if M == m:
  if M == n or M <= n//2:
    print("Yes")
  else:
    print("No")
else:
  alone = a.count(m)
  left = n - alone
  if alone > M:
    print("No")
  elif M - alone <= left // 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
def printans(t):
    print(t)
    sys.exit()

N=int(input())
A=[int(i) for i in input().split()]

if all([a==A[0] for a in A]):#全部同じ
    shurui=A[0]
    if shurui==N-1 or shurui*2<=N:
        printans("Yes")
    else:printans("No")
else:#少ないやつは自分だけの色、そいつら以外で上と同じ処理
    maxshurui = max(A)
    if all([a in (maxshurui,maxshurui-1) for a in A]):
        unique = A.count(maxshurui-1)
        shurui = maxshurui-unique
        if shurui<=0:
            printans("No")
        if shurui*2<=N-unique:
            printans("Yes")
        else:printans("No")

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = list(map(int,input().split()))
mi,ma = 10 ** 6,0
cnt = [0] * n
for v in a:
    cnt[v] += 1
    mi = min(mi,v)
    ma = max(ma,v)
if ma - mi >= 2:
    print("No")
    sys.exit()
if mi != ma:
    if cnt[mi] == ma or (n - cnt[mi]) < 2 * (ma - cnt[mi]):
        print("No")
    else:
        print("Yes")
else:
    if mi == n - 1 or mi * 2 <= n:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        for _ in range(num): return []
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(map(int, input().split())) for _ in range(N)]
        return map(list,zip(*read_all))

#################

N = I()
a = III()

small = a[0]
large = a[0]

for i in range(1,N):
    if a[i]>small:
        large = a[i]
        break
    if a[i]<small:
        large = small
        small = a[i]
        break

if small != large:
    small_num = 0
    large_num = 0
    for i in range(N):
        if a[i]==small:
            small_num += 1
        else:
            large_num += 1
    num = large_num
    val = large-small_num
    if 2*val<=num and val>=1:
        print('Yes')
    else:
        print('No')
else:
    num = N
    val = large
    if val+1==num:
        print('Yes')
    elif 2*val<=num:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

minColor = min(A)
maxColor = max(A)

if minColor == maxColor:
    if minColor == N - 1:  # 各色の猫が1匹ずつ
        print('Yes')
    elif minColor * 2 <= N:  # 各色の猫が2匹以上
        print('Yes')
    else:
        print('No')
    exit()

minCnt = 0
maxCnt = 0

for a in A:
    if a == minColor:
        minCnt += 1
    elif a == maxColor:
        maxCnt += 1
    else:
        print('No')
        exit()

if (maxColor - minCnt) * 2 <= maxCnt and minCnt == maxCnt - 1 and N - minCnt >= 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) >= 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] == N - 1:
        print('Yes')
    elif N // 2 >= cntA[0][0]:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][0] + 1 == cntA[1][0]:
        if N >= cntA[0][1] + (cntA[1][0] - cntA[0][1]) * 2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) >= 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] == N - 1:
        print('Yes')
    elif N // 2 >= cntA[0][0]:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][0] + 1 == cntA[1][0]:
        if N >= cntA[0][1] + cntA[1][1] * 2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) >= 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] == N - 1:
        print('Yes')
    elif N // 2 >= cntA[0][0]:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][0] == cntA[1][0] - 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) >= 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] == N - 1:
        print('Yes')
    elif N // 2 >= cntA[0][0]:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][1] == 1 and cntA[0][0] == cntA[1][0] - 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) >= 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] <= 2:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][1] == 1 and cntA[0][0] == cntA[1][0] - 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) >= 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] <= 2:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][1] == 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntA = Counter(A)
cntA = list(cntA.items())
cntA.sort()

if len(cntA) > 3:
    print('No')
elif len(cntA) == 1:
    if cntA[0][0] <= 2:
        print('Yes')
    else:
        print('No')
elif len(cntA) == 2:
    if cntA[0][1] == 1:
        print('Yes')
    else:
        print('No')
else:
    if cntA[0][1] == 1 and cntA[1][1] == 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
arr=list(map(int,input().split()))
min_,max_=min(arr),max(arr)
ans=None

if max_-min_ > 1:
    ans=False
elif max_-min_ == 1:
    """
    A=max_
    y=len([a for a in arr if a==max_])
    x=N-y
    nc=A-x
    ans=(A-x)>0 and y >=2*(A-x)
    """
    
    y=len([a for a in arr if a==max_])
    x=N-y
    nc=max_-x
    ans=nc!=0 and y>=2*nc

else:
    ans=N>=2*min_ or min_+1==N

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
min_,max_=min(A),max(A)

f = lambda k,n: k==n or 2*k <= n

ans=None

if max_-min_ > 1:
    ans=False
elif max_-min_ == 1:
    q=len([a for a in A if a==max_])
    p=N-q
    nc=max_-p
    ans=nc!=0 and q>=2*nc
else:
    ans=N>=2*min_ or min_+1==N

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
min_,max_=min(A),max(A)

f = lambda k,n: k==n or 2*k <= n

ans=None

if max_-min_ > 1:
    ans=False
elif max_-min_ == 1:
    k=max_
    q=len([a for a in A if a==max_])
    p=N-q
    ans=k-p!=0 and f(k-p,q)
else:
    k=min_
    ans=f(k,N) or f(k+1,N)

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

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):
    if k==0:
        return False
    return k==n or 2*k <= n

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_) or f(N,min_+1)

if ans is True:
    print("Yes")
else:
    print("No")

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):
    if k==0:
        return False
    if n//k == 1 and n%k>0:
        return False
    return True

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_) or f(N,min_+1)

if ans is True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
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_)

if ans is True:
    print("Yes")
else:
    print("No")