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()))
if len(set(a))==1:
    if n>=2*a[0] or n-1==a[0]:print("Yes")
    else:print("No")
elif len(set(a))>=3:print("No")
else:
    s,S=sorted(list(set(a)))
    if 2*n-a.count(s)<=S:print("Yes")
    else:print("No")

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

mx,mxc = 0,0
mn,mnc = 1000000,0
for i in a:
    if mx == i:
        mxc += 1
    if mn == i:
        mnc += 1
    if mx < i:
        mx = i
        mxc = 1
    if mn > i:
        mn = i
        mnc = 1

d = mx-mn


if d > 1:
    print('No')
elif d == 1:
    if mx > mnc and 2*(mx-mnc) <= mxc:
        print('Yes')
    else:
        print('No')
elif d == 0:
    if a[0] == n-1 or 2*a[0] < n:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

mx,mxc = 0,0
mn,mnc = 1000000,0
for i in a:
    if mx == i:
        mxc += 1
    if mn == i:
        mnc += 1
    if mx < i:
        mx = i
        mxc = 1
    if mn > i:
        mn = i
        mnc = 1

d = mx-mn


if d > 1:
    print('No')
elif d == 1:
    if mx > mnc and 2*(mx-mnc) <= mxc:
        print('Yes')
    else:
        print('No')
elif d == 0:
    if a[0] == n-1 or a[0] == 1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

A.sort()
v = A[-1] - A[0]
if v >= 2:
    print('No')
elif v == 1:
    if A[0]*2 <= n or A[0] == n-1:
        print('Yes')
    else:
        print('No')
else:
    x = A.index(A[-1])
    y = A[0] - x + 1
    if y > 0 and y*2 <= n-x:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

A.sort()
v = len(set(A))
if v > 2:
    print('No')
elif v == 1:
    if A[0]*2 <= n or A[0] == n-1:
        print('Yes')
    else:
        print('No')
else:
    x = A.index(A[-1])
    y = A[0] - x + 1
    if y > 0 and y*2 <= n-x:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    if c[ma] % 2 != 0:
        return False
    x = ma - c[ma] // 2
    if x == c[mi]:
        return True
    return x <= c[mi] - 2

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

A.sort()
if A[-1]-A[0]>1:
    print('No')
else:
    if A[-1]-A[0]==1:
        n=A.count(A[0])
        m=A.count(A[-1])
        kind=A[-1]-n
        if m>=2*kind and kind!=0:
            print('Yes')
        else:
            print('No')
    else:
        if A[0]==N-1:
            print('Yes')
        else:
            if N>=2*A[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+1:
  print("No")
elif M==m+1:
  cntm=a.count(m)
  cntM=n-cntm
  if cntm>m:
    print("No")
  elif cntm+cntM//2<M:
    print("No")
  else:
    print("Yes")
elif M==m:
  if m<=n//2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    if c[ma] % 2 != 0:
        return False
    if c[ma] // 2 + c[mi] < ma:
        return False
    return ma != c[ma] // 2 + c[mi] - 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    if c[ma] % 2 != 0:
        return False
    if c[ma] + c[mi] < ma:
        return False
    return ma != c[ma] // 2 + c[mi] - 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    if c[ma] % 2 != 0:
        return False
    return ma != c[ma] // 2 + c[mi] - 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return N % 2 == 0 or ma != N - 2
    c = Counter(a)
    if c[ma] % 2 != 0:
        return False
    return ma != c[ma] // 2 + c[mi] - 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

res = True
maxvar = max(A)

x = 0
y = 0

for i in range(N):
    if A[i] == maxvar:
        x += 1
    elif A[i] == maxvar - 1:
        y += 1
    else:
        res = False
        break

if (maxvar - y) * 2 + y > N or (maxvar - y) * 2 <= 0:
    res = False

if maxvar == N - 1 and y == 0:
    res = True

print('Yes' if res else 'No')

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
k=len(set(A))
if k==1:
  if A[0]==n-1 or 2*A[0]<=n:
    print("Yes")
  else:
    print("No")
else:
  ma=min(A)
  ct=0
  for a in A:
    if a==ma:
      ct+=1
  if ma+1>ct and (ma+1-ct)*2<=n-ct:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
k=len(set(A))
if k==1:
  if A[0]==n-1 or 2*A[0]<=n:
    print("Yes")
  else:
    print("No")
else:
  ma=min(A)
  ct=0
  for a in A:
    if a==ma:
      ct+=1
  if (ma+1-ct)*2<=n-ct:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
k=len(set(A))
if k==1:
  if A[0]==n-1 or 2*A[0]<=n:
    print("Yes")
  else:
    print("No")
else:
  ma=min(A)
  ct=0
  for a in A:
    if a==ma:
      ct+=1
  if ct>1:
    print("No")
  else:
    if ma*2<=n-1:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
data = [[-1, 0]]
for x in a:
    if data[-1][0] == x:
        data[-1][1] += 1
    else:
        data.append([x, 1])
data = data[1:]

if len(data) == 1:
    print("Yes" if data[0][0] * 2 <= n or data[0][0] + 1 == n else "No")
elif len(data) == 2:
    if data[0][0] + 1 == data[1][0] and data[0][0] == data[0][1] and data[0][0]*2 + 1 == n:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, *a = map(int, read().split())
a.sort()
if a[0] != a[1] and a[0] + 1 != a[-1]:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

d = {}

for ai in a:
    if ai not in d:
        d[ai] = 0
    d[ai] += 1

f = 1

k = list(d.keys())
k.sort()

# ボッチ猫の数
b = 0

if len(k) > 2:
    f = 0
elif len(k) == 2:
    if k[1] - k[0] != 1:
        f = 0
    b = d[k[0]]

# グループ数
g = k[-1] - b

if g <= 0 or g > d[k[-1]] // 2:
    f = 0

if b == 0 and k[-1] == n - 1:
    f = 1

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

Submission status: Wrong Answer

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

d = {}

for ai in a:
    if ai not in d:
        d[ai] = 0
    d[ai] += 1

f = 1

k = list(d.keys())
k.sort()

# ボッチ猫の数
b = 0

if len(k) > 2:
    f = 0
elif len(k) == 2:
    if k[1] - k[0] != 1:
        f = 0
    b = d[k[0]]

# グループ数
g = k[-1] - b

if g == 0 or g > d[k[-1]] // 2:
    f = 0

if b == 0 and k[-1] == n - 1:
    f = 1

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

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
from collections import Counter
a=dict(Counter(lists))
if len(a)==1:
    if n>=lists[0]*2 or lists[0]==n-1:
        print("Yes")
    else:
        print("No")
    
elif len(a)==2:
    P=list(a.keys())
    Q=list(a.values())
    x,y=min(P),max(P) #x=k+l-1,y=k+l
    c,d=a[x],a[y]#c=k,d=?
    if 2*y-c<=n and c>0 and y>c and d+c==y:
        print("Yes")
    else:
        print("No")

    
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
from collections import Counter
a=dict(Counter(lists))
if len(a)==1:
    if n>=lists[0]*2 or lists[0]==n-1:
        print("Yes")
    else:
        print("No")
    
elif len(a)==2:
    P=list(a.keys())
    Q=list(a.values())
    x,y=min(P),max(P) #x=k+l-1,y=k+l
    c,d=a[x],a[y]#c=k,d=?
    if 2*y-c<=n and c>0 and y>c:
        print("Yes")
    else:
        print("No")

    
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
from collections import Counter
a=dict(Counter(lists))
if len(a)==1:
    if n>=lists[0]*2:
        print("Yes")
    else:
        print("No")
    
elif len(a)==2:
    P=list(a.keys())
    Q=list(a.values())
    x,y=min(P),max(P) #x=k+l-1,y=k+l
    c,d=a[x],a[y]#c=k,d=?
    if 2*y-c<=n and c>0 and y>c:
        print("Yes")
    else:
        print("No")
 
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = []
C = []
for num in A:
    if len(B) >= 4:
        print("No")
        break
    elif num in B: 
        C[B.index(num)] += 1
    else:
        B.append(num)
        C.append(1)


if len(B) > 2:
    print('No')
elif len(B) == 1:
    if n == B[0] +1:
        print('Yes')
    elif n//B[0] >= 2:
        print('Yes')
    else:
        print('No')
elif B[0]  == (B[1]+1):
    k = C[1]
    m = B[1]
    if m-k+1 <= 0:
        print('No')
    elif (n-k) % (m-k+1) == 0:
        print('Yes')
    else:
        print('No')
elif B[1] == (B[0]+1):
    k = C[0]
    m = B[0]
    if m-k+1 <= 0:
        print('No')
    elif (n-k) % (m-k+1) == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

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

A.sort()
flag = True
for a in A:
    if a > A[0]+1:
        flag = False

if flag:
    cnt = A.count(A[0])
    if cnt == N and (A[0] == N-1 or A[0]*2 <= N):
        ans = "Yes"
    elif cnt == A[0] and cnt < N-1:
        ans = "Yes"
    elif cnt < A[0] and N-cnt >= 2*A[0]:
        ans = "Yes"
    else:
        ans = "No"
else:
    ans = "No"
print(ans)

Submission status: Wrong Answer

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

A.sort()
flag = True
for a in A:
    if a > A[0]+1:
        flag = False

if flag:
    cnt = A.count(A[0])
    if cnt == N and (A[0] == N-1 or A[0]*2 <= N):
        ans = "Yes"
    elif cnt <= A[0] and N-cnt >= 2*A[0]:
        ans = "Yes"
    else:
        ans = "No"
else:
    ans = "No"
print(ans)

Submission status: Wrong Answer

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

D={}
for i in range(N):
    if L[i] not in D:
        D[L[i]]=1
    else:
        D[L[i]]+=1

if len(D)>2:
    print("No")
    exit()
elif len(D)==1:
    if L[0]==N-1:
        print("Yes")
        exit()
    if L[0]*2<=N:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

D=list(D.items())
D.sort()
#print(D)
if D[0][0]+1!=D[1][0]:
    print("No")
    exit()

Odd=D[0][1]
if D[1][0]!=N-Odd:
    print("No")
    exit()

if D[1][1]==1:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

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

D={}
for i in range(N):
    if L[i] not in D:
        D[L[i]]=1
    else:
        D[L[i]]+=1

if len(D)>2:
    print("No")
    exit()
elif len(D)==1:
    if L[0]==N-1:
        print("Yes")
        exit()
    if L[0]*2>N:
        print("No")
        exit()
    if 1<=L[0]<=N-1:
        print("Yes")
        exit()

D=list(D.items())
D.sort()
#print(D)
if D[0][0]+1!=D[1][0]:
    print("No")
    exit()

Odd=D[0][1]
if D[1][0]!=N-Odd:
    print("No")
    exit()

if D[1][1]==1:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

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

D={}
for i in range(N):
    if L[i] not in D:
        D[L[i]]=1
    else:
        D[L[i]]+=1

if len(D)>2:
    print("No")
    exit()
elif len(D)==1:
    if L[0]==N-1:
        print("Yes")
    if L[0]*2>N:
        print("No")
        exit()
    if 1<=L[0]<=N-1:
        print("Yes")
        exit()

D=list(D.items())
D.sort()
#print(D)
if D[0][0]+1!=D[1][0]:
    print("No")
    exit()

Odd=D[0][1]
if D[1][0]!=N-Odd:
    print("No")
    exit()

if D[1][1]==1:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

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

D={}
for i in range(N):
    if L[i] not in D:
        D[L[i]]=1
    else:
        D[L[i]]+=1

if len(D)>2:
    print("No")
    exit()
elif len(D)==1:
    if L[0]*2>N:
        print("No")
        exit()
    if 1<=L[0]<=N-1:
        print("Yes")
        exit()

D=list(D.items())
D.sort()
#print(D)
if D[0][0]+1!=D[1][0]:
    print("No")
    exit()

Odd=D[0][1]
if D[1][0]!=N-Odd:
    print("No")
    exit()

if D[1][1]==1:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
Ma,ma=max(A),min(A)
b=Ma-ma<=1
if b:
    if Ma==ma:
        b=N==Ma+1 or N//2>=Ma
    else:
        Mc=len(list(a for a in A if a==Ma))
        mc=N-Mc
        b=Ma==mc+1
print("YNeos"[not b::2])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
Ma,ma=max(A),min(A)
b=Ma-ma<=1
if b:
    if Ma==ma:
        b=N==Ma+1 or any(N//i==Ma for i in range(2,N+1))
    else:
        Mc=len(list(a for a in A if a==Ma))
        mc=N-Mc
        b=Ma==mc+1
print("YNeos"[not b::2])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
Ma,ma=max(A),min(A)
b=Ma-ma<=1
if b:
    if Ma==ma:
        b=N==Ma+1 or any(N//i==Ma for i in range(1,N+1))
    else:
        Mc=len(list(a for a in A if a==Ma))
        mc=N-Mc
        b=Ma==mc+1
print("YNeos"[not b::2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = set(a)
if len(s)>=3:
    print('No')
elif len(s)==2:
    #頑張る
    mx = max(a)
    mn = min(a)
    if a.count(mn) < mx and 2*(mx-a.count(mn))<=a.count(mx):
        print('Yes')
    else:
        print('No')
else:
    if a[0]==n-1:
        print('Yes')
    elif a[0]*2<=n:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

if max(a)-min(a)>=2:
  print "No"
elif max(a)-min(a)==0:
  if N>=2*a[0] or N==a[0]+1:
    print "Yes"
  else:
    print "No"
else:
  if a.count(max(a))>=2 and a.count(min(a))==min(a):
    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 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 mx>=ac[mn]+(ac[mx]+1)//2 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()
if mx>ac[mn]+ac[mx]//2 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()
if mx>ac[mn]+ac[mx]//2 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 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()
if mx>ac[mn]+ac[mx]//2 or ac[mx]<2:##これで場合分け足りるか？
    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")
            print(ac)
    exit()

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

mn = min(cl)
mx = max(cl)
if mx-mn>1:
    print("No")
    exit()
if mx>ac[mn]+ac[mx]//2 or ac[mx]<2:##これで場合分け足りるか？
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

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

ls_A = len(set(A))

if ls_A >= 3:
  print("No")
  exit()
  
if max(A) - min(A) >= 2:
  print("No")
  exit()
  
if len(set(A)) == 1:
  if A[0] == N - 1:
    print("Yes")
    exit()
  if N // A[0] >= 2:
    print("Yes")
  else:
    print("No")
else:
  min_A = min(A)
  cnt = 0
  for a in A:
    if a == min_A:
      cnt += 1
  N -= cnt
  if N // min_A >= 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
fewer = 0
m = min(a)
M = max(a)
if M - m >= 2:
  print("No")
else:
  if m == M:
    if m == n-1:
      print("Yes")
    else:
      if m <= n/2:
        print("Yes")
      else:
        print("No")
  else:
    for i in range(n):
      if a[i] == m:
        fewer += 1
    more = n - fewer
    num_remain = M - fewer
    if num_remain <= more/2:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
fewer = 0
if max(a) - min(a) >= 2:
  print("No")
else:
  if min(a) == max(a):
    if min(a) == n-1:
      print("Yes")
    else:
      if min(a) <= n/2:
        print("Yes")
      else:
        print("No")
  else:
    for i in range(n):
      if a[i] == min(a):
        fewer += 1
    more = n - fewer
    num_remain = max(a) - fewer
    if num_remain <= more/2:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

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

a = max(A)
b = min(A)

# import sys
# if a - b > 1:
#     print("No")
#     sys.exit()

ok = 0

if a - b == 1:
    C = [0, 0]
    for i in range(n):
        C[A[i] - b] += 1
    if a - C[0] > 0 and C[1] // 2 >= a - C[0]:
        ok = 1
else:
    if n == a + 1:
        ok = 1   
    if n // 2 >= a:
        ok = 1

if ok == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
mi = min(l); ma = max(l)
if ma-mi > 1: print('No')
else:
  al = l.count(mi)
  if al - 1 + (n!=al) <= mi <= al - 1 + (n-al)//2: print('Yes')
  else: print('No')

Submission status: Wrong Answer

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

ma = max(a)
mi = min(a)
if ma-mi >= 2:
    print('No')
    exit()
if ma == mi:
    if a[0] <= N//2 or a[0] == N-1:
        print('Yes')
    else:
        print('No')
else:
    maxnum = a.count(ma)
    minnum = a.count(mi)
    if max(a) == minnum:
        print('No')
    elif 2*(N-ma) >= maxnum:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
k = a.count(a[0])
if a[-1] - a[0] > 1:
    print('No')
elif a[-1] == a[0]:
    if N == a[0]-1:
        print('Yes')
    elif N >= a[0]*2:
        print('Yes')
    else:
        print('No')
elif a[-1] < k + 1:
    print('No')
elif a[-1] > (N-k)//2 + k:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

b = [0 for i in range(n+1)]

for i in range(n):
    b[a[i]]+=1
    b[a[i]+1]+=1

for i in range(1,n+1):
    # b[i]==nとなるi色だけ可能性がある
    if b[i]==n:
        unique = 0
        for j in range(n):
            if a[j]==i-1:
                unique+=1
        if n-unique==1:
            break
        if unique<=i<=(n-unique)//2+unique:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
from random import randint

N = int(input())
a = [int(i) for i in input().split()]
# N = randint(2, 8)
# x = randint(2, N)
# y = randint(1, 8)
# a = [x] * y + [x-1] * (N - y)

def solve() :
    c = Counter(a)
    if len(c.keys()) > 2 :
        return 'No'
    
    if len(c.keys()) == 2 :
        mk, Mk = min(c.keys()), max(c.keys())
        mv, Mv = c[mk], c[Mk]
        n = N - mv
        m = Mk - mv
        if 0 < m * 2 <= n :
            return 'Yes'
        else :
            return 'No'
    else :
        n = N
        m = list(c.keys())[0]
        if m != 0 and (n >= m * 2 or m == n - 1) :
            return 'Yes'
        else :
            return 'No'    
            
print(solve())

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def solve() :
    c = Counter(a)
    if len(c.keys()) > 2 :
        return 'No'
    
    if len(c.keys()) == 2 :
        mk, Mk = min(c.keys()), max(c.keys())
        mv, Mv = c[mk], c[Mk]
        n = N - mv
        m = Mk - mv
        if m != 0 and n >= m * 2 :
            return 'Yes'
        else :
            return 'No'
    else :
        n = N
        m = list(c.keys())[0]
        if m != 0 and (n >= m * 2 or m == n - 1) :
            return 'Yes'
        else :
            return 'No'    
    
print(solve())

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
mn = min(a)
c = mx + 0
b = 0
s = 0
if mx == mn and (mx != N - 1):
  mn -= 1
if mx >= N:
  print("No")
  exit(0)
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] == mn:
    c = a[i] + 1
    s += 1
  else:
    b += 1
if s >= c:
  print("No")
  exit(0)
if b == 1:
  print("No")
  exit(0)
if b // 2 < c - s:
  print("No")
else: print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
mn = min(a)
c = mx + 0
b = 0
s = 0
if mx == mn and (mx != N - 1):
  mn -= 1
if mx >= N:
  print("No")
  exit(0)
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] == mn:
    c = a[i] + 1
    s += 1
  else:
    b += 1
if s > c:
  print("No")
  exit(0)
if b == 1:
  print("No")
  exit(0)
if b // 2 < c - s:
  print("No")
else: print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
mn = min(a)
c = mx + 0
b = 0
s = 0
if mx == mn and (mx != N - 1):
  mn -= 1
if mx >= N:
  print("No")
  exit(0)
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] == mn:
    c = a[i] + 1
    s += 1
  else:
    b += 1
if b == 1:
  print("No")
  exit(0)
if b // 2 < c - s:
  print("No")
else: print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
mn = min(a)
c = mx + 0
b = 0
s = 0
if mx >= N:
  print("No")
  exit(0)
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] == mn:
    c = a[i] + 1
    s += 1
  else:
    b += 1
if b == 1:
  print("No")
  exit(0)
if b // 2 < c - s:
  print("No")
else: print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
c = mx + 0
b = 0
s = 0
if mx >= N:
  print("No")
  exit(0)
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] < mx:
    c = a[i] + 1
    s += 1
  else: b += 1
if b // 2 < c - s:
  print("No")
else: print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
c = mx + 0
b = 0
s = 0
if mx >= N:
  print("No")
  exit(0)
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] < mx:
    c = a[i] + 1
    s += 1
  else: b += 1
if c > b: print("No")
elif b % 2 and (c != N - 1): print("No")
else: print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
mx = max(a)
c = mx + 0
b = 0
s = 0
for i in range(N):
  if abs(a[i] - mx) > 1:
    print("No")
    exit(0)
  if a[i] < mx:
    c = a[i] + 1
    s += 1
  else: b += 1
if c > b: print("No")
elif b % 2 and (c != N - 1): print("No")
else: print("Yes")

Submission status: Wrong Answer

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