Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# ki
from collections import deque

# input

n, q = map(int, input().split())
ln = [list(map(int, input().split())) for i in range(n-1)]
lq = [list(map(int, input().split())) for i in range(q)]

edge = [[] for i in range(n+1)]

for next in ln:
    parent = next[0]
    child = next[1]
    edge[parent].append(child)
    edge[child].append(parent)


score = [0]*(n+1)
visited = [False]*(n+1)

for q in lq:
    score[q[0]] += q[1]

que = deque()
que.append(1)

while que:
    node = que.popleft()
    if not visited[node]:
        visited[node] = True
        for next in edge[node]:
            if not visited[next]:
                score[next] += score[node]
                que.append(next)

print(" ".join([str(n) for n in score][1:]))


Fixed submission:
# ki
from collections import deque

# input

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

edge = [[] for i in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

lq = [list(map(int, input().split())) for i in range(q)]

score = [0]*(n+1)
visited = [False]*(n+1)

for q in lq:
    score[q[0]] += q[1]

que = deque()
que.append(1)

while que:
    node = que.popleft()
    if not visited[node]:
        visited[node] = True
        for next in edge[node]:
            if not visited[next]:
                score[next] += score[node]
                que.append(next)

print(" ".join([str(n) for n in score][1:]))
Buggy python submission (verdict: Time Limit Exceeded):
qt = int(input())
sl = [input() for i in range(qt)]
ls = []
count = 0

for s in sl:
    s = "".join(sorted(s))
    ls.append(s)

i = 0
j = 0
key = ""

while len(ls) > i:
    while len(ls) > (j + 1):
        j += 1
        if ls[i] == ls[j]:
            count += 1
    i += 1
    j = i

print(count)


Fixed submission:
import math as m

qt = int(input())
sl = [input() for i in range(qt)]
d = {}
count = 0

for s in sl:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for e in d.values():
    if e > 1:
        count += m.factorial(e) // (m.factorial(e - 2) * 2)

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
la = [int(input()) for i in range(n)]

s_la = sorted(la, reverse=True)

for a in la:
	max_la = copy.copy(s_la)
	max_la.remove(a)
	print(max_la[0])

Fixed submission:

n = int(input())
la = [int(input()) for i in range(n)]

s_la = sorted(la, reverse=True)

for a in la:
	if a == s_la[0]:
		print(s_la[1])
	else:
		print(s_la[0])
Buggy python submission (verdict: Runtime Error):
import math

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

a -= 1
cd = (c * d) // math.gcd(c, d)

a_d_c = a // c
b_d_c = b // c

a_d_d = a // d
b_d_d = b // d

a_d_cd = a // cd
b_d_cd = b // cd

b_d = b_d_c + b_d_d - b_d_cd
a_d = a_d_c + a_d_d - a_d_cd

ans =  b - b_d - a + a_d

print(ans)

Fixed submission:
import fractions as math

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

a -= 1
cd = (c * d) // math.gcd(c, d)

a_d_c = a // c
b_d_c = b // c

a_d_d = a // d
b_d_d = b // d

a_d_cd = a // cd
b_d_cd = b // cd

b_d = b_d_c + b_d_d - b_d_cd
a_d = a_d_c + a_d_d - a_d_cd

ans =  b - b_d - a + a_d

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = map(int, input().split())

cd = c * d
count = 0

a_d, a_m = divmod(a, cd)
b_d, b_m = divmod(b, cd)

left = cd * (a_d+1)
if left > b:
	left = b

for i in range(a, left):
	if i % c != 0 and i % d != 0:
		count += 1

right = cd * b_d

if right >= left + cd:
	count2 = 0
	for i in range(left, left + cd):
		if i % c != 0 and i % d != 0:
			count2 += 1
	
	count += count2 * (b_d - a_d - 1)
 
if right >= left:
	for i in range(right, b+1):
		if i % c != 0 and i % d != 0:
			count += 1
#print("{} {} {} {}".format(a, left, right, b))
print(count)

Fixed submission:
import fractions as math

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

a -= 1
cd = (c * d) // math.gcd(c, d)

a_d_c = a // c
b_d_c = b // c

a_d_d = a // d
b_d_d = b // d

a_d_cd = a // cd
b_d_cd = b // cd

b_d = b_d_c + b_d_d - b_d_cd
a_d = a_d_c + a_d_d - a_d_cd

ans =  b - b_d - a + a_d

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions as m

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

gstackl = [0]
gstackr = [0]

ans = 0

for i in range(0, n):
	gstackl.append(m.gcd(gstackl[i], al[i]))

for i in reversed(range(1, n)):
	gstackr = [m.gcd(gstackr[0], al[i])] + gstackr

gstackr.append(0)

#print(gstackl)
#print(gstackr)

for i in range(n):
	l = gstackl[i]
	r = gstackr[i]
	#print("{} {}".format(l, r))
	a = m.gcd(l, r)
	#print(a)
	if a > ans:
		ans = a

print(ans)

Fixed submission:
import fractions as m

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

gstackl = [0]*n
gstackr = [0]*n

ans = 0

for i in range(1, n):
	gstackl[i] = m.gcd(gstackl[i-1], al[i-1])
	gstackr[n-i-1] = m.gcd(gstackr[n-i], al[n-i])

#print(gstackl)
#print(gstackr)

for i in range(n):
	l = gstackl[i]
	r = gstackr[i]
	#print("{} {}".format(l, r))
	a = m.gcd(l, r)
	#print(a)
	if a > ans:
		ans = a

print(ans)

Buggy python submission (verdict: Runtime Error):
import math as m

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

gstackl = [0]
gstackr = [0]

ans = 0

for i in range(0, n):
	gstackl.append(m.gcd(gstackl[i], al[i]))

for i in reversed(range(1, n)):
	gstackr = [m.gcd(gstackr[0], al[i])] + gstackr

gstackr.append(0)

#print(gstackl)
#print(gstackr)

for i in range(n):
	l = gstackl[i]
	r = gstackr[i]
	#print("{} {}".format(l, r))
	a = m.gcd(l, r)
	#print(a)
	if a > ans:
		ans = a

print(ans)

Fixed submission:
import fractions as m

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

gstackl = [0]*n
gstackr = [0]*n

ans = 0

for i in range(1, n):
	gstackl[i] = m.gcd(gstackl[i-1], al[i-1])
	gstackr[n-i-1] = m.gcd(gstackr[n-i], al[n-i])

#print(gstackl)
#print(gstackr)

for i in range(n):
	l = gstackl[i]
	r = gstackr[i]
	#print("{} {}".format(l, r))
	a = m.gcd(l, r)
	#print(a)
	if a > ans:
		ans = a

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c, k = [int(x) for x in input().split()]

if k <= a:
  print(k)
elif a < k and k<= a+b:
  print(a)
else:
  print(a-(k-a-b))


Fixed submission:
s= str(input())
t= str(input())

if len(t) == len(s) + 1 and len(s) >=1 and len(s) <= 10 and t.islower() and s.islower() and s==t[:-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a, b, c, k = [int(x) for x in input().split()]

if k <= a:
  print(k)
elif k<= a+b:
  print(a)
else:
  print(a-(k-a-b))

Fixed submission:
s= str(input())
t= str(input())

if len(t) == len(s) + 1 and len(s) >=1 and len(s) <= 10 and t.islower() and s.islower() and s==t[:-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a, b, c, k = [int(x) for x in input().split()]

ab = a+b
abc = a+b+c

if k <= a:
  print(k)
elif k<= ab:
  print(k)
else:
  print(a-(k-ab))

Fixed submission:
s= str(input())
t= str(input())

if len(t) == len(s) + 1 and len(s) >=1 and len(s) <= 10 and t.islower() and s.islower() and s==t[:-1]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
s= str(input())
t= str(input())

if len(t) = len(s) + 1 and len(s) >=1 and len(s) <= 10 and s.islower() and t.islower():
  print("Yes")
else:
  print("No")

Fixed submission:
s= str(input())
t= str(input())

if len(t) == len(s) + 1 and len(s) >=1 and len(s) <= 10 and t.islower() and s.islower() and s==t[:-1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a, b, c, k = [int(x) for x in input().split()]

ab = a+b
abc = a+b+c

if k <= a:
  print(k)
elif k<= ab:
  print(k):
else:
  print(a-(k-ab))


Fixed submission:
a, b, c, k = [int(x) for x in input().split()]
 
if k <= a:
  print(k)
elif a < k and k<= a+b:
  print(a)
else:
  print(a-(k-a-b))
Buggy python submission (verdict: Runtime Error):
n, m, x = [int(x) for x in input().split()]
c = []
a = []
for i in range(n):
  tmp = [int(x) for x in input().split()]
  c.append(tmp[0])
  a.append(tmp[1:])
#全探索
ans = 10**8 # as INF
for s in range(2**n):
  s = bin(s)
  cost = 0
  d = [0 for j in range(m)]
  for i in range(n):
    is_use = bin(s>>i&1) == bin(1)
    if is_use:
      cost += c[i]
      for j in range(m):
        d[j]+=a[i][j]
  ok = True
  for j in range(m):
    if d[j] < x:
      ok = False
  if ok and cost < ans:
    ans = cost
print(ans)
  	


Fixed submission:
n, m, x = [int(x) for x in input().split()]
c = []
a = []
for i in range(n):
  tmp = [int(x) for x in input().split()]
  c.append(tmp[0])
  a.append(tmp[1:])
#全探索
ans = 10**8 # as INF
for s in range(2**n):
  cost = 0
  d = [0 for j in range(m)]
  for i in range(n):
    is_use = bin(s>>i&1) == bin(1)
    if is_use:
      cost += c[i]
      for j in range(m):
        d[j]+=a[i][j]
  ok = True
  for j in range(m):
    if d[j] < x:
      ok = False
  if ok and cost < ans:
    ans = cost
if ans == 10**8:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
r = int(input())
print(3r^2)


Fixed submission:
r = int(input())
print(3*r*r)

Buggy python submission (verdict: Runtime Error):
r = int(input)
print(3r^2)

Fixed submission:
r = int(input())
print(3*r*r)
Buggy python submission (verdict: Runtime Error):
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
for i range(N):
  cop = arr.copy()
  del cop[i]
  print(max(cop))

Fixed submission:
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
max_inds = []
max_v = arr[0]
for i in range(N):
  if arr[i] > max_v:
    max_v = arr[i]
for i in range(N):
  if arr[i] == max_v:
    max_inds.append(i)
for i in range(N):
  if len(max_inds) >= 2:
    print(max_v)
  else:
    if i == max_inds[0]:
      cop = arr.copy()
      del cop[i]
      print(max(cop))
    else:
      print(max_v)

Buggy python submission (verdict: Runtime Error):
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
for i range(N):
  cop = arr.copy()
  del cop[i]
  cop.sort()
  print(cop[-1])

Fixed submission:
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
max_inds = []
max_v = arr[0]
for i in range(N):
  if arr[i] > max_v:
    max_v = arr[i]
for i in range(N):
  if arr[i] == max_v:
    max_inds.append(i)
for i in range(N):
  if len(max_inds) >= 2:
    print(max_v)
  else:
    if i == max_inds[0]:
      cop = arr.copy()
      del cop[i]
      print(max(cop))
    else:
      print(max_v)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
arr = [int(input()) for i in range(N)]
max_v= []

for v in arr:
  check = 0
  for i in range(len(max_v)):
    if max_v[i] < v:
      max_v[i] = v
      check = 1
      break
  if check == 0:
    max_v.append(v)
print(len(max_v))


Fixed submission:
import bisect
N = int(input())
arr = [int(input()) for i in range(N)]
dp = [-1 for _ in range(N)]
for i in arr:
    dp[bisect.bisect_left(dp, i) - 1] = i
print(sum([i >= 0 for i in dp]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
arr = [int(input()) for i in range(N)]
max_v= []
for v in arr:
  check = 0
  for i, k in enumerate(max_v):
    if k < v:
      max_v[i] = v
      check = 1
      break
  if check == 0:
    max_v.append(v)
print(len(max_v))


Fixed submission:
import bisect
N = int(input())
arr = [int(input()) for i in range(N)]
dp = [-1 for _ in range(N)]
for i in arr:
    dp[bisect.bisect_left(dp, i) - 1] = i
print(sum([i >= 0 for i in dp]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
arr = [int(input()) for i in range(N)]
c = 0
col_min = []

for i in range(N-1, -1, -1):
  if i == N-1:
    col_min.append(arr[i])
    c += 1
  else:
    check = 0
    for k, v in enumerate(col_min):
      if v > arr[i]
      	col_min[k] = arr[i]
        check = 1
        break
    if check == 0:
      col_min.append(arr[i])
      c += 1
print(c)

Fixed submission:
import bisect
N = int(input())
arr = [int(input()) for i in range(N)]
dp = [-1 for _ in range(N)]
for i in arr:
    dp[bisect.bisect_left(dp, i) - 1] = i
print(sum([i >= 0 for i in dp]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
arr = []
for i in range(N):
  arr.append(int(input()))
c = 0
col_min = []

for i in range(N-1, -1, -1):
  if i == N-1:
    col_min.append(arr[i])
    c += 1
  else:
    check = 0
    for k, v in enumerate(col_min):
      if v > arr[i]
      	col_min[k] = arr[i]
        check = 1
        break
    if check == 0:
      col_min.append(arr[i])
      c += 1
print(c)
        

Fixed submission:
import bisect
N = int(input())
arr = [int(input()) for i in range(N)]
dp = [-1 for _ in range(N)]
for i in arr:
    dp[bisect.bisect_left(dp, i) - 1] = i
print(sum([i >= 0 for i in dp]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
h_vals = input().split(' ')
hmax = -1
count = 0
for h in h_vals:
  if hmax <= h:
  	hmax = h
  	count+=1
print(count)


Fixed submission:
N = int(input())
h_vals = input().split(' ')
h_vals = [int(h) for h in h_vals]
hmax = -1
count = 0
for h in h_vals:
  if hmax <= h:
  	hmax = h
  	count+=1
print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
h_vals = input().split(' ')
hmax = -1
count = 0
for h in h_vals:
  if hmax <= h
  	hmax = h
  	count+=1
print(count)

Fixed submission:
N = int(input())
h_vals = input().split(' ')
h_vals = [int(h) for h in h_vals]
hmax = -1
count = 0
for h in h_vals:
  if hmax <= h:
  	hmax = h
  	count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
s=input()
n=len(s)
s = bin(int(s, 2))
s_10 = '1' * (n % 2) + '01' * (n // 2)
s_01 = '0' * (n % 2) + '10' * (n // 2)
s_10 = bin(int(s_10, 2))
s_01 = bin(int(s_01, 2))
r = s ^ s_01
l = s ^ s_10
print(min(r.count('1'), l.count('1')))

Fixed submission:
s=input()
n=len(s)
s = int(s, 2)
s_10 = '1' * (n % 2) + '01' * (n // 2)
s_01 = '0' * (n % 2) + '10' * (n // 2)
s_10 = int(s_10, 2)
s_01 = int(s_01, 2)
r = bin(s ^ s_01)
l = bin(s ^ s_10)
print(min(r.count('1'), l.count('1')))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
M = int(input())
A = np.array(list(map(int, input().split())))
Needed = np.sum(A)
if Needed > N:
    print(-1)
else:
    print(N - Needed)

Fixed submission:
import numpy as np

N = int(input().split()[0])
A = np.array(list(map(int, input().split())))
Needed = np.sum(A)
if Needed > N:
    print(-1)
else:
    print(N - Needed)

Buggy python submission (verdict: Runtime Error):
import numpy as np

tmp = np.array(list(map(int, input().split())))
N = tmp[0]
A = tmp[2:]

Needed = np.sum(A)

if Needed > N:
    print(-1)
else:
    print(N - Needed)

Fixed submission:
import numpy as np

N = int(input().split()[0])
A = np.array(list(map(int, input().split())))
Needed = np.sum(A)
if Needed > N:
    print(-1)
else:
    print(N - Needed)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros(N)
for a in A:
    ans[a-1] += 1
for o in ans:
    print(int(o))

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros(N)
for a in A:
    ans[a-1] += 1
for o in ans:
    print(int(o))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros(N)
for a in A:
    ans[a-1] += 1
for o in ans:
    print(int(o))

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros(N)
for a in A:
    ans[a-1] += 1
for o in ans:
    print(int(o))

Buggy python submission (verdict: Runtime Error):

N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros(N)
for a in A:
    ans[a-1] += 1
for o in ans:
    print(int(o))

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = np.zeros(N)
for a in A:
    ans[a-1] += 1
for o in ans:
    print(int(o))
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

Sum = 0
for l in range(k):
    for m in range(k):
        for n in range(k):
            Sum += gcd(l+1, m+1, n+1)
            
print(Sum)

Fixed submission:

k = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

Sum = 0

# 一種類の数字が出てくるパターン
for i in range(k):
    Sum += gcd(i+1, i+1, i+1)

# 二種類の数字が出てくる場合 -> 各パターンは3通りあるはず
for i in range(k-1):
    for j in range(i+1, k):
        Sum += gcd(i+1, j+1, j+1)*3

# 二種類の数字が出てくる場合 
for i in range(k-1):
    for j in range(i+1, k):
        Sum += gcd(i+1, i+1, j+1)*3
        
# 三種類の数字が出てくる場合
for i in range(k-2):
    for j in range(i+1, k-1):
        for m in range(j+1, k):
            Sum += gcd(i+1, j+1, m+1)*6
            
print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if j < k < n and s[i] != s[k] and s[j] != s[k]:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

Fixed submission:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if j < k < n and s[i] != s[k] and s[j] != s[k]:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())

r_idx = []
g_idx = []
b_idx = []

for i, s in enumerate(S):
  if s == "R":
    r_idx.append(i)
  elif s == "G":
    g_idx.append(i)
  elif s == "B":
    b_idx.append(i)
    
count = 0
for r in r_idx:
  for g in g_idx:
    for b in b_idx:
      if b==2*g-r or g==2*r-b or r==2*b-g:
        continue
      else:
        count += 1
        
print(count)

Fixed submission:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if j < k < n and s[i] != s[k] and s[j] != s[k]:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())

r_idx = set()
g_idx = set()
b_idx = set()

for i, s in enumerate(S):
    if s == "R":
        r_idx.add(i)
    elif s == "G":
        g_idx.add(i)
    elif s == "B":
        b_idx.add(i)

count = 0
if r_idx != set() and g_idx != set() and b_idx != set():
    for r in r_idx:
        for g in g_idx:
            for b in b_idx:
                if abs(g-r) != abs(g-b) and abs(r-b) != abs(g-b) and abs(r-g) != abs(r-b):
                    count += 1
                    
print(count)

Fixed submission:
n = int(input())
s = input()
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            continue
        k = 2*j - i
        if j < k < n and s[i] != s[k] and s[j] != s[k]:
            cnt += 1
print(s.count('R') * s.count('G') * s.count('B') - cnt)
Buggy python submission (verdict: Runtime Error):
import sys
s = sys.stdin.readline()
if (s== 'ABC'):
  sys.stdout('ARC')
else:
  sys.stdout('ABC')

Fixed submission:
s = input()
if (s=='ABC'):
    print('ARC')
else:
    print('ABC')

Buggy python submission (verdict: Runtime Error):
s = input()
if (s == 'ABC):
    print('ARC')
else:
    print('ABC')
    

Fixed submission:
s = input()
if (s=='ABC'):
    print('ARC')
else:
    print('ABC')
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    if l[a-1] >= l[b-1]:
        tmp[b-1]=-1
    if l[a-1] <= l[b-1]
        tmp[a-1]=-1

print(tmp.count(0))

Fixed submission:
n,m=map(int,input().split())
l=list(map(int,input().split()))
tmp=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    if l[a-1] >= l[b-1]:
        tmp[b-1]=-1
    if l[a-1] <= l[b-1]:
        tmp[a-1]=-1

print(tmp.count(0))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
l=list(combinations_with_replacement(range(1,m+1),n))

res=0
lt=[list(map(int,input().split())) for _ in range(q)]

for j in range(len(l)):
    tmp=0
    for i in range(len(lt)):
        a,b,c,d = lt[i][0],lt[i][1],lt[i][2],lt[i][3]
        if l[j][b-1]-l[j][a-1] == c:
            tmp += d
    res=max(tmp,res)

print(res)


Fixed submission:
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
l=list(combinations_with_replacement(range(1,m+1),n))

res=0
lt=[list(map(int,input().split())) for _ in range(q)]

for j in range(len(l)):
    tmp=0
    for i in range(len(lt)):
        a,b,c,d = lt[i][0],lt[i][1],lt[i][2],lt[i][3]
        if l[j][b-1]-l[j][a-1] == c:
            tmp += d
    res=max(tmp,res)

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            sum += math.gcd(math.gcd(l,m),n)

print(sum)

Fixed submission:
from fractions import gcd
k=int(input())
l=[]
dp=[[0]*(k+1) for i in range(k+1)]

for i in range(1,k+1):
    for j in range(1,k+1):
        dp[i][j]=gcd(i,j)
        l.append(gcd(i,j))
sum=0
for x in range(1,k+1):
    for y in range(len(l)):
        sum += int(dp[l[y]][x])
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k=int(input())
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            sum += gcd(gcd(l,m),n)

print(sum)

Fixed submission:
from fractions import gcd
k=int(input())
l=[]
dp=[[0]*(k+1) for i in range(k+1)]

for i in range(1,k+1):
    for j in range(1,k+1):
        dp[i][j]=gcd(i,j)
        l.append(gcd(i,j))
sum=0
for x in range(1,k+1):
    for y in range(len(l)):
        sum += int(dp[l[y]][x])
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k=int(input())
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        for n in range(1,k+1):
            sum += gcd(gcd(l,m),n)

print(sum)

Fixed submission:
from fractions import gcd
k=int(input())
l=[]
dp=[[0]*(k+1) for i in range(k+1)]

for i in range(1,k+1):
    for j in range(1,k+1):
        dp[i][j]=gcd(i,j)
        l.append(gcd(i,j))
sum=0
for x in range(1,k+1):
    for y in range(len(l)):
        sum += int(dp[l[y]][x])
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k=int(input())
r1=[]
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        r1.append(gcd(l,m))

for i in range(len(r1)):
    for j in range(1,k+1):
        sum += gcd(r1[i],j)
print(sum)



Fixed submission:
from fractions import gcd
k=int(input())
l=[]
dp=[[0]*(k+1) for i in range(k+1)]

for i in range(1,k+1):
    for j in range(1,k+1):
        dp[i][j]=gcd(i,j)
        l.append(gcd(i,j))
sum=0
for x in range(1,k+1):
    for y in range(len(l)):
        sum += int(dp[l[y]][x])
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k=int(input())
r1=[]
r2=[]
for l in range(1,k+1):
    for m in range(1,k+1):
        r1.append(gcd(l,m))

for i in range(len(r1)):
    for j in range(1,k+1):
        r2.append(gcd(r1[i],j))

print(sum(r2))

Fixed submission:
from fractions import gcd
k=int(input())
l=[]
dp=[[0]*(k+1) for i in range(k+1)]

for i in range(1,k+1):
    for j in range(1,k+1):
        dp[i][j]=gcd(i,j)
        l.append(gcd(i,j))
sum=0
for x in range(1,k+1):
    for y in range(len(l)):
        sum += int(dp[l[y]][x])
print(sum)