Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import product
def inpl(): return tuple(map(int, input().split()))
   

S = input()
x, y = inpl()
M = []

d = 0
for s in S:
    if s == "F":
        d += 1
    else:
        M.append(d)
        d = 0
M.append(d)

Cx = Counter(M[2::2])
Cy = Counter(M[1::2])

Lx = []
Ly = []

for k, v in Cx.items():
    if k == 0:
        pass
    else:
        Lx.append(list(range(-k*v, k*v+1, 2*k)))
        
for k, v in Cy.items():
    if k == 0:
        pass
    else:
        Ly.append(list(range(-k*v, k*v+1, 2*k)))

def bfss(Ls, t, f):
    N = set([f])
    for L in Ls:
        nN = set(([n+l for n, l in product(N, L)]))
        N = nN
    if t in N:
        return True
    else:
        return False

if bfss(Lx, x, M[0]) and bfss(Ly, y, 0):
    print("Yes")
else:
    print("No")

Fixed submission:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
C = Counter(A)
res = 0

for k, v in C.items():
    if v < k:
        res += v
    elif v > k:
        res += (v - k)
print(res)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
print((1900*M + (N-M)*100)*pow(2, M))

Fixed submission:
X, Y = input().split()
if X>Y:
  print(">")
elif X == Y:
  print("=")
else:
  print("<")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from bisect import bisect_left
N = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(int, input().split())))

AB = [N for _ in range(N)]
BC = [N for _ in range(N)]
result = 0

j = 0
for i, a in enumerate(A):
    while a >= B[j]:
        AB[j] = i
        j += 1
        if j == N:
            break
    if j == N:
        break

sAB = []
for i in range(N):
    sAB.append(sum(AB[:i+1]))

j = 0
for i, b in enumerate(B):
    while b >= C[j]:
        BC[j] = i
        j += 1
        if j == N:
            break
    if j == N:
        break

for bc in BC:
    if bc:
        result += sAB[bc-1]
print(result)

Fixed submission:
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect
N = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(int, input().split())))

AB = []
result = 0
 
for i in range(N):
    AB = bisect_left(A, B[i])
    BC = N - bisect(C, B[i])
    result += AB * BC

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from bisect import bisect_left
N = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(int, input().split())))

AB = []
result = 0

for i in range(N):
    AB.append(bisect_left(A, B[i]))

sAB = []
for i in range(N):
    sAB.append(sum(AB[:i+1]))

for i in range(N):
    j = bisect_left(B, C[i])
    if j:
        result += sAB[j-1]
print(result)

Fixed submission:
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect
N = int(input())
A = sorted(tuple(map(int, input().split())))
B = sorted(tuple(map(int, input().split())))
C = sorted(tuple(map(int, input().split())))

AB = []
result = 0
 
for i in range(N):
    AB = bisect_left(A, B[i])
    BC = N - bisect(C, B[i])
    result += AB * BC

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from numpy import bitwise_or
from bisect import bisect, insort

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

N, K = inpl()
numbers = []

for _ in range(N):
    A, B = inpl()
    numbers.append([A, B])


res = 0

target = bin(K)[2:]
targets = [target]
while "10" in target:
    n = target.rfind("10")
    new_target = target[:n] + "0" + "1"*(len(target)-n-1)
    targets.append(new_target)
    target = new_target

targets = list(map(int, targets, [2]*len(targets)))

for target in targets:
    tmp = 0
    for a, b in numbers:
        if bitwise_or(target, a) == target:
            tmp += b
    res = max(res, tmp)
print(res)

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): 
    return tuple(map(int, input().split()))

N, K = inpl()
numbers = []

for _ in range(N):
    A, B = inpl()
    numbers.append([A, B])
res = 0

target = bin(K)[2:]
targets = [target]
while "10" in target:
    n = target.rfind("10")
    new_target = target[:n] + "0" + "1"*(len(target)-n-1)
    targets.append(new_target)
    target = new_target

targets = list(map(int, targets, [2]*len(targets)))

for target in targets:
    tmp = 0
    for a, b in numbers:
        if (target | a) == target:
            tmp += b
    res = max(res, tmp)
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
#input = sys.stdin.readline

def inpl(): return list(map(int, input().split()))
A, B, C, D, E, F = inpl()
waters = [100*A*a + 100*B*b for a in range(30//A + 1) for b in range((30-A*a)//B + 1)]
sugars = [C*c + D*d for c in range(3000//C + 1) for d in range((3000-C*c)//D + 1)]

waters = sorted(set(waters))[1:]
sugars = sorted(set(sugars))


def check(m):
    if m > E:
        return False, None, None
    for water in waters:
        sugar_ix = bisect_left(sugars, m*water/(100-m))
        if (sugar_ix == len(sugars)):
            continue
        sugar = sugars[sugar_ix]
        if sugar + water <= F and sugar <= water*E//100:
            return True, sugar, water
    else:
        return False, None, None

OK = 0
NG = E + 1

while abs(OK - NG)>1e-8:
    mid = (OK+NG)/2
    if check(mid)[0]:
        OK = mid
    else:
        NG = mid

_, sugar, water = check(OK)
print(sugar+water, sugar)

Fixed submission:
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor, mul

import sys
#input = sys.stdin.readline

def inpl(): return list(map(int, input().split()))
A, B, C, D, E, F = inpl()
waters = [100*A*a + 100*B*b for a in range(30//A + 1) for b in range((30-A*a)//B + 1)]
sugars = [C*c + D*d for c in range(3000//C + 1) for d in range((3000-C*c)//D + 1)]

waters = sorted(set(waters))[1:]
sugars = sorted(set(sugars))


def check(m):
    if m > E:
        return False, None, None
    for water in waters:
        sugar_ix = bisect_left(sugars, m*water/(100-m))
        if (sugar_ix == len(sugars)):
            continue
        sugar = sugars[sugar_ix]
        if sugar + water <= F and sugar <= water*E//100:
            return True, sugar, water
    else:
        return False, None, None

OK = 0
NG = E + 1

for _ in range(1000):
    mid = (OK+NG)/2
    if check(mid)[0]:
        OK = mid
    else:
        NG = mid

_, sugar, water = check(OK)
print(sugar+water, sugar)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from itertools import combinations

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

N = int(input())
res = 0
exist = True
A = []

for _ in range(N):
    A.append(inpl())

for i, j in combinations(range(N), 2):
    vervose = False

    for k in range(N):
        if A[i][j] > A[i][k] + A[k][j]:
            exist = False
            break
    
    if not exist:
        break
    
    for k in range(N):
        if i == k or j == k:
            pass
        elif A[i][j] == A[i][k] + A[k][j]:
            vervose = True
            break
        
    if not vervose:
        res += A[i][j]
if exist:
    print(res)
else:
    print(-1)


Fixed submission:
# -*- coding: utf-8 -*-
A, B, C, D, E, F = tuple(map(int, input().split()))
A, B = 100*A, 100*B
waters = set([a+b for b in range(0, F+1, B) for a in range(0, F+1, A) if a+b <= F])

res_water = min(A, B)
res_sugar = 0
max_ratio = 0

for w in sorted(waters):
    sugars = [c+d for c in range(0, int(w//100)*E+1, C)
                         for d in range(0, int(w//100)*E+1, D) 
                             if (c+d+w <= F) and (c+d <= int(w/100)*E)]
    sugar = max(sugars)
    #print(sugars)
    if w+sugar==0:
        continue
    if 100*sugar / (w+sugar) > max_ratio:
        max_ratio = 100*sugar / (w+sugar)
        res_water = w
        res_sugar = sugar
print("{} {}".format(res_water+res_sugar, res_sugar))

Buggy python submission (verdict: Runtime Error):
waters = set([a+b for b in range(0, F+1, B) for a in range(0, F+1, A) if a+b <= F])

res_water = 0
res_sugar = 0
max_ratio = 0

for w in sorted(waters):
    sugars = [c+d for c in range(0, int(w/100)*E+1, C)
                         for d in range(0, int(w/100)*E+1, D) 
                             if (c+d+w <= F) and (c+d <=int(w/100)*E)]
    sugar = max(sugars)
    #print(sugars)
    if w+sugar==0:
        continue
    if 100*sugar / (w+sugar) > max_ratio:
        max_ratio = 100*sugar / (w+sugar)
        res_water = w
        res_sugar = sugar
print("{} {}".format(res_water+res_sugar, res_sugar))

Fixed submission:
# -*- coding: utf-8 -*-
A, B, C, D, E, F = tuple(map(int, input().split()))
A, B = 100*A, 100*B
waters = set([a+b for b in range(0, F+1, B) for a in range(0, F+1, A) if a+b <= F])

res_water = min(A, B)
res_sugar = 0
max_ratio = 0

for w in sorted(waters):
    sugars = [c+d for c in range(0, int(w//100)*E+1, C)
                         for d in range(0, int(w//100)*E+1, D) 
                             if (c+d+w <= F) and (c+d <= int(w/100)*E)]
    sugar = max(sugars)
    #print(sugars)
    if w+sugar==0:
        continue
    if 100*sugar / (w+sugar) > max_ratio:
        max_ratio = 100*sugar / (w+sugar)
        res_water = w
        res_sugar = sugar
print("{} {}".format(res_water+res_sugar, res_sugar))
Buggy python submission (verdict: Time Limit Exceeded):

volume = [1,2,4, 8]
value = tuple(map(int, input().split()))
N = int(input())
 
counts = [10**10 for _ in range(N*4 + 1)]
counts[0] = 0
 
for i in range(4):
    for n in range(volume[i], N*4+1):
        counts[n] = min(counts[n], counts[n-volume[i]] + value[i])
 
print(counts[-1])

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

volume = [1, 2, 4, 8]
value = {k:v for k, v in zip(volume, inpl())}
cosp = {k:v/k for k, v in value.items()}
N = int(input())
N = N*4
res = 0

for k, _ in sorted(cosp.items(), key=lambda x: x[1]):
    res += (N // k)*value[k]
    N = N % k
print(int(res))

Buggy python submission (verdict: Runtime Error):
volume = [1,2,4, 8]
value = tuple(map(int, input().split())
N = int(input())

counts = [10**10 for _ in range(N*4 + 1)]
counts[0] = 0

for i in range(4):
    for n in range(volume[i], N*4+1):
        counts[n] = min(counts[n], counts[n-volume[i]] + value[i])

print(counts[-1])

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

volume = [1, 2, 4, 8]
value = {k:v for k, v in zip(volume, inpl())}
cosp = {k:v/k for k, v in value.items()}
N = int(input())
N = N*4
res = 0

for k, _ in sorted(cosp.items(), key=lambda x: x[1]):
    res += (N // k)*value[k]
    N = N % k
print(int(res))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from bisect import bisect_left, insort
from math import pi

def inpl(): return tuple(map(int, input().split()))
sx, sy, gx, gy = inpl()

yrev = False
if sx > gx:
    sx, sy, gx, gy = gx, gy, sx, sy

if sy > gy:
    sy, gy = 10**8 - 1 - sy, 10**8 - 1 - gy 
    yrev = True

N = int(input())
fountains = []

for _ in range(N):
    x, y = inpl()
    if yrev:
        y = 10**8 - 1 - y
    if (sx <= x <= gx) & (sy <= y <= gy):
        insort(fountains, [x, y])

L = []
if len(fountains):
    L.append(fountains[0][1])

for f in fountains: # 最長増加部分列
    x, y = f
    if L[-1] < y:
        L.append(y)
    else:
        L[bisect_left(L, y)] = y

if min(gx - sx, gy - sy) + 1 == len(L):
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*(len(L)-1) + (10*pi - 20))
else:
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*len(L))

Fixed submission:
# -*- coding: utf-8 -*-
from bisect import bisect_left, insort
from math import pi
 
def inpl(): return tuple(map(int, input().split()))
sx, sy, gx, gy = inpl()
 
yrev = False
if sx > gx:
    sx, sy, gx, gy = gx, gy, sx, sy
 
if sy > gy:
    sy, gy = 10**8 - 1 - sy, 10**8 - 1 - gy 
    yrev = True
 
N = int(input())
fountains = []
 
for _ in range(N):
    x, y = inpl()
    if yrev:
        y = 10**8 - 1 - y
    if (sx <= x <= gx) & (sy <= y <= gy):
        fountains.append([x, y])

fountains.sort()
 
L = []
if len(fountains):
    L.append(fountains[0][1])
 
for f in fountains: # 最長増加部分列
    x, y = f
    if L[-1] < y:
        L.append(y)
    else:
        L[bisect_left(L, y)] = y
 
if min(gx - sx, gy - sy) + 1 == len(L):
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*(len(L)-1) + (10*pi - 20))
else:
    print(((gx - sx)+(gy - sy))*100 - (20 - 5*pi)*len(L))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np

K = int(input())
K = K

# astypeを入れないとおかしくなっちゃう
a = np.ones(50).astype(np.int64)*(49) + (K)//50

if K%50 != 0:
    a[:K%50] += 51 - (K%50)
    a[K%50:] -= (K%50)
else:
    pass
              
result = "50\n{}".format(a[0])
for a_ in a[1:]:
    result += (" {}".format(int(a_)))
print(result)

Fixed submission:
# -*- coding: utf-8 -*-

N, M = [int(n) for n in input().split()]
islands = {n:[] for n in range(1, N+1)}
result = "IMPOSSIBLE"

for m in range(M):
    a, b = [int(n) for n in input().split()]
    islands[a].append(b)
    islands[b].append(a)

ok_isl = set()
search_isl = [1]
next_isl = set()

loop = True
for x in range(2):
    for i in search_isl:
        if N in islands[i]:
            loop = False
            result = "POSSIBLE"            
        else:
            next_isl.update(islands[i])
    
    ok_isl = ok_isl.union(search_isl)
    
    search_isl = next_isl.difference(ok_isl)
    if len(search_isl) == 0:
        break

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
 
N = int(input())
A = inpl()
 
print(min([abs(sum(A[:i])-sum(A[i:])) for i in range(1, N)]))

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from itertools import combinations

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

N = int(input())
A = inpl()
s = sum(A)

X = [sum(A[:i]) for i in range(1, N)]
print(min([abs(2*x - s) for x in X]))

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from itertools import combinations

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

N = int(input())
A = inpl()

print(min([abs(sum(A[:i])-sum(A[i:])) for i in range(1, N)]))

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from heapq import heappop, heappush
def inpl(): return map(int, input().split())
N = int(input())

X = []
Y = []

for i in range(N):
    x, y = inpl()
    X.append((i, x))
    Y.append((i, y))

X = sorted(X, key=lambda x: x[1])
Y = sorted(Y, key=lambda y: y[1])

G = [[] for _ in range(N)]
for i in range(N-1):
    Xa, Xb = X[i], X[i+1]
    Ya, Yb = Y[i], Y[i+1]
    G[Xa[0]].append([Xb[0], Xb[1]-Xa[1]])
    G[Xb[0]].append([Xa[0], Xb[1]-Xa[1]])
    
    G[Ya[0]].append([Yb[0], Yb[1]-Ya[1]])
    G[Yb[0]].append([Ya[0], Yb[1]-Ya[1]])

visited = [False]*N
Q = [(0, 0)]
ans = 0

while Q:
    c, n = heappop(Q)
    if visited[n]:
        continue
    visited[n] = True
    ans += c
    
    for m, d in G[n]:
        if visited[m]:
            continue
        else:
            heappush(Q, (d, m))

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
from math import factorial

N, M = [int(n) for n in input().split()]
if abs(N-M) == 0:
    result = factorial(N)**2 * 2
elif abs(N-M) == 1:
    result = factorial(N) * factorial(M)
else:
    result = 0
    
print(result % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from math import factorial

N = int(input())
cities = [[int(m) for m in input().split()] for n in range(N)]

def reasonable_way(A, B):
    A = list(sorted(set(A)))
    B = list(sorted(set(B)))
    
    a = 0
    b = 0
    
    cheap = 10**9 + 1
    
    while a < len(A) and b < len(B):
        if b+1 < len(B):
            while A[a] - B[b+1] > 0:
                if b+1 == len(B):
                    break
                else:
                    b += 1

        cheap = min(abs(A[a] - B[b]), cheap)
        if b+1 < len(B):
            cheap = min(abs(A[a] - B[b+1]), cheap)

        if cheap == 0:
            return 0

        a += 1        

    return cheap

x_key_map = {x: [] for x in set([city[0] for city in cities])}
y_key_map = {y: [] for y in set([city[1] for city in cities])}

for city in cities:
    x_key_map[city[0]].append(city[1])
    y_key_map[city[1]].append(city[1])

x_keys = list(sorted(x_key_map.keys()))
y_keys = list(sorted(y_key_map.keys()))
    
tmp = 0
for i in range(len(x_keys) - 1):
    tmp += min(abs(x_keys[i] - x_keys[i+1]),
               reasonable_way(x_key_map[x_keys[i]], x_key_map[x_keys[i+1]]))

result = tmp
tmp = 0

for i in range(len(y_keys) - 1):
    tmp += min(abs(y_keys[i] - y_keys[i+1]),
               reasonable_way(y_key_map[y_keys[i]], y_key_map[y_keys[i+1]]))    
result = min(result, tmp)

print(result)    

Fixed submission:
# -*- coding: utf-8 -*-
from math import factorial

N, M = [int(n) for n in input().split()]
if abs(N-M) == 0:
    result = factorial(N)**2 * 2
elif abs(N-M) == 1:
    result = factorial(N) * factorial(M)
else:
    result = 0
    
print(result % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from heapq import heappop, heappush
def inpl(): return map(int, input().split())
N = int(input())

X = []
Y = []

for i in range(N):
    x, y = inpl()
    X.append((i, x))
    Y.append((i, y))

X = sorted(X, key=lambda x: x[1])
Y = sorted(Y, key=lambda y: y[1])

G = [[] for _ in range(N)]
for i in range(N-1):
    Xa, Xb = X[i], X[i+1]
    Ya, Yb = Y[i], Y[i+1]
    G[Xa[0]].append([Xb[0], Xb[1]-Xa[1]])
    G[Xb[0]].append([Xa[0], Xb[1]-Xa[1]])
    
    G[Ya[0]].append([Yb[0], Yb[1]-Ya[1]])
    G[Yb[0]].append([Ya[0], Yb[1]-Ya[1]])

visited = [False]*N
Q = [(0, 0)]
ans = 0

while Q:
    c, n = heappop(Q)
    if visited[n]:
        continue
    visited[n] = True
    ans += c
    
    for m, d in G[n]:
        if visited[m]:
            continue
        else:
            heappush(Q, (d, m))

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

n = int(input())
X = []
Y = []
for i in range(n):
    x, y = inpl()
    X.append((x, i))
    Y.append((y, i))

X = sorted(X, key = lambda x: x[0])
Y = sorted(Y, key = lambda y: y[0])

G = [[] for _ in range(n)]
edges = []
for i in range(n-1):
    edges.append((X[i][1], X[i+1][1], abs(X[i][0] - X[i+1][0])))
    edges.append((Y[i][1], Y[i+1][1], abs(Y[i][0] - Y[i+1][0])))

edges = sorted(edges, key = lambda e: e[2])

tree = [[-1, 1] for _ in range(n)]

def find(i):
    if tree[i][0] == -1:
        group = i
    else:
        group = find(tree[i][0])    
    return group
  
def unite(x, y):
    px = find(x)
    py = find(y)
      
    if tree[px][1] == tree[py][1]: # rank is same
        tree[py][0] = px
        tree[px][1] += 1
    else:
        if tree[px][1] < tree[py][1]:
            px, py = py, px
        tree[py][0] = px

res = 0

for s, t, w in edges:
    if find(s) != find(t):
        unite(s, t)
        res += w
print(res)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from queue import Queue

N = int(input())
a = sorted([int(n) for n in input().split()], reverse=True)

alone = a.count(max(a) - 1)

if alone:
    a = [a_ - alone for a_ in a][alone:]
    if len(a) == 2 and a[0] == 1:
        print("Yes")
    elif 2*a[0] <= len(a) and a[0] <= len(a)//a[0]:
        print("Yes")
    else:
        print("No")

else:
    if a[0] == N - 1:
        print("Yes")
    elif 2*a[0] <= len(a) and a[0] <= len(a)//a[0]:
        print("Yes")
    else:
        print("No")

Fixed submission:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

C = Counter(A)

if len(C) >= 3:
    print("No")
elif len(C) == 1:
    for k, v in C.items():
        if k == N-1 or N >= 2*k:
            print("Yes")
        else:
            print("No")
else:
    k = sorted(C.keys())[0]
    v = C[k]
    X = N - v
    if (k+1-v) * 2 <= C[k+1] and v <= k:
        print("Yes")
    else:
        print("No")