Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=[]
l= 0
r = n
for i in range(m):
    ln,rn=map(int,input().split())
    if ln>l:
        l=ln
    if rn<r:
        r=rn
print(rn-ln+1)

Fixed submission:
n,m=map(int,input().split())

s=[]
l= 0
r = n
for i in range(m):
    ln,rn=map(int,input().split())
    if ln>l:
        l=ln
    if rn<r:
        r=rn
if r-l+1>0:
    print(r-l+1)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(list(map(int,input().split())))
ans=n
for i in range(1,n+1):
    for j in range(m):
        if i<a[j][0] or a[j][1]<i:
            ans=ans-1
            break

print(ans)


Fixed submission:
n,m=map(int,input().split())

s=[]
l= 0
r = n
for i in range(m):
    ln,rn=map(int,input().split())
    if ln>l:
        l=ln
    if rn<r:
        r=rn
if r-l+1>0:
    print(r-l+1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):

N,Y=map(int,input().split())

for i in range(N+1):
    for j in range(N+1-j):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)


Fixed submission:

N,Y=map(int,input().split())

for i in range(N+1):
    for j in range(N+1-i):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open('/Users/murakiyusuke/coding/atcoder/input.txt','r')
sys.stdin = f

S=input()
T=input()

def match(S,T):
    for i in range(len(T)):
        if S[i]==T[i] or S[i]=='?':
            continue
        else:
            return False
    return True

if len(T)>len(S):
    print('UNRESTORABLE')
    exit()

S=S[::-1]
T=T[::-1]   
p=len(S)-len(T)+1
for i in range(p):
    sub = S[i:i+len(T)]
    if match(sub,T):
        S1=S.replace(sub,T,1).replace('?','a')
        print(S1[::-1])
        exit()
print('UNRESTORABLE')
        




Fixed submission:


S=input()
T=input()

def match(S,T):
    for i in range(len(T)):
        if S[i]==T[i] or S[i]=='?':
            continue
        else:
            return False
    return True

if len(T)>len(S):
    print('UNRESTORABLE')
    exit()

S=S[::-1]
T=T[::-1]   
p=len(S)-len(T)+1
for i in range(p):
    sub = S[i:i+len(T)]
    if match(sub,T):
        S1=S.replace(sub,T,1).replace('?','a')
        print(S1[::-1])
        exit()
print('UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
import itertools

N,M=map(int,input().split())
if M==0:
    print(0)
    exit()
S=[list(map(int,input().split()))for _ in range(N) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)

Fixed submission:
import itertools

N,M=map(int,input().split())
S=[list(map(int,input().split()))for _ in range(M) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)

Buggy python submission (verdict: Runtime Error):
import itertools

N,M=map(int,input().split())
S=[list(map(int,input().split()))for _ in range(N) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)

Fixed submission:
import itertools

N,M=map(int,input().split())
S=[list(map(int,input().split()))for _ in range(M) ]

a=[]
for i in range(N):
    a.append(i+1)

L=list(itertools.permutations(a))


cnt=0

for l in L:
    tmp=1
    if l[0]!=1:
        break
    for j in range(N-1):
        if ([l[j],l[j+1]] in S) or ([l[j+1],l[j]] in S):
            tmp=1
        else:
            tmp=0
            break
    if tmp==1:
        cnt+=1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,x=map(int,input().split())
for i in range(a,b+1):
    if i%x==0:
        print((b//x)-math.ceil(a/x)+1)
        exit()

print(0)


Fixed submission:
import math
a,b,x=map(int,input().split())
if a%x>0 and b//x-a//x==0:
    print(0)
else:
    print((b//x)-math.ceil(a/x)+1)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,x=map(int,input().split())
ans=0
for i in range(a,b+1):
    if i%x==0:
        ans+=1
print(ans)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a%x>0 and b//x-a//x==0:
    print(0)
else:
    print((b//x)-math.ceil(a/x)+1)
Buggy python submission (verdict: Runtime Error):
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(int(input())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)


Fixed submission:
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(int(input()))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)


Fixed submission:
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = list(map(int, input().split()))
for i in range(N):
    X[i] -= A

dp = defaultdict(int)
dp[0] = 1

for x in X:
    
    for j, c in list(dp.items()):
        dp[j + x] += c

print(dp[0]-1)


Fixed submission:
from collections import defaultdict

N, A = map(int, input().split())
X = list(map(int, input().split()))
for i in range(N):
    X[i] -= A

dp = defaultdict(int)
dp[0] = 1

for x in X:
    
    for j, c in list(dp.items()):
        dp[j + x] += c

print(dp[0]-1)
Buggy python submission (verdict: Runtime Error):
s = input()
n= len(s)
a=[]

for i in range(n):
    if s[i]!='B':
        a.append(s[i])
    else:
        del a[-1]
print(''.join(a))



Fixed submission:
s = input()
n= len(s)
a=[]

for i in range(n):
    if s[i]!='B':
        a.append(s[i])
    else:
        if a!=[]:
            del a[-1]
print(''.join(a))
Buggy python submission (verdict: Runtime Error):
import math

A B H M = map(int, input().split())

H_arg = H*30 + 0.5*M
M_arg = 6*M

if H_arg - M_arg>=180:
    H_M_arg = (360-H_arg) + M_arg
else:
    H_M_arg = abs(H_arg - M_arg)

X = math.sqrt(A**2+B**2-2*A*B*cos(H_M_arg))
print(X)


Fixed submission:
import math

A, B, H, M = map(int, input().split())

H_arg = H*30 + 0.5*M
M_arg = 6*M

if H_arg - M_arg>=180:
    H_M_arg = (360-H_arg) + M_arg
else:
    H_M_arg = abs(H_arg - M_arg)

# print(H_M_arg)

X = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(H_M_arg)))
print(X)
Buggy python submission (verdict: Runtime Error):
import math
import itertools

N = int(input())
P = input()
Q = input()

p_list = [int(i) for i in P.split(" ")]
q_list = [int(i) for i in Q.split(" ")]

n = []
for i in range(N):
    n.append(i+1)

p_num = 1
q_num = 1
for i in itertools.permutations(n):
    if list(i)==p_list:
        a = p_num
    elif list(i)==q_list:
        b = q_num
    p_num += 1
    q_num += 1

print(abs(a-b))


Fixed submission:
import math
import itertools

N = int(input())
P = input()
Q = input()

p_list = [int(i) for i in P.split(" ")]
q_list = [int(i) for i in Q.split(" ")]

n = []
for i in range(N):
    n.append(i+1)

p_num = 1
q_num = 1
for i in itertools.permutations(n):
    if list(i)==p_list:
        a = p_num
    if list(i)==q_list:
        b = q_num
    p_num += 1
    q_num += 1

print(abs(a-b))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = a*b
 
 
if c % 2==0:
  print("even")
elif c % 2==1:
  print("odd")
  

Fixed submission:
a,b=map(int,input().split())
if (a*b) % 2:
  print("Odd")
else:
  print("Even")

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = a*b


if c % 2==0:
  print("even")
elif c % 2==1:
  print("odd")
  
	

Fixed submission:
a,b=map(int,input().split())
if (a*b) % 2:
  print("Odd")
else:
  print("Even")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())

ans = 0
for x in range(n+1):
    tmp = a*x//b - a*(x//b)
    if tmp > ans:
        ans = tmp

print(ans)


Fixed submission:
a, b, n = map(int, input().split())

x = n
if n >= b-1:
    x = b-1

ans = (a*(x%b))//b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, n = map(int, input().split())

ans = 0
for x in range(n+1):
    tmp = a*x//b - a*(x//b)
    if tmp > ans:
        ans = tmp

print(ans)


Fixed submission:
a, b, n = map(int, input().split())

x = n
if n >= b-1:
    x = b-1

ans = (a*(x%b))//b
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]
l = [list(x) for x in zip(*l)]

flag = True
ans = [-1] * n
for i in range(m):
    if ans[l[0][i]-1] == -1:
        ans[l[0][i]-1] = l[1][i]
    elif ans[l[0][i]-1] != l[1][i]:
        flag = False

if n != 1:
    if ans[0] == 0:
        flag = False

if flag:
    ans[0] = max(0, ans[0])
    ans[1] = max(0, ans[1])
    ans[2] = max(0, ans[2])
    ans = str(ans[0]) + str(ans[1]) + str(ans[2])

print(ans) if flag else print(-1)


Fixed submission:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(m)]

l = [list(x) for x in zip(*l)]

flag = True
num = [-1] * n
for i in range(m):
    if num[l[0][i]-1] == -1:
        num[l[0][i]-1] = l[1][i]
    elif num[l[0][i]-1] != l[1][i]:
        flag = False

if n != 1:
    if num[0] == 0:
        flag = False
    elif num[0] == -1:
        num[0] = 1

ans = ""
if flag:
    for i in range(n):
        ans += str(max(0, num[i]))

print(ans) if flag else print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

ans = 1
for i in range(1, n):
    if p[i] <= min(p[:i]):
        ans += 1

print(ans)


Fixed submission:
n = int(input())
p = list(map(int, input().split()))

ans = 1
min = p[0]
for i in range(1, n):
    if min > p[i]:
        min = p[i]
    if p[i] <= min:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

ans = 1
for i in range(1, n):
    flag = True
    for j in range(i):
        if p[i] > p[j]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)


Fixed submission:
n = int(input())
p = list(map(int, input().split()))

ans = 1
min = p[0]
for i in range(1, n):
    if min > p[i]:
        min = p[i]
    if p[i] <= min:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print((a * b) // math.gcd(a, b))


Fixed submission:
import math
a, b = map(int, input().split())

i = 1
flag = True
while(flag):
    if (a * i) % b == 0:
        flag = False
        ans = a * i
        break
    i += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
from scipy.spatial import distance

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

n_fct = math.factorial(n)
d = [0] * n_fct
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d[j] += distance.euclidean((i[j][0], i[j][1]), (i[j+1][0], i[j+1][1]))
        else:
            d[j] += distance.euclidean((i[j][0], i[j][1]), (i[0][0], i[0][1]))

print(sum(d)/len(d))


Fixed submission:
import math
import itertools
from scipy.spatial import distance

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

d = 0
for i in itertools.permutations(l):
    for j in range(n-1):
        if j+1 < n:
            d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)

print(d/math.factorial(n))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

l.sort()
ans = 0
for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        c_candidate = [k for k in l[j+1:] if k < a+b]
        ans += len(c_candidate)

print(ans)


Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))

l.sort()
ans = 0
for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        ans += bisect.bisect_left(l, a+b)-j-1

print(ans)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = [int(i) for i in input().split()]

i = 0
while True:
    if x - l[i] < 0:
        break
    x -= l[i]
    i += 1

print(i+1)


Fixed submission:
n, x = map(int, input().split())
l = [int(i) for i in input().split()]

i = 0
for i in range(n):
    if x - l[i] < 0:
        break
    x -= l[i]
    i += 1

print(i+1)
Buggy python submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())

pattern = 1
if w/2 == x and h/2 == y:
    pettern = 1
elif w/2 == x or h/2 == y:
    pettern = 0

print("{} {}".format(w*h/2, pettern))


Fixed submission:
w, h, x, y = map(int, input().split())

pattern = 0
if w/2 == x and h/2 == y:
    pattern = 1

print("{} {}".format(w*h/2, pattern))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
gate = []
for i in range(m):
    li, ri = map(int, input().split())
    gate.append([li, ri])

l_inside = list(range(1, n+1))
for i in range(m):
    l_inside = [j for j in l_inside if gate[i][0] <= j and j <= gate[i][1]]

print(len(l_inside))


Fixed submission:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())

l_max = 1
r_min = n
for i in range(m):
    li, ri = map(int, input().split())
    if l_max < li:
        l_max = li
    if r_min > ri:
        r_min = ri

print(r_min-l_max+1 if r_min-l_max >= 0 else 0)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
a, b = map(int, raw_input().split())
if a % 2 and b % 2:
	print "Odd"
else:
	print "Even"

Fixed submission:
a, b = map(int, input().split())
if (a*b)%2 == 1:
    print("Odd")
else:
    print("Even")
Buggy python submission (verdict: Runtime Error):
s = input()
print("yes" if len(s) = len(set(s))) else "not")

Fixed submission:
import collections
s = input()
alph = "abcdefghijklmnopqrstuvwxyz"
col = dict(collections.Counter(s))

flag = True
for i in range(26):
    if col.get(alph[i], 0) > 1:
        print("no")
        flag = False
        break
if flag:
    print("yes")
Buggy python submission (verdict: Runtime Error):
k, x = [int(x) for x in input().split()]
rl = max(-1000000, x - k + 1)
rr = min(+1000000, x + k - 1)
print(" ".join(range(rl, rr + 1)))

Fixed submission:
k, x = [int(x) for x in input().split()]
rl = max(-1000000, x - k + 1)
rr = min(+1000000, x + k - 1)
print(*(range(rl, rr + 1)))
Buggy python submission (verdict: Runtime Error):
input()
p = [int(x) for x in input()]
q = sorted(p)
d = [(pi, qi) for pi, qi in zip(p, q) if pi != qi]
print("YES" if len(d) == 0 or len(d) == 2 and d[0][0] == d[1][1] and d[1][0] == d[0][1] else "NO")

Fixed submission:
input()
p = [int(x) for x in input().split()]
q = sorted(p)
d = [(pi, qi) for pi, qi in zip(p, q) if pi != qi]
print("YES" if len(d) == 0 or len(d) == 2 and d[0][0] == d[1][1] and d[1][0] == d[0][1] else "NO")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]

ans = [
    sum(a[(i + j) % n] * (-1) ** (j % 2)
        for j in range(n))
    for i in range(n)
]

print(" ".join(str(x) for x in ans))


Fixed submission:
#!/usr/bin/env python3
n = int(input())
a = [int(x) for x in input().split()]

v = sum(a[i] * (-1) ** (i % 2) for i in range(n))

ans = [0] * n

for i in range(n):
    ans[i] = v
    v = -v + 2 * a[i]

print(" ".join(str(x) for x in ans))
Buggy python submission (verdict: Runtime Error):
n, x = [int(x) for x in input().split()]
k = 0
ans = 1
for li in input().split():
    k += li
    ans += k <= x

print(ans)

Fixed submission:
n, x = [int(x) for x in input().split()]
k = 0
ans = 1
for li in input().split():
    k += int(li)
    ans += k <= x

print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
n = int(input())
res = [(i, *input().split()) for i in range(n)]

res.sort(key=lambda x: (x[1], -int(x[2])))

for r in res:
    print(r[0] + 1)


Fixed submission:
#!/usr/bin/env python3
n = int(input())
res = [[i] + input().split() for i in range(n)]

res.sort(key=lambda x: (x[1], -int(x[2])))

for r in res:
    print(r[0] + 1)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import defaultdict
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    d = defaultdict(int)
    for Bi, Ci in zip(B, C):
        d[Ci] += Bi

    k = [0] * 0
    for key in sorted(d.keys(), reverse=True):
        k += [key] * d[key]
        if len(k) > N:
            break
    print(sum(sorted(A + k, reverse=True)[:N]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import defaultdict
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    d = defaultdict(int)
    for Bi, Ci in zip(B, C):
        d[Ci] += Bi

    k = [0] * N
    i = 0
    for key in sorted(d.keys(), reverse=True):
        newi = min(N, i + d[key])
        for j in range(i, newi):
            k[j] = key
        i = newi
        if newi > N:
            break
    print(sum(sorted(A + k, reverse=True)[:N]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    par = list(range(N))

    def getpar(n: int):
        if par[n] == n:
            return n
        par[n] = getpar(par[n])
        return par[n]

    def union(a: int, b: int):
        par[getpar(b)] = par[getpar(a)]

    for Xi, Yi in zip(X, Y):
        Xi -= 1
        Yi -= 1
        union(Xi, Yi)

    print(len({getpar(i) for i in range(N)}))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    Z = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


sys.setrecursionlimit(1000000)


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    par = list(range(N))

    def getpar(n: int):
        if par[n] == n:
            return n
        par[n] = getpar(par[n])
        return par[n]

    def union(a: int, b: int):
        par[getpar(b)] = getpar(a)

    for Xi, Yi in zip(X, Y):
        Xi -= 1
        Yi -= 1
        union(Xi, Yi)

    print(len({getpar(i) for i in range(N)}))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    Z = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

n = int(input())
a = [int(x) for x in input().split()]

m = 1
l = 0
while m < n:
    m *= 2
    l += 1
tr = [0] * (2 * m)

tr[m:m + n] = a


def gcd(a, b):
    if not a:
        return b
    while b:
        r = a % b
        a, b = b, r
    return a


def init_tr():
    for d in range(l - 1, -1, -1):
        for i in range(1 << d, 1 << (d + 1)):
            tr[i] = gcd(tr[i * 2], tr[i * 2 + 1])


def upd_tr(j):
    i = j // 2
    if i == 0:
        return
    tr[i] = gcd(tr[i * 2], tr[i * 2 + 1])
    upd_tr(i)


init_tr()

ans = 0

for i in range(n):
    tmp = tr[m + i]
    tr[m + i] = 0
    upd_tr(m + i)
    ans = max(ans, tr[1])
    tr[m + i] = tmp
    upd_tr(m + i)

print(ans)


Fixed submission:
#!/usr/bin/env python3

n = int(input())
a = [int(x) for x in input().split()]

m = 1
l = 0
while m < n:
    m *= 2
    l += 1
tr = [0] * (2 * m)

tr[m:m + n] = a


def gcd(a, b):
    if not a:
        return b
    while b:
        r = a % b
        a, b = b, r
    return a


def init_tr():
    for d in range(l - 1, -1, -1):
        for i in range(1 << d, 1 << (d + 1)):
            tr[i] = gcd(tr[i * 2], tr[i * 2 + 1])


def upd_tr(j):
    i = j // 2
    if i == 0:
        return
    tr[i] = gcd(tr[i * 2], tr[i * 2 + 1])
    upd_tr(i)


init_tr()

ans = 0

for i in range(n):
    tmp = tr[m + i]
    tr[m + i] = 0
    upd_tr(m + i)
    ans = max(ans, tr[1])
    tr[m + i] = tmp
    upd_tr(m + i)

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = [int(x) for x in input()]
print(max(a + a - 1, a + b, b + b - 1))

Fixed submission:
a, b = [int(x) for x in input().split()]
print(max(a + a - 1, a + b, b + b - 1))