Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03855 (python)

Fixed submission:
from collections import Counter
N,K,L = map(int,input().split())

p_road = [i for i in range(N)]
p_rail = [i for i in range(N)]

def root(a,par):
    if a == par[a]: return a
    par[a] = root(par[a],par)
    return par[a]

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

for i in range(K):
    a,b = map(lambda x:int(x)-1, input().split())
    unite(a,b,p_road)

for i in range(L):
    a,b = map(lambda x:int(x)-1, input().split())
    unite(a,b,p_rail)

road_ids = []
rail_ids = []
for i in range(N):
    road_ids.append(root(i,p_road))
    rail_ids.append(root(i,p_rail))

ctr = Counter()
for a,b in zip(road_ids, rail_ids):
    ctr.update([(a,b)])

print(' '.join(list(map(str, [ctr[(road_ids[i], rail_ids[i])] for i in range(N)]))))

Buggy submission (verdict: Runtime Error):
N,K,L = map(int, raw_input().split())
roads = [-1 for i in range(N)]
rails = [-1 for i in range(N)]
same_roads = {}
same_rails = {}

max_road_id = -1
for i in range(K):
  p,q = map(int, raw_input().split())
  p -= 1
  q -= 1
  if roads[p] < 0 and roads[q] < 0:
    max_road_id += 1
    roads[p] = max_road_id
    roads[q] = max_road_id
  elif roads[p] == roads[q]:
    continue
  elif roads[p] >= 0 and roads[q] < 0:
    roads[q] = roads[p]
  elif roads[q] < 0 and roads[q] >= 0:
    roads[p] = roads[q]
  else:
    same_roads[max(roads[p],roads[q])] = min(roads[p],roads[q]) 
distinct_roads = [i for i in range(max_road_id + 1)]
for road_id in range(max_road_id, -1, -1):
  if road_id in same_roads:
    distinct_roads[road_id] = same_roads[road_id]
 
max_rail_id = -1
for i in range(L):
  r,s = map(int, raw_input().split())
  r -= 1
  s -= 1
  if rails[r] < 0 and rails[s] < 0:
    max_rail_id += 1
    rails[r] = max_rail_id
    rails[s] = max_rail_id
  elif rails[r] == rails[s]:
    continue
  elif rails[r] >= 0 and rails[s] < 0:
    rails[s] = rails[r]
  elif rails[r] < 0 and rails[s] >= 0:
    rails[r] = rails[s]
  else:
    same_rails[max(rails[r],rails[s])] = min(rails[r],rails[s])
distinct_rails = [i for i in range(max_rail_id + 1)]
for rail_id in range(max_rail_id, -1, -1):
  if rail_id in same_rails:
    distinct_rails[rail_id] = same_rails[rail_id]

combi_counts = {}
for i in range(N):
  road = roads[i]
  rail = rails[i]
  if road < 0 or rail < 0:
    continue
  if (road,rail) in combi_counts:
    combi_counts[(distinct_roads[road],distinct_rails[rail])] += 1
  else:
    combi_counts[(distinct_roads[road],distinct_rails[rail])] = 1

result = []
for i in range(N):
  road = roads[i]
  rail = rails[i]
  if road < 0 or rail < 0:
    result.append(1)
  else:
    result.append(combi_counts[(distinct_roads[road],distinct_rails[rail])])
print ' '.join(map(str, result))
Problem p03921 (python)

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 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')

Buggy 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')
Problem p03994 (python)

Fixed submission:
S = input()
k = int(input())
goal = ord('z') + 1
ans = []
for c in S:
    if c == 'a':
        ans.append('a')
        continue
    d = goal - ord(c)
    if k >= d:
        k -= d
        ans.append('a')
    else:
        ans.append(c)
last = (k + ord(ans[-1]) - ord('a')) % 26
ans[-1] = chr(ord('a') + last)
print(''.join(ans))

Buggy submission (verdict: Runtime Error):
S = input()
k = int(input())
goal = ord('z') + 1
ans = []
for c in S:
    if c == 'a': continue
    d = goal - ord(c)
    if k >= d:
        k -= d
        ans.append('a')
    else:
        ans.append(c)
last = (k + ord(ans[-1]) - ord('a')) % 26
ans[-1] = chr(ord('a') + last)
print(''.join(ans))
Problem p02537 (python)

Fixed submission:
n,k = map(int,input().split())
scale = 21
#scale = 4
seg = [0 for _ in range(2**scale)]
db = [2**i for i in range(scale)]
rdb = list(reversed(db))
#print(rdb)
for _ in range(n):
  c = int(input())
  l = max(c-k,0)
  r = min(c+k+1,2**(scale-1))
  maxi = 0
  now = [[l,r]]
  #print(now)
  for i in range(scale):
    last = now
    now = []
    for xy in last:
      x,y = xy
      if x == y:
        continue
      X = (x-1) // rdb[i] + 1
      Y = y     // rdb[i]
      #print(x,y,X,Y,rdb[i])
      if X < Y:
        for Z in range(X,Y):
          maxi = max(maxi,seg[db[i]+Z])
        now.append([x,X*rdb[i]])
        now.append([Y*rdb[i],y])
      else:
        now.append(xy)
      #print(int(X<Y),X,maxi)
    #print(now,rdb[i],maxi)
  c += db[-1]
  while True:
    seg[c] = max(seg[c],maxi + 1)
    c //= 2
    if not c:
      break
  #print(seg)
print(seg[1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
scale = 21
scale = 3
seg = [0 for _ in range(2**scale)]
db = [2**i for i in range(scale)]
rdb = list(reversed(db))
#print(db)
#print(rdb)
#print(db)
for _ in range(n):
  c = int(input())
  l = max(c-k,0)
  r = min(c+k+1,2**(scale-1))
  maxi = 0
  now = [[l,r]]
  #print(now)
  for i in range(scale):
    last = now
    now = []
    for xy in last:
      x,y = xy
      if x == y:
        continue
      X = (x-1) // rdb[i] + 1
      Y = y     // rdb[i]
      #print(x,y,X,Y,rdb[i])
      if X < Y:
        maxi = max(maxi,seg[db[i]+X])
        now.append([x,X*rdb[i]])
        now.append([Y*rdb[i],y])
      else:
        now.append(xy)
      #print(int(X<Y),X,maxi)
    #print(now,i,maxi)
  c += db[-1]
  while True:
    seg[c] = max(seg[c],maxi + 1)
    c //= 2
    if not c:
      break
  #print(seg)
print(seg[1])
Problem p02541 (python)

Fixed submission:
n = int(input())
n *= 2
ans = []
ans2 = []
for i in range(2,32*10**6):
  if n % i == 0:
    ans.append(i)
    n //= i
    cnt = 1
    while n % i == 0:
      n //= i
      cnt += 1
    ans2.append(cnt)
if n != 1:
  ans.append(n)
  ans2.append(1)
#print(ans)
#print(ans2)
l = len(ans)
for i in range(l):
  ans[i] **= ans2[i]
#print(ans)
if len(ans) == 1:
  print(ans[0]-1)
  exit()
time = [0 for _ in range(l)]
def nex(time):
  for i in range(l):
    if time[i] == 0:
      time[i] = 1
      return time
    else:
      time[i] = 0
  else:
    return 'over'
can = []
while time != 'over':
  x = 1
  y = 1
  for i in range(l):
    if time[i] == 0:
      x *= ans[i]
    else:
      y *= ans[i]
  #print(x,y)
  X = int(x)
  Y = int(y)
  if x > y:
    rec = []
    while y != 1:
      rec.append(x//y)
      x,y = y,x%y
    #print(rec)
    if rec:
      le = len(rec)
      rec.reverse()
      now = [1,-rec[0]]
      for j in range(1,le):
        #print(now)
        now[0],now[1] = now[1],now[0]-now[1]*rec[j]
      #print(now)
      #print(min(abs(X*now[0]),abs(Y*now[1])))
      can.append(min(abs(X*now[0]),abs(Y*now[1])))
  time = nex(time)
print(min(can))

Buggy submission (verdict: Runtime Error):
n = int(input())
n *= 2
ans = []
ans2 = []
for i in range(2,32*10**6):
  if n % i == 0:
    ans.append(i)
    n //= i
    cnt = 1
    while n % i == 0:
      n //= i
      cnt += 1
    ans2.append(cnt)
if n != 1:
  ans.append(n)
  ans2.append(1)
#print(ans)
#print(ans2)
l = len(ans)
for i in range(l):
  ans[i] **= ans2[i]
#print(ans)
time = [0 for _ in range(l)]
def nex(time):
  for i in range(l):
    if time[i] == 0:
      time[i] = 1
      return time
    else:
      time[i] = 0
  else:
    return 'over'
can = []
while time != 'over':
  x = 1
  y = 1
  for i in range(l):
    if time[i] == 0:
      x *= ans[i]
    else:
      y *= ans[i]
  #print(x,y)
  X = int(x)
  Y = int(y)
  if x > y:
    rec = []
    while y != 1:
      rec.append(x//y)
      x,y = y,x%y
    #print(rec)
    if rec:
      le = len(rec)
      rec.reverse()
      now = [1,-rec[0]]
      for j in range(1,le):
        #print(now)
        now[0],now[1] = now[1],now[0]-now[1]*rec[j]
      #print(now)
      #print(min(abs(X*now[0]),abs(Y*now[1])))
      can.append(min(abs(X*now[0]),abs(Y*now[1])))
  time = nex(time)
print(min(can))
Problem p02733 (python)

Fixed submission:
h,w,K = map(int,input().split())
cum = [[0 for _ in range(w+1)]]
for _ in range(h):
  tmp = input()
  add = [0]
  for j in range(w):
    add.append(add[-1]+int(tmp[j]))
  cum.append(add)
for i in range(h):
  for j in range(w):
    cum[i+1][j+1] += cum[i][j+1]
time = [0 for _ in range(h-1)]
def nex(time):
  for d in range(h-1):
    if time[d] == 0:
      time[d] = 1
      return time
    else:
      time[d] = 0
  else:
    return 'over'
can = []
while time != 'over':
  tmp = [0]
  for d in range(h-1):
    if time[d] == 1:
      tmp.append(d+1)
  tmp.append(h)
  #print(tmp,time)
  l = len(tmp) - 1
  ans = l - 1
  now = 0
  att = 1
  for j in range(1,w+1):
    cand = []
    for k in range(l):
      cand.append(cum[tmp[k+1]][j] - cum[tmp[k+1]][now] - cum[tmp[k]][j] + cum[tmp[k]][now])
    #print(cand,now,tmp)
    if max(cand) > K:
      now = j - 1
      ans += 1
      cane = []
      for k in range(l):
        cane.append(cum[tmp[k+1]][j] - cum[tmp[k+1]][now] - cum[tmp[k]][j] + cum[tmp[k]][now])
        #if tmp == [0,1,3]:
          #print(cane,j)
        if max(cane) > K:
          ans += 1
          now = j
    #print(l-1,ans,time)
  else:
    can.append(ans)
  time = nex(time)
  #print(tmp,l-1,ans)
print(min(can))

Buggy submission (verdict: Runtime Error):
h,w,K = map(int,input().split())
cum = [[0 for _ in range(w+1)]]
for _ in range(h):
  tmp = input()
  add = [0]
  for j in range(w):
    add.append(add[-1]+int(tmp[j]))
  cum.append(add)
for i in range(h):
  for j in range(w):
    cum[i+1][j+1] += cum[i][j+1]
time = [0 for _ in range(h-1)]
def nex(time):
  for d in range(h-1):
    if time[d] == 0:
      time[d] = 1
      return time
    else:
      time[d] = 0
  else:
    return 'over'
can = []
while time != 'over':
  tmp = [0]
  for d in range(h-1):
    if time[d] == 1:
      tmp.append(d+1)
  tmp.append(h)
  #print(tmp,time)
  l = len(tmp) - 1
  ans = l - 1
  now = 0
  att = 1
  for j in range(1,w+1):
    cand = []
    for k in range(l):
      cand.append(cum[tmp[k+1]][j] - cum[tmp[k+1]][now] - cum[tmp[k]][j] + cum[tmp[k]][now])
    #print(cand,now,tmp)
    if max(cand) > K:
      if att == 1:
        break
      now = j - 1
      ans += 1
      att = 1
    else:
      att = 0
  else:
    #print(l-1,ans,time)
    can.append(ans)
  time = nex(time)
  #print(tmp,l-1,ans)
print(min(can))
Problem p02778 (python)

Fixed submission:
l = len(input())
print('x'*l)

Buggy submission (verdict: Runtime Error):
s = input()
l = len(input())
print('x'*l)
Problem p02874 (python)

Fixed submission:
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(int,input().split())))
raw.sort(key= lambda x: x[1])
EF = []
for i in range(n):
  EF.append(raw[i][1])
SL1 = [raw[0][0]]
for i in range(1,n):
  SL1.append(max(SL1[-1],raw[i][0]))
SL2 = [raw[-1][0]]
for i in range(1,n):
  SL2.append(max(SL2[-1],raw[n-i-1][0]))
SL2.reverse()
#print(EF)
#print(SL1)
#print(SL2)
can = []
for i in range(n-1):
  tmp = max(EF[0]-SL1[i]+1,0) + max(EF[i+1]-SL2[i+1]+1,0)
  can.append(tmp)
#print(can)
ans1 = max(can)
xlen = []
xl = []
xr = []
for i in range(n):
  xlen.append(raw[i][1] - raw[i][0] + 1)
  xl.append(raw[i][0])
  xr.append(raw[i][1])
#print(max(xl))
ans2 = max(xlen) + max(0,min(xr)-max(xl)+1)
print(max(ans1,ans2))

Buggy submission (verdict: Runtime Error):
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(int,input().split())))
raw.sort(key= lambda x: x[1])
EF = []
for i in range(n):
  EF.append(raw[i][1])
SL1 = [raw[0][0]]
for i in range(1,n):
  SL1.append(max(SL1[-1],raw[i][0]))
SL2 = [raw[-1][0]]
for i in range(1,n):
  SL2.append(max(SL2[-1],raw[n-i-1][0]))
SL2.reverse()
#print(EF)
#print(SL1)
#print(SL2)
can = []
for i in range(n-1):
  if EF[0] - SL1[i] + 1 > 0 and EF[i+1] - SL2[i+1] + 1 > 0:
    tmp = (EF[0]-SL1[i]+1) + (EF[i+1]-SL2[i+1]+1)
    can.append(tmp)
#print(can)
print(max(can))
Problem p02909 (python)

Fixed submission:
s = input()
if s == 'Sunny':
  print('Cloudy')
elif s == 'Cloudy':
  print('Rainy')
else:
  print('Sunny')

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
raw = []
for i in range(n):
  raw.append(s[i:])
raw.sort()
#print(raw)
if all( raw[i-1][0] != raw[i][0] for i in range(1,n)):
  ans = 0
else:
  ans = 1
  for i in range(1,n):
    one = raw[i-1]
    two = raw[i]
    lone = len(one)
    ltwo = len(two)
    stop = min(lone,ltwo,abs(lone-ltwo))
    if ans > stop:
      pass
    else:
      for i in range(ans,stop):
        if one[i] == two[i]:
          ans += 1
print(ans)
Problem p02921 (python)

Fixed submission:
a = input()
b = input()
ans = 0
for i in range(3):
  if a[i] == b[i]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
#16:07
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
tmp = [0 for _ in range(n)]
now = [i for i in range(n)]
ans = 0
while now:
  ans += 1
  last = now
  now = []
  for x in last:
    tmp[x] = 0
  for x in last:
    try:
      y = raw[x][cnt[x]]
      if tmp[x] == tmp[y] == 0 and x == raw[y][cnt[y]]:
        cnt[x] += 1
        cnt[y] += 1
        tmp[x] = 1
        tmp[y] = 1
        now.append(x)
        now.append(y)
    except:
      pass
  #print(now)
if cnt == [n-1 for _ in range(n)]:
  print(ans-1)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
#dummy
#16:07
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = [i for i in range(n)]
ans = 0
while now:
  ans += 1
  last = now
  now = []
  tmp = [0 for _ in range(n)]
  for x in last:
    if cnt[x] < n-1:
      y = raw[x][cnt[x]]
      if tmp[x] == tmp[y] == 0 and x == raw[y][cnt[y]]:
        cnt[x] += 1
        cnt[y] += 1
        tmp[x] = 1
        tmp[y] = 1
        now.append(x)
        now.append(y)
  #print(now)
  if n > 500 and cnt[0] == 10:
    break
if cnt == [n-1 for _ in range(n)]:
  print(ans-1)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = []
for _ in range(n):
  xy.append(list(map(int,input().split())))
can = []
for i in range(n):
  now = [0,0]
  xp = [0,0]
  xm = [0,0]
  X = - xy[i][1] + 0.00000000000001
  Y = xy[i][0]
  for j in range(n):
    x,y = xy[j]
    if x * X + y * Y > 0:
      now[0] += x
      now[1] += y
    elif x * X + y * Y == 0:
      if x == 0:
        if y > 0:
          xp[0] += x
          xp[1] += y
        else:
          xm[0] += x
          xm[1] += y
      elif x > 0:
        xp[0] += x
        xp[1] += y
      else:
        xm[0] += x
        xm[1] += y
  xp[0] += now[0]
  xp[1] += now[1]
  xm[0] += now[0]
  xm[1] += now[1]
  use = max(xp[0]**2+xp[1]**2,xm[0]**2+xm[1]**2)
  can.append(use)
print(max(can)**.5)
Problem p02926 (python)

Fixed submission:
#解説解法
n = int(input())
xp = []
xm = []
yp = []
ym = []
for _ in range(n):
  x,y = map(int,input().split())
  if x == 0:
    if y == 0:
      n -= 1
    elif y > 0:
      yp.append([0,x,y])
    else:
      ym.append([0,x,y])
  elif x > 0:
    xp.append([y/x,x,y])
  else:
    xm.append([y/x,x,y])
xp.sort()
xm.sort()
xy = xp + yp + xm + ym
can = []
for i in range(-n,0):
  for j in range(i+1,i+n+1):
    X = 0
    Y = 0
    for k in range(i,j):
      x,y = xy[k][1],xy[k][2]
      X += x
      Y += y
    can.append(X**2+Y**2)
if n == 0:
  print(0)
else:
  print(max(can)**.5)

Buggy submission (verdict: Runtime Error):
#解説解法
n = int(input())
xp = []
xm = []
yp = []
ym = []
for _ in range(n):
  x,y = map(int,input().split())
  if x == 0:
    if y == 0:
      n -= 1
    elif y > 0:
      yp.append([0,x,y])
    else:
      ym.append([0,x,y])
  elif x > 0:
    xp.append([y/x,x,y])
  else:
    xm.append([y/x,x,y])
xp.sort()
xm.sort()
xy = xp + yp + xm + ym
can = []
for i in range(-n,0):
  for j in range(i+1,i+n+1):
    X = 0
    Y = 0
    for k in range(i,j):
      x,y = xy[k][1],xy[k][2]
      X += x
      Y += y
    can.append(X**2+Y**2)
print(max(can)**.5)
Problem p02934 (python)

Fixed submission:
n = int(input())
s = list(map(int,input().split()))
t = 0
for i in range(n):
  t += 1 / s[i]
print( 1 / t )

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int,input().split()))
inv = 0
for i in range(n):
  inv += 1 / a[i]
print( 1 / inv )
Problem p02953 (python)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
h.append(0)
flag = 1
for i in range(n):
  if h[i] < h[i-1]:
    flag = 0
    break
  elif h[i] == h[i-1]:
    pass
  else:
    h[i] -= 1
if flag == 1:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))
flag = 1
for i in range(1,n):
  if h[i] < h[i-1]:
    flag = 0
    break
  if h[i] > h[i-1]:
    h[i] -= 1
if flag == 1:
  print('Yes')
else:
  prinr('No')
Problem p02963 (python)

Fixed submission:
s = int(input())
print(0,0,10**9,1,10**9-(s-1)%(10**9)-1,(s-1)//(10**9)+1)

Buggy submission (verdict: Runtime Error):
s = int(input())
print(0,0,10**9,1,s%(10**9),s//(10**9)
Problem p02975 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
s = 0
for i in range(n):
  s ^= a[i]
if s == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
l = [[0,0],[0,0],[0,0]]
flag = 0
for i in range(n):
  x = A[i]
  for j in range(3):
    if l[j] == [0,0]:
      l[j] = [x,1]
      break
    if x == l[j][0]:
      l[j][1] += 1
      break
  else:
    break
a = l[0][1]
b = l[1][1]
c = l[2][1]
aa = l[0][0]
bb = l[1][0]
cc = l[2][0]
if n % 3 == 0:
  m = n // 3
  if a == m:
    if b == m and c == m:
      if aa ^ bb ^ cc == 0:
        flag = 1
  if a == 2 * m and b == m:
    if bb == 0:
      flag = 1
  if a == m and b == 2 * m:
    if aa == 0:
      flag = 1
else:
  if a == n and aa == 0:
    flag = 1
if c == 0:
  if a == m or b == m:
    print('Yes')
else:
  ?

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
l = [[0,0],[0,0],[0,0]]
flag = 0
for i in range(n):
  x = A[i]
  for j in range(3):
    if l[j] == [0,0]:
      l[j] = [x,1]
      break
    if x == l[j][0]:
      l[j][1] += 1
      break
  else:
    break
a = l[0][1]
b = l[1][1]
c = l[2][1]
aa = l[0][0]
bb = l[1][0]
cc = l[2][0]
if n % 3 == 0:
  m = n // 3
  if a == m:
    if b == m and c == m:
      if aa ^ bb ^ cc == 0:
        flag = 1
  if a == 2 * m and b == m:
    if bb == 0:
      flag = 1
  if a == m and b == 2 * m:
    if aa == 0:
      flag = 1
else:
  if a == n and aa == 0:
    flag = 1
if a == m:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
l = [[0,0],[0,0],[0,0]]
flag = 0
for i in range(n):
  x = A[i]
  for j in range(3):
    if l[j] == [0,0]:
      l[j] = [x,1]
      break
    if x == l[j][0]:
      l[j][1] += 1
      break
  else:
    break
a = l[0][1]
b = l[1][1]
c = l[2][1]
aa = l[0][0]
bb = l[1][0]
cc = l[2][0]
if n % 3 == 0:
  m = n // 3
  if a == m:
    if b == m and c == m:
      if aa ^ bb ^ cc == 0:
        flag = 1
  if a == 2 * m and b == m:
    if bb == 0:
      flag = 1
  if a == m and b == 2 * m:
    if aa == 0:
      flag = 1
else:
  if a == n and aa == 0:
    flag = 1
if a == m and b == 2 * m:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
l = [[0,0],[0,0],[0,0]]
flag = 0
for i in range(n):
  x = A[i]
  for j in range(3):
    if l[j] == [0,0]:
      l[j] = [x,1]
      break
    if x == l[j][0]:
      l[j][1] += 1
      break
  else:
    break
a = l[0][1]
b = l[1][1]
c = l[2][1]
aa = l[0][0]
bb = l[1][0]
cc = l[2][0]
if n % 3 == 0:
  m = n // 3
  if a == m:
    if b == m and c == m:
      if aa ^ bb ^ cc == 0:
        flag = 1
  if a == 2 * m and b == m:
    if bb == 0:
      flag = 1
  if a == m and b == 2 * m:
    if aa == 0:
      flag = 1
else:
  if a == n and aa == 0:
    flag = 1
if a == 2 * m:
  print('Yes')
Problem p03006 (python)

Fixed submission:
n = int(input())
xy = []
diff = []
for _ in range(n):
  tmp = list(map(int,input().split()))
  xy.append(tmp)
for i in range(n):
  for j in range(n):
    if j != i:
      tmpd = [ xy[j][0] - xy[i][0] , xy[j][1] - xy[i][1] ]
      flag = 0
      for mxy in diff:
        if mxy[1:] == tmpd:
            flag = 1
            mxy[0] += 1
            break
      if flag == 0:
        diff.append([0]+tmpd)
diff.sort()
diff.reverse()
if n == 1:
  print(1)
else:
  print(n-diff[0][0]-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = []
diff = []
for _ in range(n):
  tmp = list(map(int,input().split()))
  xy.append(tmp)
for i in range(n):
  for j in range(n):
    if j != i:
      tmpd = [ xy[j][0] - xy[i][0] , xy[j][1] - xy[i][1] ]
      flag = 0
      for mxy in diff:
        if mxy[1:] == tmpd:
            flag = 1
            mxy[0] += 1
            break
      if flag == 0:
        diff.append([0]+tmpd)
diff.sort()
diff.reverse()
print(n-diff[0][0]-1)
Problem p03007 (python)

Fixed submission:
#12:17
n = int(input())
a = list(map(int,input().split()))
plus = []
minus = []
for i in range(n):
  if a[i] >= 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
plus.sort()
minus.sort(reverse=True)
lp = len(plus)
lm = len(minus)
if lp >= 1 and lm >= 1:
  ans = sum(plus) - sum(minus)
  print(ans)
  x = minus[0]
  lp = len(plus)
  for i in range(1,lp):
    print(x,plus[i])
    x = x - plus[i]
  minus[0] = x
  x = plus[0]
  for j in range(lm):
    print(x,minus[j])
    x = x - minus[j]
elif lp == 0:
  ans = - sum(minus) + 2 * max(minus)
  print(ans)
  x = minus[1]
  for j in range(2,lm):
    print(x,minus[j])
    x = x - minus[j]
  print(x,minus[0])
elif lm == 0:
  ans = sum(plus) - 2 * min(plus)
  print(ans)
  x = plus[0]
  for i in range(2,lp):
    print(x,plus[i])
    x = x - plus[i]
  print(plus[1],x)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
plus = 0
for i in range(n):
  plus += ( 2 * int( a[i] > 0 ) - 1 )
score = 0
for i in range(n):
  score += abs(a[i])
if plus != n:
  print(score)
  a.sort()
  if plus >=0:
    for k in range(plus):
      print(a[0],a[-1])
      a[0] -= a[-1]
      del a[-1]
    half = ( n - plus ) // 2
    if half != 0:
      for k in range(half-1):
        print(a[k],a[-1])
        a[k] -= a[-1]
        del a[-1]
      for k in range(half):
        print(a[-1],a[0])
        a[-1] -= a[0]
        del a[0]
  else:
    plus *= -1
    for k in range(plus):
      print(a[-1],a[0])
      a[-1] -= a[0]
      del a[0]
    half = ( n - plus ) // 2
    if half != 0:
      for k in range(half-1):
        print(a[k],a[-1])
        a[k] -= a[-1]
        del a[-1]
      for k in range(half):
        print(a[-1],a[0])
        a[-1] -= a[0]
        del a[0]
else:
  unchi