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

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

print(min(n*a, b))

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
 
v = []

if l == 0:
    print(0)
if l*r < 2019:
    print(l*r)
else:
    for a, i in enumerate(range(l, r+1)):
        for j in range(i+1, r+1):
            if i*j%2019 in v:
                break
            else:
                v.append(i*j%2019)
        else:
            continue
        break

    print(min(v))

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
 
v = []
 
if l*r < 2019:
    print(l*r)
else:
    flag = True
    for a, i in enumerate(range(l, r+1)):
        for j in range(l+a+1, r+1):
            if i*j%2019 in v:
                break
            else:
                v.append(i*j%2019)
        else:
            continue
        break

    print(min(v))

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
 
v = []
 
if l*r < 2019:
    print(l*r)
else:
    for a, i in enumerate(range(l, r+1)):
        for j in range(l+a+1, r+1):
            if i*j%2019 in v:
                print(min(v))
                exit()
            else:
                v.append(i*j%2019)
                
    print(min(v))
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())
 
v = []
if l*r < 2019:
    print(l*r)
else:
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            v.append(i*j%2019)
            if v[-1] == 0:
                break
        else:
            continue
        break
 
    print(min(v))

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
 
v = []

if l*r < 2019:
    print(l*r)
else:
    c = r - l
    for i in range(l, l + c):
        for j in range(i+1, l + c):
            v.append(i*j%2019)
            if v[-1] == 0:
                break
        else:
            continue
        break

    print(min(v))
Problem p03273 (python)

Fixed submission:
H,W = map(int,input().split())
h = [0]*H
w = [0]*W
l = [list(input()) for i in range(H)]
for i in range(H):
    if all([i=='.' for i in l[i][:]]):
        h[i]=1
lt = list(zip(*l))
for j in range(W):
    if all([j=='.' for j in lt[j][:]]):
        w[j]=1
for i in range(H):
    for j in range(W):
        if h[i]==0 and w[j]==0:
            print(l[i][j],end='')
    if h[i]==0:
        print()

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W = map(int,input().split())
h = [0]*H
w = [0]*W
l = [list(input()) for i in range(H)]
for i in range(H):
    if all([i=='.' for i in l[i][:]]):
        h[i]=1
for j in range(W):
    if all([j=='.' for j in np.array(l).T[j][:]]):
        w[j]=1
for i in range(H):
    for j in range(W):
        if h[i]==0 and w[j]==0:
            print(l[i][j],end='')
    if h[i]==0:
        print()
Problem p02900 (python)

Fixed submission:
import fractions
A, B = map(int, input().split())
MAX = fractions.gcd(A, B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
print(len(set(prime_factorize(MAX)))+1)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
MAX = math.gcd(A, B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
print(len(set(prime_factorize(MAX)))+1)
Problem p02957 (python)

Fixed submission:
a, b = map(int, input().split())
if (a + b) % 2 != 0:
    print("IMPOSSIBLE")
else:
    print(int((a+b)/2))

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if p[n] != n+1:
        cnt+=1

if cnt <= 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
q = p.copy()
cnt = 0
for n in range(N):
    if p[n] != q[n]:
        cnt+=1

if cnt <= 2:
    print("YES")
else:
    print("NO")
Problem p02958 (python)

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if p[n] != n+1:
        cnt+=1
 
if cnt <= 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if p[n] != i+1:
        cnt+=1

if cnt <= 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if p[n] != i+1:
        cnt+=1

if cnt <= 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
i = 0
j = 0
for n in range(N-1):
    if p[n] > p[n+1]:
        if i == 0:
            i = p[n]
        elif j == 0:
            j = p[n+1]
        else:
            print("NO")
            exit()

if i == 0 and j == 0:
    print("YES")
elif j < p[p.index(i)+1] and p[p.index(j)-1] < i:
    print("YES") 
else:
    print("NO")
Problem p03280 (python)

Fixed submission:
A, B = map(int, input().split())
print(A*B-A-B+1)

Buggy submission (verdict: Runtime Error):
print(A*B-A-B+1)
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
for i in range(A, min(A+K, B+1)):
    print(i)
for i in range(max(B-K+1, A+K), B+1):
    print(i)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
L = []
if A+K+1 >= B-K+1:
    for i in range(A, b+1):
        print(i)
        exit()
for i in range(A, A+K):
    L.append(i)
for j in range(B-K+1, B+1):
    L.append(j)
list(set(L)).sort()
for k in L:
    print(k)
Problem p03471 (python)

Fixed submission:
N, Y = map(int, input().split())
for a in range(N+1):
    for b in range(N+1-a):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y:
            print(a, b, c)
            exit()
print('-1 -1 -1')

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())
yukichi = -1
ichiyo = -1
hideyo = -1
for a in range(N+1):
    for b in range(N+1-a):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y:
            yukichi = a
            ichiyo = b
            hideyo = c

print(f'{yukichi} {ichiyo} {hideyo}')

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())
yukichi = -1
ichiyo = -1
hideyo = -1
for a in range(N+1):
    for b in range(N+1-a):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y and c >= 0:
            yukichi = a
            ichiyo = b
            hideyo = c

print(f'{yukichi} {ichiyo} {hideyo}')

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())
yukichi = -1
ichiyo = -1
hideyo = -1
for a in range(N+1):
    for b in range(N+1):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y and c >= 0:
            yukichi = a
            ichiyo = b
            hideyo = c

print(f'{yukichi} {ichiyo} {hideyo}')

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())
yukichi = -1
ichiyo = -1
hideyo = -1
for a in range(N+1):
    for b in range(N+1):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y and c >= 0:
            yukichi = a
            ichiyo = b
            hideyo = c

print(f'{yukichi} {ichiyo} {hideyo}')
Problem p03860 (python)

Fixed submission:
AtCoder, s, Contest = map(str, input().split()) 
print('A' + s[0] + 'C')

Buggy submission (verdict: Runtime Error):
AtCoder, s, Contest = map(str, input().split()) 
x = s[0]
print(f'A{x}C')

Buggy submission (verdict: Runtime Error):
AtCoder, s, Contest = map(str, input().split()) 
print(f'A{s[0]}C')AtCoder, s, Contest = map(str, input().split()) 
x = s[0]
print(f'A{s}C')

Buggy submission (verdict: Runtime Error):
AtCoder, s, Contest = map(str, input().split()) 
print(f'A{s[0]}C')

Buggy submission (verdict: Runtime Error):
AtCoder, s, Contest = map(str, input().split()) 
print(f'A{s[0]}C')
Problem p02917 (python)

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
ans = [999999999]*n
for i in range(n-1):
	ans[i] = min(ans[i], arr[i])
	ans[i+1] = min(ans[i+1], arr[i])
print(sum(ans))

Buggy submission (verdict: Runtime Error):
# Author : prayushd
# Language : Python

import re
import os
import sys
from math import ceil, inf
from fractions import gcd
from queue import Queue
from collections import defaultdict, Counter, deque
from bisect import bisect, insort, bisect_left, bisect_right

mod = int(1e9)+7
input = sys.stdin.readline

'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [inf]*n
	for i in range(n-1):
		ans[i] = min(ans[i], arr[i])
		ans[i+1] = min(ans[i+1], arr[i])
	# print(ans)
	print(sum(ans))


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
# Author : prayushd
# Language : Python

import re
import os
import sys
from math import ceil
from fractions import gcd
from queue import Queue
from collections import defaultdict, Counter, deque
from bisect import bisect, insort, bisect_left, bisect_right

mod = int(1e9)+7
input = sys.stdin.readline

'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [inf]*n
	for i in range(n-1):
		ans[i] = min(ans[i], arr[i])
		ans[i+1] = min(ans[i+1], arr[i])
	print(sum(ans))


if __name__ == '__main__':
	main()
Problem p03551 (python)

Fixed submission:
n, m = map(int, input().split(" "))
# n, m = 100, 5

gacha = 1900 * m
state = 100 * (n-m)

res = (gacha + state) * 2**m

print(res)

Buggy submission (verdict: Runtime Error):
n, m = input().split(" ")
# n, m = 100, 5

gacha = 1900 * m
state = 100 * (n-m)

res = (gacha + state) * 2**m

print(res)
Problem p03683 (python)

Fixed submission:
from math import factorial

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

def foo(N,M):
	if N == M+1 or N+1 == M:
		tm = factorial(min(N,M))
		return(tm*max(N,M)*tm)

	elif N==M:
		return((factorial(N)**2)*2)

	else:
		return(0)

print(foo(N,M)%(10**9+7))

Buggy submission (verdict: Runtime Error):
from math import factorial

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

def foo(N,M):
	if N == M+1 or N+1 == M:
		tm = factorial(min(N,M))
		return(tm*max(N,M)+tm)

	elif N==M:
		return(2*factorial(N)*2)

	else:
		return(0)

print(foo(N,M)/(10**9+7))
Problem p03747 (python)

Fixed submission:
N, L, T = list(map(int, input().split(" ")))

# N,L,T = 3,10,6
# a = [1,2,3]
# b = [2,1,1]

a = []
b = []
for i in range(N):
    an, ve = map(int, input().split(" "))
    a.append(an)
    b.append(ve)

crash = 0

for i in range(1, N):
    if b[0] != b[i]:
        if b[0] == 1:
            crash += (T - ((a[i] - a[0]) / 2)) // (L / 2) + 1
        else:
            crash += (T - (L - (a[i] - a[0])) / 2) // (L / 2) + 1

for i in range(N):
    if b[i] == 1:
        a[i] += T
    else:
        a[i] -= T
    a[i] %= L


if b[0] == 1:
    where = int(crash) % N
else:
    where = int(-crash) % N

nowplace = a[0]

a.sort()

if b[0] == 1:
	where0 = max([i for i in range(N) if a[i] == nowplace])
else:
	where0 = min([i for i in range(N) if a[i] == nowplace])

where0 = (where0 - where) % N

res = a[where0:] + a[:where0]
res = map(str, res)

for i in res:
    print(i)

Buggy submission (verdict: Runtime Error):
N, L, T = list(map(int, input().split(" ")))

# N,L,T = 3,10,6
# a = [1,2,3]
# b = [2,1,1]

a = []
b = []
for i in range(N):
    an, ve = map(int, input().split(" "))
    a.append(an)
    b.append(ve)

crash = 0

for i in range(1, N):
    if b[0] != b[i]:
        if b[0] == 1:
            crash += (T - ((a[i] - a[0]) / 2)) // (L / 2) + 1
        else:
            crash += (T - (L - (a[i] - a[0])) / 2) // (L / 2) + 1

for i in range(N):
    if b[i] == 1:
        a[i] += T
    else:
        a[i] -= T
    a[i] %= L


if b[0] == 1:
    where = int(crash) % N
else:
    where = int(-crash) % N

nowplace = a[where]
a.sort()

if b[0] == 1:
	if crash % 2 == 1:
		where0 = min([i for i in range(N) if a[i] == nowplace])
	else:
		where0 = max([i for i in range(N) if a[i] == nowplace])		
else:
	if crash % 2 == 1:
		where0 = max([i for i in range(N) if a[i] == nowplace])
	else:
		where0 = min([i for i in range(N) if a[i] == nowplace])

where0 = (where0 - crash) % N

res = a[where0:] + a[:where0]
res = map(str, res)

for i in res:
    print(i)
Problem p03765 (python)

Fixed submission:
S = list(input())
T = list(input())

# S=list("BBAAABA")
# T=list("BBBA")

q = int(input())

l = []
for i in range(q):
	l.append(list(map(int,input().split(" "))))


sta = [0 for i in range(len(S))]
stb = [0 for i in range(len(S))]

tta = [0 for i in range(len(T))]
ttb = [0 for i in range(len(T))]

if S[0] == "A":
	sta[0] = 1
else:
	stb[0] = 1

if T[0] == "A":
	tta[0] = 1
else:
	ttb[0] = 1

for i in range(1,len(S)):
	if S[i] == "A":
		sta[i] = sta[i-1]+1
		stb[i] = stb[i-1]
	else:
		sta[i] = sta[i-1]
		stb[i] = stb[i-1]+1

for i in range(1,len(T)):
	if T[i] == "A":
		tta[i] = tta[i-1]+1
		ttb[i] = ttb[i-1]
	else:
		tta[i] = tta[i-1]
		ttb[i] = ttb[i-1]+1


def get(l,a,b):
	if a == 0:
		return(l[b])
	else:
		return(l[b]-l[a-1])

for a,b,c,d in l:
	sa = get(sta,a-1,b-1)
	sb = get(stb,a-1,b-1)
	ta = get(tta,c-1,d-1)
	tb = get(ttb,c-1,d-1)


	if (sa+sb*2)%3 == (ta+tb*2)%3:
		print("YES")
	else:
		print("NO")

Buggy submission (verdict: Runtime Error):
S = list(input())
T = list(input())

# S=list("BBAAABA")
# T=list("BBBA")

q = int(input())

l = []
for i in range(q):
	l.append(list(map(int,input().split(" "))))


sta = [0 for i in range(len(S))]
stb = [0 for i in range(len(S))]

tta = [0 for i in range(len(T))]
tta = [0 for i in range(len(T))]

if S[0] == "A":
	sta[0] = 1
else:
	stb[0] = 1

if T[0] == "A":
	tta[0] = 1
else:
	ttb[0] = 1

for i in range(1,len(S)):
	if S[i] == "A":
		sta[i] = sta[i-1]+1
	else:
		stb[i] = stb[i-1]+1

for i in range(1,len(T)):
	if T[i] == "A":
		tta[i] = tta[i-1]+1
	else:
		ttb[i] = ttb[i-1]+1

def get(l,a,b):
	if a == 0:
		return(l[b])
	else:
		return(l[b]-l[a-1])
		
for a,b,c,d in l:
	sa = get(sta,a-1,b-1)
	sb = get(stb,a-1,b-1)
	ta = get(tta,c-1,d-1)
	tb = get(ttb,c-1,d-1)


	if (sa+sb*2)%3 == (ta+tb*2)%3:
		print("YES")
	else:
		print("NO")
Problem p02900 (python)

Fixed submission:
#import numpy as np
#from math import gcd

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

    
##################################################################

if __name__ == "__main__":
    Input1 = [input() for i in range(1)]
    #N = int(Input1[0])
    A,B = list(map(int,Input1[0].split()))
    if B > A:
        temp = A
        A = B
        B = temp

    ans = 1
    if B == 1:
        print(ans)
    else:
        fact = factorization(B)
        for i in range(len(fact)):
            f = fact[i][0]
            if A % f == 0:
                ans += 1
        print(ans)
    
    #print(' '.join(map(str,B)))

Buggy submission (verdict: Runtime Error):
#import numpy as np
#from math import gcd

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

    
##################################################################

if __name__ == "__main__":
    Input1 = [input() for i in range(1)]
    #N = int(Input1[0])
    A,B = list(map(int,Input1[0].split()))
    if B > A:
        temp = A
        A = B
        B = temp

    ans = 1
    if B == 1:
        print(ans)
    else:
        for i in range(len(fact)):
            f = fact[i][0]
            if A % f == 0:
                ans += 1
        print(ans)
    
    #print(' '.join(map(str,B)))
Problem p03029 (python)

Fixed submission:
A,P=map(int,input().split())
print(((A*3)//2 + P//2) + (((A*3)%2 + P%2)//2))

Buggy submission (verdict: Runtime Error):
A,P=map(int,input().split())
print(((A*3)//2 + b//2) + (((A**3)%2 + b%2)//2))
Problem p03101 (python)

Fixed submission:
H,W=map(int,input().split())
h,w=map(int,input().split())
print(H*W-((W*h)+((H*w)-(h*w))))

Buggy submission (verdict: Runtime Error):
H,W=int(input())
h,w=int(input())
print(H*W-(W*h)+((H*w)-(h*w)))
Problem p03106 (python)

Fixed submission:
A,B,K=list(map(int,input().split()))
ans=[]
c=min(A,B)
for i in range(1,c+1):
  if A%i==0 and B%i==0:
    ans.append(i)

print(ans[-K])

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
ans=[]
for i in range(1,A):
  if A%i==0 and B%i==0:
    ans.append(i)

if len(ans)==0:
  print(1)
else:
  print(ans[-K])
Problem p03292 (python)

Fixed submission:
a,b,c=map(int,input().split())
print(max(a,b,c)-min(a,b,c))

Buggy submission (verdict: Runtime Error):
a,b,c=int(input())
print(max(a,b,c)-min(a,b,c))
Problem p03711 (python)

Fixed submission:
s='0131212112121'
x,y=map(int,input().split())
print("Yes" if s[x]==s[y] else "No")

Buggy submission (verdict: Runtime Error):
s='0131212112121'
print("Yes" if s[x]==s[y] else "No")
Problem p02910 (python)

Fixed submission:
s = input()
c = True
for i in range(len(s)):
    if i % 2 == 1:
        if s[i] != 'U' and s[i] != 'D' and s[i] != 'L':
            c = False
    if i % 2 == 0:
        if s[i] != 'U' and s[i] != 'D' and s[i] != 'R':
            c = False

if c:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
c = True
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != 'U' && s[i] != 'D' && s[i] != 'L':
            c = False
    if i % 2 == 1:
        if s[i] != 'U' && s[i] != 'D' && s[i] != 'R':
            c = False

if c:
    print('Yes')
else:
    print('No')
Problem p02922 (python)

Fixed submission:
import math

a, b = map(int, input().split())

print(math.ceil((b - 1) / (a - 1)))

Buggy submission (verdict: Runtime Error):
n = int(input())


if n % 2 == 0:
    print(int(n / 2 * (n - 1)))
else:
    print(int((n - 1) / 2 * n))
Problem p02936 (python)

Fixed submission:
# def add_node(tree, counter, ope, node, value):
#     if node in ope:
#         value += ope[node]
#     counter[node - 1] += value

#     if node in tree:
#         for i in tree[node]:
#             add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
for i in range(1, n + 1):
    if i in ope:
        counter[i - 1] += ope[i]
    if i in tree:
        for j in tree[i]:
            counter[j - 1] += counter[i - 1]
    
# add_node(tree, counter, ope, 1, 0)

print(*counter)

Buggy submission (verdict: Runtime Error):
def add_node(tree, counter, ope, node, value):
    if node in ope:
        value += ope[node]
    counter[node - 1] += value

    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
add_node(tree, counter, ope, 1, 0)

print(*counter)

Buggy submission (verdict: Runtime Error):
def add_node(tree, counter, ope, node, value):
    if node in ope:
        value += ope[node]
    counter[node - 1] += value

    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, ope, i, value)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

# print(tree, ope)

# for k in ope:
add_node(tree, counter, ope, 1, 0)

print(*counter)

Buggy submission (verdict: Runtime Error):
def add_node(tree, counter, value, node):
    counter[node - 1] += value
    if node in tree:
        for i in tree[node]:
            add_node(tree, counter, value, i)


n, q = map(int, input().split())

tree = {}

for i in range(n - 1):
    a, b = map(int, input().split())
    if a not in tree:
        tree[a] = [b]
    else:
        tree[a].append(b)

ope = {}
for j in range(q):
    p, x = map(int, input().split())
    if p not in ope:
        ope[p] = x
    else:
        ope[p] += x

counter = [0] * n

for k in ope:
    add_node(tree, counter, ope[k], k)

print(*counter)
Problem p03294 (python)

Fixed submission:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import fractions
    import functools

    n = int(input())
    as_ = list(map(int, input().split()))
        
    # gcd = functools.reduce(math.gcd, as_)
    gcm = as_[0]
    for i in range(1, n):
        gcm = gcm * as_[i] // fractions.gcd(gcm, as_[i])
        # print(gcm)
    # print(gcm - 1)
    gcm_1 = gcm - 1
    print(functools.reduce(lambda x, y: x + gcm_1 % y, as_, 0))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import fractions
    import functools

    n = int(input())
    as_ = list(map(int, input().split()))
        
    # gcd = functools.reduce(math.gcd, as_)
    gcm = as_[0]
    for i in range(1, n):
        gcm = gcm * as_[i] // math.gcd(gcm, as_[i])
        # print(gcm)
    # print(gcm - 1)
    gcm_1 = gcm - 1
    print(functools.reduce(lambda x, y: x + gcm_1 % y, as_, 0))

if __name__ == '__main__':
    main()