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

Fixed submission:
s = str(input())
s=s.replace(","," ")
print(s)

Buggy submission (verdict: Runtime Error):
K, S = map(int,input().split())
count = 0
for x in range(0,K+1,1):
  for y in range(0,K+1,1):
    z = S - x - y
    print(x,y,z)
    if x+y+z == S and z <= K and z >= 0:
      count += 1
print(count)
Problem p02754 (python)

Fixed submission:
n, a, b = map(int, input().split(' '))
r = n//(a+b)
print(int(r*a+min((n-r*(a+b),a))))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split(' '))
print(min(int(n%(a+b)),a)+int((n//(a+b)1)*a))
Problem p02623 (python)

Fixed submission:
import bisect
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

SumA = [0]
SumB = [0]
cnt = 0
for i in range(N):
    SumA.append(SumA[i] + A[i])
for i in range(M):
    SumB.append(SumB[i] + B[i])

for i in range(N+1):
    if SumA[i] > K:
        break
    tmpcnt = bisect.bisect_right(SumB, K - SumA[i]) - 1
    #print([SumA,SumB])
    #print(SumA[i])
    #print(K - SumA[i])
    #print(tmpcnt)
    #print([i,tmpcnt])
    cnt = max(cnt, i + tmpcnt)
print(cnt)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumt = 0
cnt = 0
    
while cnt < (N+M):
    
    if len(A) > 0:
        tmpA = A[0]
    else:
        tmpA = 10**10

    if len(B) > 0:
        tmpB = B[0]
    else:
        tmpA = 10**10

    if tmpA <= tmpB:
        sumt += A.pop(0)
    else:
        sumt += B.pop(0)

    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumt = 0
cnt = 0
    
for i in range(N+M):
    
    if len(A) > 0:
        tmpA = A[0]
    else:
        tmpA = 10**10

    if len(B) > 0:
        tmpB = B[0]
    else:
        tmpA = 10**10

    if tmpA <= tmpB:
        sumt += A.pop(0)
    else:
        sumt += B.pop(0)

    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumt = 0
cnt = 0
Ai = 0
Bi = 0

if (sum(A) + sum(B)) <= K:
    print(N+M)
    exit(0)
    
for i in range(N+M):
    if A[0] <= B[0]:
        sumt += A.pop(0)
    else:
        sumt += B.pop(0)

    if sumt > K:
        print(cnt)
        exit(0)
        
    cnt += 1
Problem p02729 (python)

Fixed submission:
# 200322 A

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    
    if N <= 1:
        Nc = 0
    else:
        Nc = cmb(N,2)
    
    if M < 2:
        Mc = 0
    else:
        Mc = cmb(M,2)
    print(Nc + Mc)

Buggy submission (verdict: Runtime Error):
# 200322 A
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
    
if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    print(cmb(N,2)+cmb(M,2))

Buggy submission (verdict: Runtime Error):
# 200322 A

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
    
if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    print(cmb(N,2)+cmb(M,2))

Buggy submission (verdict: Runtime Error):
# 200322 A

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

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

print(cmb(N,2)+cmb(M,2))
Problem p02831 (python)

Fixed submission:
import fractions

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

print(int((a * b) // fractions.gcd(a,b)))

Buggy submission (verdict: Runtime Error):
import math

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

print(int((a * b) // math.gcd(a,b)))

Buggy submission (verdict: Runtime Error):
import math

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

print(int(a * b // math.gcd(a,b)))

Buggy submission (verdict: Runtime Error):
import math

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

print(int(a * b / math.gcd(a,b)))

Buggy submission (verdict: Runtime Error):
import math

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

print(int(a * b / math.gcd(a,b)))
Problem p02623 (python)

Fixed submission:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sumA = [0]
sumB = [0]
tmp = 0
answer = 0
st = 0

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, -1, -1):
    booktmp = 0

    for j in range(st, M + 1):

        if sumA[i] + sumB[j] <= K:
            booktmp = i + j
        else:
            st = j
            break
    answer = max(answer, booktmp)
    if j == M:
        break


print(answer)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sumA = []
sumB = []
tmp = 0
answer = 0
st = 1

for i in range(N):
    tmp = tmp + A[i]
    sumA.append(tmp)

tmp = 0
for i in range(M):
    tmp = tmp + B[i]
    sumB.append(tmp)

for i in range(N, 0, -1):
    booktmp = 0

    for j in range(st , M + 1):

        if sumA[i-1] + sumB[j-1] <= K:
            booktmp = i + j
            st = st + 1
        else:
            st = st - 1
            break
    answer = max(answer, booktmp)


print(answer)
Problem p02831 (python)

Fixed submission:
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import statistics
import string


def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True
def hcfnaive(a,b):
    if(b==0):
        return a
    else:
        return hcfnaive(b,a%b)

a,b = splitintinput()
g = hcfnaive(a,b)
print(int(a*b/g))

Buggy submission (verdict: Runtime Error):
# from fractions import gcd
# mod = 10 ** 9 + 7
# N = int(input())
# a = list(map(int,input().split()))
# a,b,c = map(int,input().split())
# ans = [0] * N
# math.ceilで切り上げ
# dp = [[0] * 4 for i in range(3)] #2次元配列初期化
# dp = [[[0] * 2 for i in range(3)] for j in range(5)]
# (ord('A'))でASCII出力 Aは65
import math
import statistics
import string


def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True

a,b = splitintinput()
g = math.gcd(a,b)
print(int(a*b/g))

Buggy submission (verdict: Runtime Error):
import math
import statistics
import string


def intinput():
    return int(input())
def listintinput():
    return list(map(int, input().split()))
def splitintinput():
    return map(int, input().split())
def factorialsurplus(x, y, z):  # xからyまでの階乗をzで割ったあまりを求める
    ret = 1
    for i in range(x, y + 1):
        ret = (ret * i) % z
    return (ret)
def isprime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    sq = int(math.sqrt(x))
    for i in range(2,sq+1):
        if x % i == 0:
            return False
    return True

a,b = splitintinput()
gcd = math.gcd(a,b)
print(int(a*b/gcd))
Problem p02847 (python)

Fixed submission:
ans = {"SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1, }
s = input()
print(ans[s])

Buggy submission (verdict: Runtime Error):
ans = {"SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1, }
s = input()
print(ans[s])D
Problem p02879 (python)

Fixed submission:
a,b = map(int,input().split())
if a > 9 or b > 9:
    print(-1)
else:
    print(a*b)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
if a > 9 or b > 9:
    print(-1)
else:
    print(A*B)
Problem p03774 (python)

Fixed submission:
n,m = map(int,input().split())#n学生 mチェックポイント
student = []
checkpoint = []
for i in range(n):
    student.append(list(map(int,input().split())))
for i in range(m):
    checkpoint.append(list(map(int,input().split())))

for i in range(n):
    ans = 0 #答えの初期化
    tmp = 100000000000 #距離初期化
    for j in range(m):
        if tmp > abs(student[i][0] - checkpoint[j][0]) + abs(student[i][1] - checkpoint[j][1]):
            ans = j
            tmp = abs(student[i][0] - checkpoint[j][0]) + abs(student[i][1] - checkpoint[j][1])
    print(ans+1)

Buggy submission (verdict: Runtime Error):

m,n = map(int,input().split())#m学生 nチェックポイント
student = []
checkpoint = []
for i in range(m):
    student.append(list(map(int,input().split())))
for i in range(n):
    checkpoint.append(list(map(int,input().split())))

for i in range(m):
    ans = 0 #答えの初期化
    tmp = 1000000000
    for j in range(n):
        if tmp > abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1]):
            ans = i
            tmp = abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1])
    print(ans+1)

Buggy submission (verdict: Runtime Error):

m,n = map(int,input().split())#m学生 nチェックポイント
student = []
checkpoint = []
for i in range(n):
    student.append(list(map(int,input().split())))
for i in range(m):
    checkpoint.append(list(map(int,input().split())))

for i in range(m):
    ans = 0 #答えの初期化
    tmp = 10000000000000
    for j in range(n):
        if tmp > abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1]):
            ans = i
            tmp = abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1])
    print(ans+1)

Buggy submission (verdict: Runtime Error):
m,n = map(int,input().split())#m学生 nチェックポイント
student = []
checkpoint = []
for i in range(n):
    student.append(list(map(int,input().split())))
for i in range(m):
    checkpoint.append(list(map(int,input().split())))

for i in range(m):
    ans = 0 #答えの初期化
    tmp = 10000000000000
    for j in range(m):
        if tmp > abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1]):
            ans = i
            tmp = abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1])
    print(ans+1)

Buggy submission (verdict: Runtime Error):
m,n = map(int,input().split())#m学生 nチェックポイント
student = []
checkpoint = []
for i in range(n):
    student.append(list(map(int,input().split())))
for i in range(m):
    checkpoint.append(list(map(int,input().split())))

for i in range(m):
    ans = 0 #答えの初期化
    tmp = 10000000000000
    for j in range(m):
        if tmp < abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1]):
            ans = i
            tmp = abs(student[i][0] - checkpoint[i][0]) + abs(student[i][1] - checkpoint[i][1])
    print(ans+1)
Problem p03804 (python)

Fixed submission:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を1行ずつ比較
            if b[k] != a[i+k][j:j+n]:
                break
        else:
            flag = True
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n+1):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

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

Buggy submission (verdict: Runtime Error):
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

print(a)
print(b)

for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n+1):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

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

Buggy submission (verdict: Runtime Error):
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

print(a)
print(b)

for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n+1):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

if flag:
    print('Yes')
else:
    print('No')
Problem p02723 (python)

Fixed submission:
S = input()
if S[2] == S[3] and S[4] == S[5]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N, X, Y = map(int,input().split())
X -= 1
Y -= 1

nallpath = N*(N-1)//2
distance = [0] * nallpath

indx = 0
for j in range(N-1):
    for i in range(j+1,N):
        if i <= X:
            distance[indx] = i - j
        elif j >= Y:
            distance[indx] = i - j
        elif j <= X and Y<= i:
            distance[indx] = i - j - (Y-X-1)
        elif  X <= j < i <= Y:
            distance[indx] = min(i-j, (j-X)+(Y-i)+1)
        elif j <= X and X < i <= Y:
            distance[indx] = (X-j) + min(i-X, Y-i+1)
        else:
            distance[indx] = (i-Y) + min(Y-j, j-X+1)
        indx += 1
for i in range(N-1):print(distance.count(i+1))
Problem p02951 (python)

Fixed submission:
A, B, C = map(int,input().split())
print(max(0, C-(A-B)))

Buggy submission (verdict: Runtime Error):
A, B, C = map(int,input())
print(max(0, C-(A-B)))
Problem p02954 (python)

Fixed submission:
S = input()

Lindex = S.index("L")
Rindex = 0

num = [0]*len(S)

for i in range(len(S)):
  if S[i] == "R":
    Rindex = i
    if Lindex < i: Lindex = i+ S[i:].index("L")
    if (Lindex-i)%2==1:
      num[Lindex-1] += 1
    else:
      num[Lindex] += 1
  else:
    if (Rindex-i)%2==1:
      num[Rindex+1] += 1
    else:
      num[Rindex] += 1
print(*num)

Buggy submission (verdict: Runtime Error):
S = input()
num = [0]*len(S)
for i in range(len(S)):
  if S[i] == "R":
    for j in range(i+1,len(S)):
      if S[j] =="L":
        Lindex = j
        break
    if (Lindex-i)%2==1:
      num[Lindex-1] += 1
    else:
      num[Lindex] += 1
  else:
    for j in range(i-1,0,-1):
      if S[j] =="R":
        Rindex = j
        break
    if (Rindex-i)%2==1:
      num[Rindex+1] += 1
    else:
      num[Rindex] += 1

print(*num)

Buggy submission (verdict: Runtime Error):
S = input()
num = [0]*len(S)
for i in range(len(S)):
  if S[i] == "R":
    for j in range(i+1,len(S)):
      if S[j] =="L":
        Lindex = j
        break
    if (Lindex-i)%2==1:
      num[Lindex-1] += 1
    else:
      num[Lindex] += 1
  else:
    for j in range(i-1,0,-1):
      if S[j] =="R":
        Rindex = j
        break
    if (Rindex-i)%2==1:
      num[Rindex+1] += 1
    else:
      num[Rindex] += 1

print(*num)
Problem p02862 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

fac = [0] * (10**6+5)
ifac = [0] * (10**6+5)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k
    if x - 2 * q < 0 or q < 0:
        print(0)
        return

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

fac = [0] * (10**6+1)
ifac = [0] * (10**6+1)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

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

Fixed submission:
import sys
input = sys.stdin.readline
from math import factorial

def main():
	n, k = map(int, input().strip().split())
	for i in range(1, k+1):
		if i-1 > n - k:
			print(0)
			continue
		c = factorial(k-1)//(factorial(k-i)*factorial(i-1))
		noko = factorial(n-k+1)//(factorial(i) * factorial(n-k-i+1))
		# print(c, noko)
		ans = c * noko
		# print(ans)
		ans %= 10**9+7
		print(ans)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from math import factorial

def main():
	n, k = map(int, input().strip().split())
	for i in range(1, k+1):
		c = factorial(k-1)//(factorial(k-i)*factorial(i-1))
		noko = factorial(n-k+1)//(factorial(i) * factorial(n-k-i+1))
		# print(c, noko)
		ans = c * noko
		# print(ans)
		ans %= 10**9+7
		print(ans)


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

Fixed submission:
import sys
input = sys.stdin.readline

def main():
	n, m = map(int, input().strip().split())
	v = [0] * (n+1)
	v[0] = 1
	v[1] = 1
	N = []
	for i in range(m):
		a = int(input().strip())
		N.append(a)
	N.append(-1)
	j = 0
	for i in range(1, n+1):
		if N[j] == i:
			v[i] = 0
			j += 1
		else:
			if i == 1:
				v[i] = 1
			else:
				v[i] = v[i-1] + v[i-2]
	print(v[n] % (10**9+7))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)
N = []
v = []
def rec(n):
	global N
	global v
	if v[n] != -1:
		return v[n]

	if N[n] == 1:
		v[n] = 0
	elif n == 1:
		v[n] = 1
	elif N[n-1] == 1:
		v[n] = rec(n-2)
	else:
		v[n] = rec(n-2) + rec(n-1)
	# print("v:", v[n])
	return v[n]

def main():
	global N, v
	n, m = map(int, input().strip().split())
	N = [0] * (n+1)
	v = [-1] * (n+1)
	v[0] = 1
	for i in range(m):
		a = int(input().strip())
		N[a] = 1
	# print(v)
	# print(N)
	print(rec(n) % (10**9+7))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = []
v = []
def rec(n):
	global N
	global v
	if v[n] != -1:
		return v[n]

	if N[n] == 1:
		v[n] = 0
	elif n == 1:
		v[n] = 1
	elif N[n-1] == 1:
		v[n] = rec(n-2)
	else:
		v[n] = rec(n-2) + rec(n-1)
	# print("v:", v[n])
	return v[n]

def main():
	global N, v
	n, m = map(int, input().strip().split())
	N = [0] * (n+1)
	v = [-1] * (n+1)
	v[0] = 1
	for i in range(m):
		a = int(input().strip())
		N[a] = 1
	# print(v)
	# print(N)
	print(rec(n) % (10**9+7))

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

Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

tmp = []
tree = []

def dfs(node, depth, fr):
    global tmp, tree
    tree[node] = (fr, depth)
    for i, c in tmp[node]:
        if i != fr:
            dfs(i, depth+c, node)

def main():
    global tmp, tree
    n = int(input().strip())
    tmp = [[] for _ in range(n)]
    tree = [0] * n
    for _ in range(n-1):
        a, b, c = map(int, input().strip().split())
        a -= 1
        b -= 1

        if b > a:
            a, b = b, a
        tmp[a].append((b, c))
        tmp[b].append((a, c))

    q, k = map(int, input().strip().split())
    k -= 1
    dfs(k, 0, -1)
    # print(tmp)
    # print(tree)
    for _ in range(q):
        x, y = map(lambda x: x-1, map(int, input().strip().split()))
        print(tree[x][1] + tree[y][1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from operator import itemgetter

tmp = []
tree = []

def dfs(node, depth, fr):
    global tmp, tree
    tree[node] = (fr, depth)
    for i, c in tmp[node]:
        if i != fr:
            dfs(i, depth+c, node)

def main():
    global tmp, tree
    n = int(input().strip())
    tmp = [[] for _ in range(n)]
    tree = [0] * n
    for _ in range(n-1):
        a, b, c = map(int, input().strip().split())
        a -= 1
        b -= 1

        if b > a:
            a, b = b, a
        tmp[a].append((b, c))
        tmp[b].append((a, c))

    q, k = map(int, input().strip().split())
    k -= 1
    dfs(k, 0, -1)
    # print(tmp)
    # print(tree)
    for _ in range(q):
        x, y = map(lambda x: x-1, map(int, input().strip().split()))
        print(tree[x][1] + tree[y][1])


if __name__ == '__main__':
    main()