Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
src = list(map(int,input().split()))
odd = two = four = 0
for a in src:
    if a%2: odd += 1
    elif a%4==0: four += 1
    else: two += 1
if two:
    print('Yes' if odd <= four else 'No)
else:
    print('Yes' if odd <= four+1 else 'No')

Fixed submission:
N = int(input())
src = list(map(int, input().split()))

x1 = x2 = x4 = 0
for a in src:
    if a%2 == 1:
        x1 += 1
    elif a%4 == 0:
        x4 += 1
    else:
        x2 += 1

def solve():
    if x4 >= x1: return True
    if x4 + 1 == x1:
        return x2 == 0
    else: return False

print('Yes' if solve() else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
mem = [[] for i in range(N)]

p1 = []
p2 = []
def solve():
    for i in range(M):
        a,b = map(int, input().split())
        if a == 1:
            p1.append(b)
        elif b == N:
            p2.append(a)
    for p in p1:
        if p in p2: return True
    return False

print('POSSIBLE' if solve() else 'IMPOSSIBLE')


Fixed submission:
N,M = map(int, input().split())
mem = [[] for i in range(N)]

p1 = []
p2 = []
def solve():
    for i in range(M):
        a,b = map(int, input().split())
        if a == 1:
            p1.append(b)
        elif b == N:
            p2.append(a)
    return len(set(p1) & set(p2)) > 0

print('POSSIBLE' if solve() else 'IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

ans = 0
while 1:
    j = -1
    for i,a in enumerate(A):
        if a >= N:
            j = i
            break
    else:
        break
    d,m = divmod(A[j],N)
    ans += d
    A[j] = m
    for i in range(N):
        if i==j: continue
        A[i] += d
print(ans)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))

ans = 0
while any(map(lambda x: x >= N, a)):
    a.sort(reverse=True)
    k = (a[0] - N)//N + 1
    ans += k
    a[0] -= k*N
    for i in range(1,N):
        a[i] += k

print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,raw_input().split())
src = map(int,raw_input().split())

def solve():
  if N == 1: return src[0] == K
  mx = max(src)
  if K > mx: return False
  g = src[0]
  for i in range(1,N):
    g = gcd(g, src[i])
    if g == 1:
      return True
  return K % g == 0

print ('POSSIBLE' if solve() else 'IMPOSSIBLE')

Fixed submission:
N,K = map(int,raw_input().split())
src = map(int,raw_input().split())

def gcd(a,b):
  a,b = max(a,b),min(a,b)
  if b == 0:
    return a
  return gcd(b, a%b)

def solve():
  if N == 1: return src[0] == K
  mx = max(src)
  if K > mx: return False
  g = src[0]
  for i in range(1,N):
    g = gcd(g, src[i])
    if g == 1:
      return True
  return K % g == 0

print ('POSSIBLE' if solve() else 'IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0

Fixed submission:
import heapq

def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0

Buggy python submission (verdict: Runtime Error):
def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0 
    

N = input()
S = [input() for i in range(N)]
scores = S[:]

print solve(scores)

Fixed submission:
import heapq

def solve(scores):
  sm = sum(scores)
  if(sm % 10 != 0): return sm
  heapq.heapify(scores)
  while scores:
    mn = heapq.heappop(scores)
    sm -= mn
    if(sm % 10 != 0) : return sm
    sm += mn
  else:
    return 0     

N = input()
S = [input() for i in range(N)]
heapq.heapify(S)

while S:
  arr = [i for i in S]
  best = solve(arr)
  if(best > 0):
    print best
    break
  heapq.heappop(S)
else:
  print 0
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,K = map(int,input().split())
src = [int(input()) for i in range(N)]
if N == 1:
    print(int(src[0]>=K))
    exit()

cums = [0]
for a in src:
    cums.append(cums[-1] + a - K)

s_cums = sorted(cums)
cmp = []
for a in cums:
    i = bisect.bisect(s_cums, a)
    cmp.append(i-1)

bit = [0] * (N+1)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for a in cmp:
    ans += bit_sum(a)
    bit_add(a, 1)
print(ans)


Fixed submission:
N,K = map(int,input().split())
src = [int(input()) for i in range(N)]

cums = [(0,1)]
for i,a in enumerate(src):
    cums.append((cums[-1][0] + a - K, i+2))

bit = [0] * (N+2)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for i,a in sorted(cums):
    ans += bit_sum(a-1)
    bit_add(a, 1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,K = map(int,input().split())
src = [int(input()) for i in range(N)]
if N == 1:
    print(int(src[0]>=K))
    exit()

cums = [0]
for a in src:
    cums.append(cums[-1] + a - K)

s_cums = sorted(cums)
cmp = []
for a in cums:
    i = bisect.bisect(s_cums, a)
    cmp.append(i-1)

bit = [0] * (N+1)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for a in cmp:
    ans += bit_sum(a)
    bit_add(a, 1)
print(ans)


Fixed submission:
N,K = map(int,input().split())
src = [int(input()) for i in range(N)]

cums = [(0,1)]
for i,a in enumerate(src):
    cums.append((cums[-1][0] + a - K, i+2))

bit = [0] * (N+2)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for i,a in sorted(cums):
    ans += bit_sum(a-1)
    bit_add(a, 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
    for a,b,c in ABC:
        a,b,c = a-1,b-1,-c
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            if i==N-1 and to == N-1:
                print('inf')
                exit()
print(-dist[-1])

Fixed submission:
N,M = map(int,input().split())
es = []
for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1, b-1
    c *= -1
    es.append((a,b,c))

INF = float('inf')
def solve():
    d = [INF for i in range(N)]
    d[0] = 0
    for i in range(N):
        for fr,to,cost in es:
            if d[fr] == INF: continue
            if d[to] > d[fr] + cost:
                d[to] = d[fr] + cost
                if i == N-1 and to == N-1: return 'inf'
    return -d[N-1]

print(solve())
Buggy python submission (verdict: Runtime Error):
N,M = map(int, raw_input().split())
hist = {}
for i in range(N):
  a,b = map(int, raw_input().split())
  if a in hist:
    hist[a] += 1
  else:
    hist[a] = 1
  if b in hist:
    hist[b] += 1
  else:
    hist[b] = 1

for v in hist.values():
  if v%2 == 1:
    print 'NO'
    break
else : print 'YES'

Fixed submission:
N,M = map(int, raw_input().split())
hist = [0 for i in range(N)]
for i in range(M):
  a,b = map(int, raw_input().split())
  hist[a-1] += 1
  hist[b-1] += 1
for v in hist:
  if v%2 == 1:
    print 'NO'
    break
else : print 'YES'
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W,K = map(int,input().split())
src = [input() for i in range(H)]
sx = sy = None
for i,row in enumerate(src):
    if 'S' in row:
        sy = i
        sx = row.index('S')

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
visited = [[0]*W for i in range(H)]
visited[sy][sx] = 1
q = deque([(0,sx,sy)])
mindist = H+W
while q:
    d,x,y = q.popleft()
    if d > K: break
    dist = min(x, W-x-1, y, H-y-1)
    mindist = min(dist, mindist)
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if src[ny][nx] == '#': continue
        if visited[ny][nx]: continue
        q.append((d+1,nx,ny))
        visited[ny][nx] = 1

ans = -(-mindist//K) + 1
print(ans)

Fixed submission:
from collections import deque

H,W,K = map(int,input().split())
src = [input() for i in range(H)]
sx = sy = None
for i,row in enumerate(src):
    if 'S' in row:
        sy = i
        sx = row.index('S')

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
visited = [[0]*W for i in range(H)]
visited[sy][sx] = 1
q = deque([(0,sx,sy)])
mindist = H+W
while q:
    d,x,y = q.popleft()
    if d > K: break
    dist = min(x, W-x-1, y, H-y-1)
    mindist = min(dist, mindist)
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if src[ny][nx] == '#': continue
        if visited[ny][nx]: continue
        q.append((d+1,nx,ny))
        visited[ny][nx] = 1

ans = -(-mindist//K) + 1
print(ans)
Buggy python submission (verdict: Runtime Error):
def solve():
  ar = raw_input().split(' ')
  A = int(ar[0])
  B = int(ar[1])
  C = int(ar[2])

  s = set([])
  sum = 0
  while True:
    sum = sum + A
    m = sum % B
    #print 'sum=',sum,'m=',m
    if (m == C): return 'Yes'
    if (m in s): return 'No'
    s.add(m)

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

Fixed submission:
def solve():
  ar = raw_input().split(' ')
  A = ar[0]
  B = ar[1]
  C = ar[2]
  if A[-1] == B[0] and B[-1] == C[0] : return 'YES'
  else: return 'NO'

if __name__ == '__main__' :
  print solve()
Buggy python submission (verdict: Runtime Error):
N = int(input())
src = map(int,input().split())
asc = 0
ans = 1
for i in range(N-1):
    d = src[i+1] - src[i]
    if asc * d < 0:
        ans += 1
        asc = 0
    else:
        asc = d
print(ans)

Fixed submission:
N = int(input())
src = list(map(int,input().split()))
asc = None
ans = 1
for i in range(N-1):
    d = src[i+1] - src[i]
    if d == 0: continue
    if asc is None:
        asc = d > 0
    elif (asc and d < 0) or (not asc and d > 0):
        ans += 1
        asc = None
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)

N,M = map(int,input().split())
src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

es = [[] for i in range(N)]
for a,b in src:
    es[a].append(b)
    es[b].append(a)

cs = [0] * N
depth = [0] * N

def rec(v,d,c,pv):
    if d < depth[v]: return
    depth[v] = d
    if cs[v]==0:
        cs[v] = c
    if d==0: return
    for to in es[v]:
        if to==pv: continue
        rec(to,d-1,c,v)

for v,d,c in qs[::-1]:
    rec(v-1,d,c,-1)

print(*cs, sep='\n')

Fixed submission:
import sys
sys.setrecursionlimit(101010)

N,M = map(int,input().split())
es = [[] for i in range(N)]
for i in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    es[a].append(b)
    es[b].append(a)
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

mem = [[0,-1] for i in range(N)] # [color,depth] for v
def paint(v,d,c):
    mc,md = mem[v]
    if d <= md: return
    mem[v] = [mc if mc else c, d]
    if d == 0: return
    for to in es[v]:
        paint(to,d-1,c)

for v,d,c in reversed(qs):
    paint(v-1,d,c)
for c,d in mem:
    print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)

N,M = map(int,input().split())
src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

es = [[] for i in range(N)]
for a,b in src:
    es[a].append(b)
    es[b].append(a)

cs = [0] * N
depth = [0] * N

def rec(v,d,c):
    if d < depth[v]: return
    depth[v] = d
    if cs[v]==0:
        cs[v] = c
    if d==0: return
    for to in es[v]:
        rec(to,d-1,c)

for v,d,c in qs[::-1]:
    rec(v-1,d,c)

print(*cs, sep='\n')

Fixed submission:
import sys
sys.setrecursionlimit(101010)

N,M = map(int,input().split())
es = [[] for i in range(N)]
for i in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    es[a].append(b)
    es[b].append(a)
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

mem = [[0,-1] for i in range(N)] # [color,depth] for v
def paint(v,d,c):
    mc,md = mem[v]
    if d <= md: return
    mem[v] = [mc if mc else c, d]
    if d == 0: return
    for to in es[v]:
        paint(to,d-1,c)

for v,d,c in reversed(qs):
    paint(v-1,d,c)
for c,d in mem:
    print(c)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N,A,B = map(int,input().split())
src = list(map(int,input().split()))
src.sort(reverse=True)

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
elif cnt == A:
    print(1)
else:
    ans = 0
    for r in range(A,B+1):
        ans += ncr[cnt][r]
    print(ans)


Fixed submission:
from collections import Counter
N,A,B = map(int,input().split())
src = list(map(int,input().split()))
src.sort(reverse=True)

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
elif cnt == A:
    print(1)
else:
    ans = 0
    for r in range(A, min(B,cnt)+1):
        ans += ncr[cnt][r]
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N,A,B = map(int,input().split())
src = list(map(int,input().split()))
src.sort(reverse=True)

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
else:
    ans = 0
    for r in range(A,B+1):
        ans += ncr[cnt][r]
    print(ans)


Fixed submission:
from collections import Counter
N,A,B = map(int,input().split())
src = list(map(int,input().split()))
src.sort(reverse=True)

ave = sum(src[:A]) / A
print(ave)

counter = Counter(src)
cnt = counter[src[0]]

ncr = [[1]]
for n in range(1,N+1):
    ncr.append([1])
    for r in range(1,n):
        ncr[n].append(ncr[n-1][r-1] + ncr[n-1][r])
    ncr[n].append(1)

if cnt < A:
    last = src[A-1]
    n = counter[last]
    r = src[:A].count(last)
    print(ncr[n][r])
elif cnt == A:
    print(1)
else:
    ans = 0
    for r in range(A, min(B,cnt)+1):
        ans += ncr[cnt][r]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

dic = defaultdict(lambda: [])
for i,a in enumerate(src):
    dic[a].append(i)
order = sorted(list(dic.items()))

hist = [0] * N
while True:
    a1,l1 = order.pop()
    if not order:
        hist[min(l1)] += len(l1) * a1
        break
    a2,l2 = order[-1]
    hist[min(l1)] += len(l1) * (a1-a2)
    l2 += l1

print(*hist, sep='\n')


Fixed submission:
from collections import defaultdict

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

dic = defaultdict(lambda:(N,0))
for i,a in enumerate(src):
    m,n = dic[a]
    dic[a] = (min(m,i), n+1)
order = sorted(list(dic.items()))

hist = [0] * N
while True:
    a1, (m1, n1) = order.pop()
    if not order:
        hist[m1] += n1 * a1
        break
    a2, (m2, n2) = order[-1]
    hist[m1] += n1 * (a1-a2)
    order[-1] = (a2, (min(m1,m2), n1+n2))

print(*hist, sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
N,MA,MB = map(int,raw_input().split())
src = []
sum_a = sum_b = 0
for i in range(N):
  a,b,c = map(int,raw_input().split())
  src.append((a,b,c))
  sum_a += a
  sum_b += b

INF = 10**9
dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  ai,bi,ci = src[i]
  for a in range(sum_a+1 - ai):
    for b in range(sum_b+1 - bi):
      dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)

ans = INF
n = 1
while True:
  a,b = n*MA,n*MB
  if a > sum_a or b > sum_b: break
  ans = min(ans, dp[N][a][b])
  n += 1

print(ans if ans != INF else -1)

Fixed submission:
N,MA,MB = map(int,raw_input().split())
src = []
sum_a = sum_b = 0
for i in range(N):
  a,b,c = map(int,raw_input().split())
  src.append((a,b,c))
  sum_a += a
  sum_b += b

INF = 10**9
dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  ai,bi,ci = src[i]
  for a in range(sum_a+1 - ai):
    for b in range(sum_b+1 - bi):
      if dp[i][a][b] == INF: continue
      dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)

ans = INF
n = 1
while True:
  a,b = n*MA,n*MB
  if a > sum_a or b > sum_b: break
  ans = min(ans, dp[N][a][b])
  n += 1

print(ans if ans != INF else -1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
src = map(int,input().split())
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i] - K*i for i in range(N)]
mem.append(mem[0])
for a,b in zip(mem,mem[1:]):
    if (a-b)%N:
        print('NO')
        exit()
print('YES')

Fixed submission:
N = int(input())
src = list(map(int,input().split()))
S = sum(src)
M = N*(N+1)//2

if S%M:
    print('NO')
    exit()

K = S//M
mem = [src[i+1] - src[i] - K for i in range(N-1)]
mem.append(src[0] - src[N-1] - K)

print('YES' if all(map(lambda x:x<=0 and x%N==0, mem)) else 'NO')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(101010)

N = int(input())
won = [[] for i in range(N)]
for i in range(1,N):
    a = int(input()) - 1
    won[a].append(i)

def height(v):
    if not won[v]: return 0
    hs = [height(op) for op in won[v]]
    ret = 0
    for i,h in enumerate(sorted(hs)):
        ret = max(ret, h + len(hs) - i)
    return ret

print(height(0))

Fixed submission:
import sys
sys.setrecursionlimit(202020)

N = int(input())
won = [[] for i in range(N)]
for i in range(1,N):
    a = int(input()) - 1
    won[a].append(i)

def height(v):
    if not won[v]: return 0
    hs = [height(op) for op in won[v]]
    ret = 0
    for i,h in enumerate(sorted(hs)):
        ret = max(ret, h + len(hs) - i)
    return ret

print(height(0))
Buggy python submission (verdict: Runtime Error):
I,O,_,J,L,_,_ = map(int,input().split())
ans1 = O + I-I%2 + J-J%2 + L-L%2
ans2 = 0
if I and J and K:
    I,J,K = I-1,J-1,K-1
    ans2 = 3 + O + I-I%2 + J-J%2 + L-L%2
print(max(ans1,ans2))

Fixed submission:
I,O,T,J,L,S,Z = map(int,input().split())
p = 2*(I//2 + J//2 + L//2)
if I and J and L:
    p = max(p, 2*((I-1)//2 + (J-1)//2 + (L-1)//2) + 3)
print(O + p)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
Y = sorted([(x-1,i+1) for i,x in enumerate(X)])

ans = [None] * (N*N)
must = []
for i,n in Y:
    ans[i] = n
    must += [n]*(n-1)
must.reverse()

used = [0] * (N+1)
free = [1]
for i in range(N*N):
    if ans[i]:
        a = ans[i]
        if used[a] != a-1:
            print('No')
            exit()
        free += [a]*(N-a)
    elif must:
        a = must.pop()
        ans[i] = a
    else:
        if free:
            a = free.pop()
            ans[i] = a
        else:
            print('No')
            exit()
    used[ans[i]] += 1

for i in range(1,N+1):
    assert used[i] == N

print('Yes')
print(*ans)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
Y = sorted([(x-1,i+1) for i,x in enumerate(X)])

ans = [None] * (N*N)
must = []
for i,n in Y:
    ans[i] = n
    must += [n]*(n-1)
must.reverse()

used = [0] * (N+1)
free = [1]
for i in range(N*N):
    if ans[i]:
        a = ans[i]
        if used[a] != a-1:
            print('No')
            exit()
        free += [a]*(N-a)
    elif must:
        a = must.pop()
        ans[i] = a
    else:
        if free:
            a = free.pop()
            ans[i] = a
        else:
            print('No')
            exit()
    used[ans[i]] += 1

for i in range(1,N+1):
    if used[i] != N:
        print('No')
        exit()

print('Yes')
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,X = map(int,input().split())
ans = 0
for a in range(A,B+1):
    if a%X==0:
        ans += 1
print(ans)

Fixed submission:
a,b,x = map(int, raw_input().split())

first = a/x
if a%x > 0 : first += 1
last = b/x
ans = last - first + 1
print ans
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

par = [i for i in range(N+M)]
def root(a):
    if par[a] == a: return a
    par[a] = root(par[a])
    return par[a]

def same(a,b):
    return root(a) == root(b)

def unite(a,b):
   ra,rb = root(a),root(b)
   if ra == rb: return
   par[ra] = rb

for i in range(N):
    src = list(map(lambda x:int(x)-1,input().split()))
    if len(src) == 1: continue
    for j in src[1:]:
        unite(i,N+j)

for i in range(1,N):
    if not same(0,i):
        print('NO')
        exit()
print('YES')


Fixed submission:
import sys
sys.setrecursionlimit(2 * 10**5)
N,M = map(int,input().split())

par = [i for i in range(N+M)]
def root(a):
    if par[a] == a: return a
    par[a] = root(par[a])
    return par[a]

def same(a,b):
    return root(a) == root(b)

def unite(a,b):
   ra,rb = root(a),root(b)
   if ra == rb: return
   par[ra] = rb

for i in range(N):
    src = list(map(lambda x:int(x)-1,input().split()))
    if len(src) == 1: continue
    for j in src[1:]:
        unite(i,N+j)

for i in range(1,N):
    if not same(0,i):
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

par = [i for i in range(N+M)]
def root(a):
    if par[a] == a: return a
    return root(par[a])

def same(a,b):
    return root(a) == root(b)

def unite(a,b):
   ra,rb = root(a),root(b)
   if ra == rb: return
   par[ra] = rb

for i in range(N):
    src = list(map(lambda x:int(x)-1,input().split()))
    for j in src[1:]:
        unite(i,N+j)

for i in range(1,N):
    if not same(0,i):
        print('NO')
        exit()
print('YES')

Fixed submission:
import sys
sys.setrecursionlimit(2 * 10**5)
N,M = map(int,input().split())

par = [i for i in range(N+M)]
def root(a):
    if par[a] == a: return a
    par[a] = root(par[a])
    return par[a]

def same(a,b):
    return root(a) == root(b)

def unite(a,b):
   ra,rb = root(a),root(b)
   if ra == rb: return
   par[ra] = rb

for i in range(N):
    src = list(map(lambda x:int(x)-1,input().split()))
    if len(src) == 1: continue
    for j in src[1:]:
        unite(i,N+j)

for i in range(1,N):
    if not same(0,i):
        print('NO')
        exit()
print('YES')