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:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 'No'
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'
print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
ol = l = a[n - 1]
s = a[0]

if l - s > 1:
    print('No')
if l - s == 1:
    sn = a.count(s)
    l -= sn
    n -= sn

if 0 < l <= n // 2 or ol == s and l == n - 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
l = a[n - 1]
s = a[0]

if l - s > 1:
    print('No')
if l - s == 1:
    sn = a.count(s)
    l -= sn
    n -= sn

if 0 < l <= n // 2 or a[n - 1] == a[0] and l == n - 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
l = a[n - 1]
s = a[0]

if l - s > 1:
    print('No')
if l - s == 1:
    sn = a.count(s)
    l -= sn
    n -= sn

if 0 < l <= n // 2 or a[n - 1] == a[0] and l == n - 1:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
min_a = min(a)
max_a = max(a)
if min_a == max_a:
    if min_a == n - 1 or 2 * min_a <= n:
        print("Yes")
    else:
        print("No")
else:
    alone = a.count(min_a)
    if alone < max_a and 2 * (max_a - alone) <= (n - alone):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve():
    if len(hist) > 2:
        return False
    if len(hist) == 1:
        v = hist[0][0]
        return v <= N/2 or v == N-1
    more = max(hist[0], hist[1])
    less = min(hist[0], hist[1])
    single_k, single_n = less
    multi_k, multi_n = more
    if multi_k - single_k != 1:
        return False
    return single_k <= single_n < single_k + multi_n / 2

N = input()
arr = map(int, raw_input().split())
hist = Counter(arr).most_common()

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

Submission status: Wrong Answer

Solution code:
s = raw_input()
ans = len(s)
for ch in set(s):
    t = ch + s + ch
    occ = [i for i in range(len(t)) if t[i] == ch]
    d = [occ[i+1] - occ[i] - 1  for i in range(len(occ)-1)]
    ans = min(ans, max(d))
print ans

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

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

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

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


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

    return 'Yes'


print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


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


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


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

    return ans


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve():
    if len(hist) > 2:
        return False
    if len(hist) == 1:
        v = hist[0][0]
        return v <= N/2 or v == N-1
    more = max(hist[0], hist[1])
    less = min(hist[0], hist[1])
    single_k, single_n = less
    multi_k, multi_n = more
    return single_k <= single_n < single_k + multi_n / 2

N = input()
arr = map(int, raw_input().split())
hist = Counter(arr).most_common()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(): return "".join(list(map(str, ans)))


N = ri()
a = rli()
if(len(set(a)) >= 3):
    print("No")
elif(len(set(a)) == 2):
    ma = max(a)
    mi = min(a)
    l_ma = 0
    l_mi = 0
    for i in a:
        if(i == ma): l_ma += 1
        if(i == mi): l_mi += 1
    if(ma >= l_mi + 2*l_ma):
        print("Yes")
    else:
        print("No")
else:
    if(a[0] == N-1 or N/a[0] >= 2):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(): return "".join(list(map(str, ans)))


N = ri()
a = rli()
if(len(set(a)) >= 3):
    print("No")
elif(len(set(a)) == 2):
    ma = max(a)
    mi = min(a)
    l_ma = 0
    l_mi = 0
    for i in a:
        if(i == ma): l_ma += 1
        if(i == mi): l_mi += 1
    if(ma - l_mi <= 0):
        print("No")
    elif(l_ma/(ma - l_mi) >= 2):
        print("Yes")
    else:
        print("No")
else:
    if(a[0] == N-1):
        print("Yes")
    elif(N/a[0] >= 2):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

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

if (n-l[0])+1 <= l[1] <= (n-l[0])*2:
# if (n-l[0])+1 <= l[1] <= (n-l[0])*2 and n-(n-l[0])*2 <= s[1] <= l[0] - 1:
  print 'Yes'
else:
  print 'No'

Submission status: Wrong Answer

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

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

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

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

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

if (n-l[0])+1 <= l[1] <= (n-l[0])*2 and n-(n-l[0])*2 <= s[1] <= l[0] - 1:
  print 'Yes'
else:
  print 'No'

Submission status: Wrong Answer

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

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

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

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

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

if n - (n-l[0])+1 <= l[1] <= (n-l[0])*2 and n-(n-l[0])*2 <= s[1] <= n - l[0] - 1:
  print 'Yes'
else:
  print 'No'

Submission status: Wrong Answer

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

result = True

if len(set(a)) > 1:
    set_min = list(set(a))[0]
    set_max = list(set(a))[1]

    if len(set(a)) > 2:
        result = False
    elif (set_max - set_min) != 1:
        result = False
    else:
        if set_max == N-1:
            result = (a.count(set_min) == N-2)
        else:
            result = (a.count(set_min) < set_max)
else:
    result = (list(set(a))[0] <= N/2 or list(set(a))[0] == N-1)



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

Submission status: Wrong Answer

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

result = True

if len(set(a)) > 1:
    set_min = list(set(a))[0]
    set_max = list(set(a))[1]

    if len(set(a)) > 2:
        result = False
    elif (set_max - set_min) != 1:
        result = False
    else:
        if set_max == N-1:
            result = (a.count(set_min) < set_max)
else:
    result = (list(set(a))[0] <= N/2 or list(set(a))[0] == N-1)



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

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
for z in range(2):
    if N == 1:
        break
    ox = [0 for i in range(N)]
    ox[0] = z
    f = 0
    if z == 1 and a[0] == 1:
        None
    else:
        for j in range(1,N):
            if ox[j-1] == 0:
                if a[j] == a[j-1]-1:
                    ox[j] = 1
                elif a[j] == a[j-1]:
                    None
                else:
                    f += 1
                    break
            if ox[j-1] == 1:
                if a[j] == a[j-1]:
                    ox[j] = 1
                elif a[j] == a[j-1] + 1:
                    None
                else:
                    f += 1
                    break
    u = ox.count(1)
    if u <= a[N-1] <= u + (N - u)//2 and f == 0:
        print("Yes")
        break
    elif z == 1:
        print("No")
        
if N == 1:
    if a[0] == 1:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

ans = 'No'
if max(a)-min(a)<=1:
    if a.count(min(a)) == min(a):
        ans = 'Yes'
    elif min(a) == max(a):
            if n == 2 and min(a) == 1:
                ans = 'Yes'
            elif n % 2 == 0 and min(a) == n-2:
                ans = 'Yes'
            elif min(a) == n-1:
                ans = 'Yes'
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    for ones in range(N):
        if ones == N-1:
            ones = N
        for others in range(1,int(N/2)+1):
            tmp = [ones + others - 1 for i in range(ones)]
            tmp.extend([ones + others for i in range(N-ones)])
            if tmp == arr:
                print 'Yes'
                return
    print 'No'

N = input()
arr = map(int, raw_input().split())
arr.sort()

solve()

Submission status: Wrong Answer

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(): return "".join(list(map(str, ans)))


N = ri()
a = rli()
if(len(set(a)) >= 3):
    print("No")
elif(len(set(a)) == 2):
    b = a[:]
    b = [item for item in b if item is not max(a)]
    mi = min(a)
    a = [item for item in a if item is not mi]
    if(a[0]-len(b) <= 0):
        print("No")
    elif(len(a) // (a[0]-len(b)) < 2):
        print("No")
    else:
        print("Yes")
else:
    if(a[0] == N-1):
        print("Yes")
    else:
        if(N // a[0] < 2):
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

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

ans = 'No'
if max(a)-min(a)<=1:
    if a.count(min(a)) == min(a):
        ans = 'Yes'
    elif min(a) == max(a):
            if n % 2 == 0 and min(a) == n-2:
                ans = 'Yes'
            elif min(a) == n-1:
                ans = 'Yes'
print(ans)

Submission status: Wrong Answer

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

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

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

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

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

if n - s[0] <= l[1] <= (n-l[0])*2 and n-(n-l[0])*2 <= s[1] <= n - l[0]:
  print 'Yes'
else:
  print 'No'

Submission status: Wrong Answer

Solution code:


import sys

def judgeUpper(ansList, var):
    for a in ansList:
        if int(a) > var:
            return True
    return False
def judgeEqual(ansList, var, N):
    if int(ansList[0]) != var and int(ansList[1]) != var:
        return False
    count = ansList.count(str(var))
    return count < N - 1 or (count == N and var * 2 > N and var+1 != N)
def judgeLower(ansList, var):
    for a in ansList:
        if int(a) < var - 1:
            return True
    return False
        
N = input()
ansList = input().split(' ')
ansSet = set(ansList)
for i in range(int(N)-1):
    var = i + 1
    if judgeUpper(ansSet, var):
        continue
    if judgeEqual(ansList, var, int(N)):
        continue
    if judgeLower(ansSet, var):
        continue
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:

import sys

def judgeUpper(ansList, var):
    for a in ansList:
        if int(a) > var:
            return True
    return False
def judgeEqual(ansList, var, N):
    if ansList[0] != var and ansList[1] != var:
        return False
    count = ansList.count(str(var))
    return count < N - 1 or (count == N and var * 2 > N and var+1 != N)
def judgeLower(ansList, var):
    for a in ansList:
        if int(a) < var - 1:
            return True
    return False
        
N = input()
ansList = input().split(' ')
ansSet = set(ansList)
for i in range(int(N)-1):
    var = i + 1
    if judgeUpper(ansSet, var):
        continue
    if judgeEqual(ansList, var, int(N)):
        continue
    if judgeLower(ansSet, var):
        continue
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == A[-1] and (A[0] == n-1 or A[0]*2 <= n):
    print("Yes")
elif A[-1] - A[0] > 1:
    print("No")
else:
    if A[0] == n-2:
        if A[-2:] == [n-1]*2 and A[-3] == n-2:
            print("Yes")
        else:
            print("No")
    else:
        if A[A[0]-1] >= A[0] and A[A[0]] == A[0]+1:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:

import sys

def judgeUpper(ansList, var):
    for a in ansList:
        if int(a) > var:
            return True
    return False
def judgeEqual(ansList, var, N):
    count = ansList.count(str(var))
    return count < N - 1 or (count == N and var * 2 > N and var+1 != N)
def judgeLower(ansList, var):
    for a in ansList:
        if int(a) < var - 1:
            return True
    return False
        
N = input()
ansList = input().split(' ')
ansSet = set(ansList)
for i in range(int(N)-1):
    var = i + 1
    if judgeUpper(ansSet, var):
        continue
    if judgeEqual(ansList, var, int(N)):
        continue
    if judgeLower(ansSet, var):
        continue
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == A[-1] and A[0]*2 <= n:
    print("Yes")
elif A[-1] - A[0] > 1:
    print("No")
else:
    if A[0] == n-2:
        if A[-2:] == [n-1]*2 and A[-3] == n-2:
            print("Yes")
        else:
            print("No")
    else:
        if A[A[0]-1] >= A[0]:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
import sys

def judgeUpper(ansList, var):
    for a in ansList:
        if int(a) > var:
#             print(a + ':' + str(var) + str(True))
            return True
    return False
def judgeEqual(ansList, var, N):
    count = ansList.count(str(var))
#     print(str(count) + ':' + str(N-1) + str(count < N - 1))
    return count < N - 1 or (count == N and var * 2 > N and var+1 != N)
def judgeLower(ansList, var):
    for a in ansList:
        if int(a) < var - 1:
#             print(a + ':' + str(var-1) + str(True))
            return True
    return False
        
N = input()
ansList = input().split(' ')
for i in range(int(N)):
    var = i + 1
    if judgeUpper(ansList, var):
        continue
    if judgeEqual(ansList, var, int(N)):
        continue
    if judgeLower(ansList, var):
        continue
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

Solution code:

import sys

def judgeUpper(ansList, var):
    for a in ansList:
        if int(a) > var:
#             print(a + ':' + str(var) + str(True))
            return True
    return False
def judgeEqual(ansList, var, N):
    count = ansList.count(str(var))
#     print(str(count) + ':' + str(N-1) + str(count < N - 1))
    return count < N - 1 or (count == N and var * 2 > N and var+1 != N)
def judgeLower(ansList, var):
    for a in ansList:
        if int(a) < var - 1:
#             print(a + ':' + str(var-1) + str(True))
            return True
    return False
        
N = input()
ansList = input().split(' ')
for i in range(int(N)):
    var = i + 1
    print(var)
    if judgeUpper(ansList, var):
        continue
    if judgeEqual(ansList, var, int(N)):
        continue
    if judgeLower(ansList, var):
        continue
    print('Yes')
    sys.exit()
print('No')

Submission status: Wrong Answer

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

result = True

if len(set(a)) > 1:
    set_min = list(set(a))[0]
    set_max = list(set(a))[1]

    if len(set(a)) > 2:
        result = False
    elif (set_max - set_min) != 1:
        result = False
    else:
        result = (a.count(set_min) < set_max)
else:
    result = (list(set(a))[0] <= N/2 or list(set(a))[0] == N-1)



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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print("Yes")