Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
Red = sorted([tuple(map(int, input().split())) for _ in range(N)])
Blue = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 0
switch = lambda X:(X[1],X[0])
for b in Blue:
    C = [switch(r) for r in Red if r < b] #候補
    if len(C) == 0:
        continue
    ans += 1
    C.sorted(reverse=True)
    Red.remove(switch(C[0]))
print(ans)

Fixed submission:
N = int(input())
Red = sorted([tuple(map(int, input().split())) for _ in range(N)])
Blue = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 0
for bx,by in Blue:
    C = [(y,x) for x,y in Red if x<bx and y<by] #候補
    if len(C) == 0:
        continue
    ans += 1
    C.sort(reverse=True)
    Red.remove((C[0][1],C[0][0]))
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Red = sorted([tuple(map(int, input().split())) for _ in range(N)])
Blue = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 0
for b in Blue:
    C = [r for r in Red if r < b] #候補
    if len(C) == 0:
        continue
    ans += 1
    pair = (0,0)
    for c in C:
        if c[1] > pair[1]:
            pair = c
    Red.remove(pair)
print(ans)

Fixed submission:
N = int(input())
Red = sorted([tuple(map(int, input().split())) for _ in range(N)])
Blue = sorted([tuple(map(int, input().split())) for _ in range(N)])

ans = 0
for bx,by in Blue:
    C = [(y,x) for x,y in Red if x<bx and y<by] #候補
    if len(C) == 0:
        continue
    ans += 1
    C.sort(reverse=True)
    Red.remove((C[0][1],C[0][0]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = {} #10000以上key以下の回文数の個数
cnt = 0
for i in range(10000, 100000):
    L = list(str(i))
    if L == list(reversed(L)):
        cnt += 1
    N[i] = cnt
A, B = map(int, input().split())
print(N[B]-N[A-1])

Fixed submission:
N = {} #10000以上key以下の回文数の個数
cnt = 0
for i in range(10000, 100000):
    L = list(str(i))
    if L == list(reversed(L)):
        cnt += 1
    N[i] = cnt
A, B = map(int, input().split())
print(N[B]-N[A-1] if A > 10000 else N[B])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
LRD = [tuple(int(x) for x in input().split()) for _ in range(M)]

import numpy as np
Graph = np.full((N,N), np.inf)
for l,r,d in LRD:
    Graph[r-1,l-1] = d
    Graph[l-1,r-1] = -d
import scipy.sparse.csgraph as csg
try:
    Graph = csg.johnson(Graph)
    for l,r,d in LRD:
        if Graph[r-1,l-1] != d or Graph[l-1,r-1] != -d:
            ans = 'No'
            break
    else:
        ans = 'Yes'
except csg.NegativeCycleError:
    ans = 'No'
print(ans)

Fixed submission:
N, M = map(int, input().split())
LRD = [tuple(int(x) for x in input().split()) for _ in range(M)]
Graph = [[] for _ in range(N)]
for l,r,d in LRD:
    Graph[r-1].append((l-1,d))
    Graph[l-1].append((r-1,-d))

seen = set()
Dfr = [0] * N #dist from Root
for root in range(N):
    if root in seen: continue
    seen.add(root)
    V = [root]
    while len(V) != 0: #bfs
        v = V.pop(0)
        for nv,d in Graph[v]:
            if nv in seen and Dfr[nv] != Dfr[v] + d: #bfsで発見済みの値が異なる⇔矛盾
                print('No')
                exit()
            if nv in seen: continue
            else:
                seen.add(nv)
                Dfr[nv] = Dfr[v] + d
                V.append(nv)
print('Yes')
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left as bsl

def main():
    with open(0) as f:
        N, H = map(int, f.readline().split())
        ab = list(map(int, f.read().split()))
    max_slash = max(ab[0::2])
    throw = [x for x in ab[1::2] if x > max_slash]
    throw.sort(reverse=True)
    throw = [sum(throw[0:i]) for i in range(1,len(throw)+1)]
    index = bsl(throw, H)
    l = len(throw)
    if index < l:
        print(index + 1)
    else:
        H += -throw[l-1]
        print(l + (H+max_slash-1)//max_slash)

main()

    

Fixed submission:
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    
#slash=斬撃最大ダメージ、投げてslash超のダメージが出るならばその剣をダメージが大きい順に投げる
import heapq as hq
Throw = [-th for th in Throw if th > slash]
hq.heapify(Throw)

dmg, cnt = 0, 0
while len(Throw) != 0:
    if dmg >= H: break
    dmg += -hq.heappop(Throw)
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Buggy python submission (verdict: Runtime Error):
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    
#slash=斬撃最大ダメージ、投げてslash超のダメージが出るならばその刀をダメージが大きい順に投げる
Throw = sorted([th for th in Throw if th > slash], reversed=True)
dmg, cnt = 0, 0
for throw in Throw:
    if dmg >= H: break
    dmg += throw
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Fixed submission:
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    
#slash=斬撃最大ダメージ、投げてslash超のダメージが出るならばその剣をダメージが大きい順に投げる
import heapq as hq
Throw = [-th for th in Throw if th > slash]
hq.heapify(Throw)

dmg, cnt = 0, 0
while len(Throw) != 0:
    if dmg >= H: break
    dmg += -hq.heappop(Throw)
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left as bsl

def main():
    with open(0) as f:
        Q = int(f.readline())
        Query = [tuple(map(int, line.split())) for line in f.readlines()]
    
    p_table = makePtable(10**5)
    p_set = set(p_table)
    Like2017 = [p for p in p_table if (p+1)//2 in p_set]
    database = [bsl(Like2017, i) for i in range(1,10**5+1)]

    for l,r in Query:
        print(database[r] - database[l-1])

def makePtable(N):
    table = list(range(2,N+1))
    result = []
    while len(table) != 0:
        p = table[0]
        result.append(p)
        table = [x for x in table[1:] if x % p != 0]
    return result

main()

Fixed submission:
#クエリにO(1)で返すためのテーブルを用意
import numpy as np
MAX = int(10e5+1)
List = list(range(2,MAX))
P = []
while len(List) > 0:
    p = List[0]
    if p >= np.sqrt(MAX): break
    P.append(p)
    List = [x for x in List if x % p != 0]
P = set(P+List)

Ans = [0] * MAX
cnt = 0
for i in range(1,MAX):
    if i in P and (i+1)//2 in P:
        cnt += 1
    Ans[i] = cnt

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(Ans[r]-Ans[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def isP(x):
    for i in range(2,int(np.sqrt(x))+1):
        if x % i == 0:
            return False
    return True

#クエリにO(1)で返すためのテーブルを用意
MAX = int(10e5+1)
P = [isP(x) for x in range(MAX)]
Ans = [0] * MAX
cnt = 0
for i in range(1,MAX):
    if P[i] and P[(i+1)//2]:
        cnt += 1
    Ans[i] = cnt

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(Ans[r]-Ans[l-1])

Fixed submission:
#クエリにO(1)で返すためのテーブルを用意
import numpy as np
MAX = int(10e5+1)
List = list(range(2,MAX))
P = []
while len(List) > 0:
    p = List[0]
    if p >= np.sqrt(MAX): break
    P.append(p)
    List = [x for x in List if x % p != 0]
P = set(P+List)

Ans = [0] * MAX
cnt = 0
for i in range(1,MAX):
    if i in P and (i+1)//2 in P:
        cnt += 1
    Ans[i] = cnt

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(Ans[r]-Ans[l-1])
Buggy python submission (verdict: Runtime Error):
def main():
    S = input() + '.'
    count = 0
    data = []
    for i, s in enumerate(S[1:]):
        count += 1
        if s != S[i]:
            data.append(count)
            count = 0
    data.append(0)
    ans = max([min(data[i-1]+data[i], data[i]+data[i+1]) for i in range(1,len(data)-1)])
    print(ans)

main()

Fixed submission:
S = list(input())
lenS = len(S)
S = S + ['.']
K = lenS
i = 0
ps = S[0]
for s in S:
    if s != ps:
        K = min(K, max(i, lenS-i))
        ps = s
    i += 1
print(K)

Buggy python submission (verdict: Runtime Error):
S = list(input())
lenS = len(S)
front = S.index('0' if S[0] == '1' else '1')
S.reverse()
end = S.index('0' if S[0] == '1' else '1')
ans = lenS - min(front, end)
print(ans)

Fixed submission:
S = list(input())
lenS = len(S)
S = S + ['.']
K = lenS
i = 0
ps = S[0]
for s in S:
    if s != ps:
        K = min(K, max(i, lenS-i))
        ps = s
    i += 1
print(K)
Buggy python submission (verdict: Runtime Error):
S = sorted(x for x in input())
T = sorted([x for x in input()], reverse=True)
for s,t in zip(S,T):
    if s < t:
        ans = 'Yes'
        break
    if s > t:
        ans = 'No'
print(ans)

Fixed submission:
s = sorted(x for x in input())
t = sorted([x for x in input()], reverse=True)
print('Yes' if s < t else 'No')
Buggy python submission (verdict: Runtime Error):
N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X.x)
for a in set(A):
    cnt = f(A,a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt-a
print(ans)

Fixed submission:
N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X,x)
for a in set(A):
    cnt = f(A,a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt-a
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = s.count(1)
print(ans)

Fixed submission:
s = input()
ans = s.count('1')
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
cnt = [A.count(a) for a in set(A)]
cnt.sort()
vrt = len(cnt)
print(sum(cnt[:vrt-K]) if vrt > K else 0)

Fixed submission:
import bisect as bs
N, K = (int(x) for x in input().split())
A = sorted([int(x) for x in input().split()])
f = lambda X, x: bs.bisect_right(X,x)-bs.bisect_left(X,x)
cnt = sorted([f(A,a) for a in set(A)],reverse=True)
vrt = len(cnt)
print(sum(cnt[K:]) if vrt > K else 0)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [] * (N+1)
L[0] = 2
L[1] = 1
for i in range(2,N+1):
    L[i] = L[i-1] + L[i-2]
print(L[N])


Fixed submission:
N = int(input())
L = [0] * (N+1)
L[0] = 2
L[1] = 1
for i in range(2,N+1):
    L[i] = L[i-1] + L[i-2]
print(L[N])
Buggy python submission (verdict: Runtime Error):
ABCD = input().strip()
for i in range(8):
    ope = [{0:'+', 1:'-'}[i & (1<<j)] for j in range(3)]
    fomula = ABCD[0] + ope[0] + ABCD[1] + ope[1] + ABCD[2] + ope[2] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Fixed submission:
List = [int(n) for n in input()]
ans = [List[0]] * 4
for i in range(8):
    for j in range(3):
        if i & (1<<j):
            ans[j+1]= -List[j+1]
        else:
            ans[j+1] = List[j+1]
    if sum(ans) == 7:
        break
ans = [str(ans[0])] + ['+' + str(x) if x>=0 else str(x) for x in ans[1:]]
print("".join(ans) + '=7')

Buggy python submission (verdict: Runtime Error):
ABCD = input()
for i in range(8):
    ope = [{0:'+', 1:'-'}[i & (1<<j)] for j in range(3)]
    fomula = ABCD[0] + ope[0] + ABCD[1] + ope[1] + ABCD[2] + ope[2] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Fixed submission:
List = [int(n) for n in input()]
ans = [List[0]] * 4
for i in range(8):
    for j in range(3):
        if i & (1<<j):
            ans[j+1]= -List[j+1]
        else:
            ans[j+1] = List[j+1]
    if sum(ans) == 7:
        break
ans = [str(ans[0])] + ['+' + str(x) if x>=0 else str(x) for x in ans[1:]]
print("".join(ans) + '=7')

Buggy python submission (verdict: Runtime Error):
ope = {0:'+', 1:'-'}
ABCD = input()
for i in range(8):
    i = [i & (1<<j) for j in range(3)]
    fomula = ABCD[0] + ope[i[0]] + ABCD[1] + ope[i[1]] + ABCD[2] + ope[i[2]] + ABCD[3]
    if eval(fomula) == 7:
        print(f'{fomula}=7')
        break

Fixed submission:
List = [int(n) for n in input()]
ans = [List[0]] * 4
for i in range(8):
    for j in range(3):
        if i & (1<<j):
            ans[j+1]= -List[j+1]
        else:
            ans[j+1] = List[j+1]
    if sum(ans) == 7:
        break
ans = [str(ans[0])] + ['+' + str(x) if x>=0 else str(x) for x in ans[1:]]
print("".join(ans) + '=7')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0
A.sort()
B.sort()
#A_b:a以上のBのパーツ数。ソートしているのでそのままBのindexと対応が付く
A_b = [sum(b > a for b in B) for a in A] 
B_c = [sum(c > b for c in C) for b in B]

ans = sum(sum(B_c[N-x:]) for x in A_b) 
#aはB[i](i>N-x)の上に乗せられる。
#B[i]を乗せられるCのパーツ数はリストB_cにまとめてある。
print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

import bisect as bs
import numpy as np
A.sort()
C.sort()
#B_a:b未満のAのパーツ数、B_c:b超のCのパーツ数
B_a = np.array([bs.bisect_left(A,b) for b in B]) 
B_c = np.array([N-bs.bisect_right(C,b) for b in B])
ans = np.dot(B_a, B_c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0
Sum = 0
A.sort(reverse=True)
B.sort(reverse=True)
#A_b:a以上のBのパーツ数。ソートしているのでそのままBのindexと対応が付く
A_b = [sum(b > a for b in B) for a in A] 
B_c = [sum(c > b for c in C) for b in B]

ans = sum(sum(B_c[:x]) for x in A_b) 
#aはB[i](i<x)の上に乗せられる。
#B[i]を乗せられるCのパーツ数はリストB_cにまとめてある。
print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

import bisect as bs
import numpy as np
A.sort()
C.sort()
#B_a:b未満のAのパーツ数、B_c:b超のCのパーツ数
B_a = np.array([bs.bisect_left(A,b) for b in B]) 
B_c = np.array([N-bs.bisect_right(C,b) for b in B])
ans = np.dot(B_a, B_c)
print(ans)
Buggy python submission (verdict: Runtime Error):
R, G = (int(x) for x in input().split())
ans = 2*G - R
print(ans)

Fixed submission:
R = int(input())
G = int(input())
ans = 2*G - R
print(ans)
Buggy python submission (verdict: Runtime Error):
N, A = (int(x) for x in input().split())
ans = N**2 - A
print(ans)

Fixed submission:
N = int(input())
A = int(input())
ans = N**2 - A
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C,D,E,F = (int(x) for x in input().split())

CCT = {}
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        water = (a*A+b*B)*100
        max_suger = water*E//100
        for c in range(max_suger//C+1):
            for d in range(max_suger//D+1):
                suger = c*C+d*D
                if water + suger > F:
                    continue
                if max_suger < suger:
                    continue
                if water+suger == 0:
                    continue
                CCT[water,suger] = 100*suger/(water+suger)

max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = [water+suger, suger]
print(*ans)


Fixed submission:
A,B,C,D,E,F = (int(x) for x in input().split())

CCT = {}
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        water = (a*A+b*B)*100
        if water > F:
            continue
        max_suger = water*E//100
        for c in range(max_suger//C+1):
            for d in range(max_suger//D+1):
                suger = c*C+d*D
                total = water + suger
                if total > F or total == 0:
                    continue
                if max_suger < suger:
                    continue
                CCT[water,suger] = suger/total

ans = (A*100, 0)
max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = (water+suger, suger)
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = (int(x) for x in input().split())
R = [int(x)-1 for x in input().split()]
graph = [[] for _ in range(N)]
cost = {}
for _ in range(M):
    a, b, c = (int(x) for x in input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    cost[min(a-1,b-1), max(b-1,a-1)] = c 
del a, b, c, K

dist = [[10e8 for _ in range(N)] for _ in range(N)]
for i in range(N): dist[i][i] = 0

def dfs(v, r, passed):
    global graph, dist
    passed.add(v)
    for nv in graph[v]:
        dist[r][nv] = dist[nv][r] =  min(dist[r][nv], dist[r][v] + cost[min(v,nv),max(v,nv)])
        if not nv in passed:
            dfs(nv, r, passed)
    passed.remove(v)
    return 0

def mindist(x, X):
    global dist
    Y = X.copy()
    Y.remove(x)
    if len(Y) == 0: return 0
    return min([dist[x][y] + mindist(y,Y) for y in Y])

passed = set()
for r in R:
    dfs(r, r, passed)
ans = min([mindist(r, R) for r in R])
print(ans)

Fixed submission:
N, M, K = (int(x) for x in input().split())
R = [int(x)-1 for x in input().split()]

dist = [[10e8 for _ in range(N)] for _ in range(N)]
for i in range(N): dist[i][i] = 0
for _ in range(M):
    a, b, c = (int(x) for x in input().split())
    dist[a-1][b-1] = dist[b-1][a-1] = c 
del a, b, c, K

for k in range(N):
    for i in range(N):
        for j in range(i,N):
            dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j])

def mindist(x, X):
    global dist
    Y = X.copy()
    Y.remove(x)
    if len(Y) == 0: return 0
    return min([dist[x][y] + mindist(y,Y) for y in Y])

ans = min([mindist(r, R) for r in R])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

pair = []
unpair = []
for a in A:
    if a in unpair:
        pair.append(a)
        unpair.remove(a)
    else:
        unpair.append(a)

pair.sort()
pair.reverse()
if len(pair) <= 1:
    ans = 0
else:
    ans = pair[0] * pair[1]
print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

pair = []
unpair = set()
for a in A:
    if a in unpair:
        pair.append(a)
        unpair.remove(a)
    else:
        unpair.add(a)

pair.sort()
pair.reverse()
if len(pair) <= 1:
    ans = 0
else:
    ans = pair[0] * pair[1]
print(ans)
Buggy python submission (verdict: Runtime Error):
N =int(input())
#graph作成
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    graph[a-1].append((b-1,c))
    graph[b-1].append((a-1,c))
Q, K = map(int, input().split())
K -= 1
query = [tuple(int(x) for x in input().split()) for _ in range(Q)]


def dfs(v, graph, seen, dist, distfromK):
    for next_v in graph[v]:
        if next_v[0] in seen:
            continue
        seen.append(next_v[0])
        ndist = dist + next_v[1]
        distfromK[next_v[0]] = ndist
        dfs(next_v[0], graph, seen, ndist, distfromK)


#dfs
seen = [K]
distfromK =[0] * N
dfs(K, graph, seen, 0, distfromK)

for q in query:
    print(distfromK[q[0]-1]+distfromK[q[1]-1])





Fixed submission:
N =int(input())
#graph作成
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    graph[a-1].append((b-1,c))
    graph[b-1].append((a-1,c))

Q, K = map(int, input().split())
K -= 1
query = [tuple(int(x) for x in input().split()) for _ in range(Q)]

        
seen = {K} 
v = [K]
distfromK =[0] * N
while len(v) != 0:  #bfsでdistfromKを埋めていく
    for nv in graph[v[0]]:
        if nv[0] in seen:
            continue
        distfromK[nv[0]] = distfromK[v[0]] + nv[1]
        v.append(nv[0])
        seen.add(nv[0])
    v.pop(0)

for q in query:
    print(distfromK[q[0]-1]+distfromK[q[1]-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(x) for x in input().split()]
ans = 10**9*N
for i in range(1,N):
    front = a[:i]
    back = a[i:]
    ans = min(ans, abs(sum(front)-sum(back)))
print(ans)

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]
ans = 10**9*N
front = 0
back = sum(a)
for i in range(N-1):
    front += a[i]
    back -= a[i]
    ans = min(ans, abs(front-back))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
with open(0) as f:
    N, *xy = map(int, f.read().split())
from collections import namedtuple
v = namedtuple('v',['x','y'])
V = [v(x-1,y-1) for x,y in zip(xy[::2],xy[1::2])] #頂点
cost = lambda i,j:min(abs(V[i].x-V[j].x), abs(V[i].y-V[j].y))
from itertools import combinations 
Edge = sorted([(cost(i,j), i, j) for i,j in combinations(range(N),2)])
root = namedtuple('root',['num', 'rank']) #(num_of_root, rank_of_root)
Root = [root(i,0) for i in range(N)] 

def fr(i): #findRoot
    if i == Root[i].num:
        return Root[i]
    Root[i] = fr(Root[i].num)
    return Root[i]


def unionT(i, j): #unionTree
    p, q = fr(i), fr(j)
    if p.rank < q.rank:
        Root[p.num] = q
    elif p.rank > q.rank:
        Root[q.num] = p
    elif p.rank == q.rank:
        r, s = min(p, q), max(p, q)
        Root[r.num] = Root[s.num] = root(r.num, r.rank+1)
    

ans = 0
#最小全域木の大きさ算出(環状にならないように辺を小さい順に足してゆく)
for w, i, j in Edge:
    p, q = fr(i), fr(j)
    if p.num == q.num: #既に連結済み
        continue
    else:
        unionT(i,j)
        ans += w
print(ans)

Fixed submission:
with open(0) as f:
    N, *xy = map(int, f.read().split())

from collections import namedtuple
v = namedtuple('v',['coordinate','num'])
#最小全域木に使われる辺は高々座標(xまたはy)が隣接する頂点間のものである
#したがって、x座標・y座標それぞれでソートして辺を求める
X = sorted([v(x,i) for x,i in zip(xy[::2], range(N))])
Y = sorted([v(y,i) for y,i in zip(xy[1::2], range(N))])

diffiter = lambda X:zip(X[:len(X)-1], X[1:]) #Xの1階階差差分のイテレータを返す関数
cost = lambda u,v:abs(u.coordinate - v.coordinate)
from itertools import chain
Edge = sorted([(cost(u,v), u.num, v.num) for u,v in chain(diffiter(X),diffiter(Y))])

root = namedtuple('root',['num', 'rank']) #(num_of_root, rank_of_root)
Root = [root(i,0) for i in range(N)]

def fr(i): #findRoot
    if i == Root[i].num:
        return Root[i]
    Root[i] = fr(Root[i].num)
    return Root[i]


def unionT(i, j): #unionTree
    p, q = fr(i), fr(j)
    if p.rank < q.rank:
        Root[p.num] = q
    elif p.rank > q.rank:
        Root[q.num] = p
    elif p.rank == q.rank:
        r, s = min(p, q), max(p, q)
        Root[r.num] = Root[s.num] = root(r.num, r.rank+1)
    

ans = 0
#最小全域木の大きさ算出(環状にならないように辺を小さい順に足してゆく)
for w, i, j in Edge:
    if fr(i).num == fr(j).num: #既に連結済み
        continue
    else:
        unionT(i,j)
        ans += w
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A + b >= 10:
    print("error")
else:
    print(A+B)

Fixed submission:
A, B = map(int, input().split())
print(A+B if A+B < 10 else 'error')
Buggy python submission (verdict: Runtime Error):
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N + 1

dp = [False * M]
dp[0] = True

for x in s:
    for i in range(M):
        if i < x: continue
        if dp[i-x]: dp[i] = True

for i in range(M):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
else:
    print(0) 

Fixed submission:
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N

dp = [False] * (M+1)
dp[0] = True

for x in s:
    for i in range(M+1):
        if M-i < x: continue
        if dp[M-i-x]: dp[M-i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
        break
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N + 1

dp = [False * M]
dp[0] = True

for x in s:
    for i in range(M+1):
        if i < x: continue
        if dp[i-x]: dp[i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
else:
    print(0) 

Fixed submission:
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N

dp = [False] * (M+1)
dp[0] = True

for x in s:
    for i in range(M+1):
        if M-i < x: continue
        if dp[M-i-x]: dp[M-i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
        break
else:
    print(0)