Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
S = []
for i in range(H):
  S.append(str(input()))
  
def main(h, w, cnt):
  global H
  global W
  global S
  tmp = []
  if (h<H-1) and (S[h+1][w]=='.') and (ans[h+1][w]<0):
    ans[h+1][w] = cnt
    tmp.append([h+1, w])
  if (w<W-1) and (S[h][w+1]=='.') and (ans[h][w+1]<0):
    ans[h][w+1] = cnt
    tmp.append([h, w+1])
  if (0<h) and (S[h-1][w]=='.') and (ans[h-1][w]<0):
    ans[h-1][w] = cnt
    tmp.append([h-1, w])
  if (0<w) and (S[h][w-1]=='.') and (ans[h][w-1]<0):
    ans[h][w-1] = cnt
    tmp.append([h, w-1])
  return tmp

def sub(h, w, cnt):
  global H
  global W
  global S
  tmp = []
  for x in range(max(h-2, 0), min(h+3, H)):
    for y in range(max(w-2, 0), min(w+3, W)):
      if (S[x][y]=='.') and (ans[x][y]<0):
        ans[x][y] = cnt
        tmp.append([x, y])
  return tmp

ans = [[-1]*W for i in range(H)]
ans[ch-1][cw-1] = 0
lis = [[ch-1, cw-1]]
li = [[ch-1, cw-1]]
flag = False
for i in range(1000000):
  for j in range(1000000):
    l = []
    for n in li:
      l += main(n[0], n[1], i)
    if l == []:
      break
    elif [dh-1, dw-1] in l:
      flag = True
      break
    else:
      lis += l
      li = l
  if flag:
    break
  else:
    z = []
    for m in lis:
      z += sub(m[0], m[1], i+1)
    if z == []:
      break
    else:
      lis = z
      li = z
print(ans[dh-1][dw-1])

Fixed submission:
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
S = []
for i in range(H):
  S.append(str(input()))
  
def main(h, w, cnt):
  global H
  global W
  global S
  tmp = []
  if (h<H-1) and (S[h+1][w]=='.') and (ans[h+1][w]<0):
    ans[h+1][w] = cnt
    tmp.append([h+1, w])
  if (w<W-1) and (S[h][w+1]=='.') and (ans[h][w+1]<0):
    ans[h][w+1] = cnt
    tmp.append([h, w+1])
  if (0<h) and (S[h-1][w]=='.') and (ans[h-1][w]<0):
    ans[h-1][w] = cnt
    tmp.append([h-1, w])
  if (0<w) and (S[h][w-1]=='.') and (ans[h][w-1]<0):
    ans[h][w-1] = cnt
    tmp.append([h, w-1])
  return tmp

def sub(h, w, cnt):
  global H
  global W
  global S
  tmp = []
  for x in range(max(h-2, 0), min(h+3, H)):
    for y in range(max(w-2, 0), min(w+3, W)):
      if (S[x][y]=='.') and (ans[x][y]<0):
        ans[x][y] = cnt
        tmp.append([x, y])
  return tmp

ans = [[-1]*W for i in range(H)]
ans[ch-1][cw-1] = 0
lis = [[ch-1, cw-1]]
li = [[ch-1, cw-1]]
flag = False
for i in range(1000000):
  for j in range(1000000):
    l = []
    for n in li:
      l += main(n[0], n[1], i)
    if l == []:
      break
    elif [dh-1, dw-1] in l:
      flag = True
      break
    else:
      lis += l
      li = l
  if flag:
    break
  else:
    z = []
    for m in lis:
      z += sub(m[0], m[1], i+1)
    if z == []:
      break
    else:
      lis = z
      li = z
print(ans[dh-1][dw-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

mx = [0] * N
cnts = [0] * N
for i in range(N):
  if mx[i] == 0:
    nxt = P[i]-1
    tmp = 0
    l = [nxt]
    for j in range(N):
      tmp += C[nxt]
      nxt = P[nxt]-1
      l.append(nxt)
      if nxt == i:
        tmp += C[nxt]
        cnt = j+2
        break
    for k in l:
      cnts[k] = cnt
      n = ((K//cnt)-1) * tmp
      if tmp > 0:
        mx[k] += n
    
for i in range(N):
  nxt = P[i]-1
  tmp = 0
  m = min(C) - 1
  for j in range((K%cnts[i])+cnts[i]):
    tmp += C[nxt]
    m = max(m, tmp)
    nxt = P[nxt]-1
  mx[i] += m

ans = max(mx)
print(ans)

Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

mx = [0] * N
cnts = [0] * N
for i in range(N):
  if mx[i] == 0:
    nxt = P[i]-1
    tmp = 0
    l = [nxt]
    for j in range(N):
      tmp += C[nxt]
      nxt = P[nxt]-1
      l.append(nxt)
      if nxt == i:
        tmp += C[nxt]
        cnt = j+2
        break
    for k in l:
      cnts[k] = cnt
      n = ((K//cnt)-1) * tmp
      if tmp > 0:
        mx[k] += n
    
for i in range(N):
  nxt = P[i]-1
  tmp = 0
  m = min(C) - 1
  for j in range((K%cnts[i])+cnts[i]):
    tmp += C[nxt]
    m = max(m, tmp)
    nxt = P[nxt]-1
  mx[i] += m

ans = max(mx)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

loop = [0] * N
cnts = [0] * N
for i in range(N):
  nxt = P[i]-1
  tmp = 0
  for j in range(N):
    tmp += C[nxt]
    nxt = P[nxt]-1
    if nxt == i:
      tmp += C[nxt]
      cnt = j+2
      break
  loop[i] = tmp
  cnts[i] = cnt

mx = [0] * N
for i in range(N):
  if loop[i] > 0:
    mx[i] += ((K//cnts[i])-1) * loop[i]
    
for i in range(N):
  nxt = P[i]-1
  tmp = 0
  m = min(C) - 1
  for j in range((K%cnts[i])+cnts[i]):
    tmp += C[nxt]
    m = max(m, tmp)
    nxt = P[nxt]-1
  mx[i] += m

ans = max(mx)
print(ans)

Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

mx = [0] * N
cnts = [0] * N
for i in range(N):
  if mx[i] == 0:
    nxt = P[i]-1
    tmp = 0
    l = [nxt]
    for j in range(N):
      tmp += C[nxt]
      nxt = P[nxt]-1
      l.append(nxt)
      if nxt == i:
        tmp += C[nxt]
        cnt = j+2
        break
    for k in l:
      cnts[k] = cnt
      n = ((K//cnt)-1) * tmp
      if tmp > 0:
        mx[k] += n
    
for i in range(N):
  nxt = P[i]-1
  tmp = 0
  m = min(C) - 1
  for j in range((K%cnts[i])+cnts[i]):
    tmp += C[nxt]
    m = max(m, tmp)
    nxt = P[nxt]-1
  mx[i] += m

ans = max(mx)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

def doku(li, K, time):
  cnt = 0
  for i in range(len(li)):
    if time+li[0] <= K:
      time += li[0]
      li.popleft()
      cnt += 1
    else:
      return cnt
  return cnt

ans = 0
time = 0
while time+min(A[0], B[0]) <= K:
  plus = min(A[0], B[0])
  time += plus
  ans += 1
  if A[0] == B[0]:
    if A[1] < B[1]:
      A.popleft()
      if not A:
        ans += doku(B, K, time)
        break;
    else:
      B.popleft()
      if not B:
        ans += doku(A, K, time)
        break;
  elif A[0] < B[0]:
    A.popleft()
    if not A:
      ans += doku(B, K, time)
      break;
  else:
    B.popleft()
    if not B:
      ans += doku(A, K, time)
      break;
    
print(ans)

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

a = [0]
b = [0]
for i in range(N):
  a.append(A[i] + a[i])
for i in range(M):
  b.append(B[i] + b[i])
  
ans = 0
j = M
for i in range(N+1):
  if a[i] > K:
    break;
  while b[j] > K-a[i]:
    j -= 1
  ans = max(ans, i+j)
  
print(ans)

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

def doku(li, K, time):
  cnt = 0
  tmp = 0
  for i in range(len(li)):
    if time+li[i] <= K:
      tmp += li[i]
      cnt += 1
    else:
      return cnt
  return cnt

ans = 0
time = 0
while time+min(A[0], B[0]) <= K:
  plus = min(A[0], B[0])
  time += plus
  ans += 1
  if A[0] <= B[0]:
    A.pop(0)
    if not A:
      ans += doku(B, K, time)
      print('A')
      break;
  else:
    B.pop(0)
    if not B:
      ans += doku(A, K, time)
      print('B')
      break;
  print(A, B, time, ans)
    
print(ans)

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

a = [0]
b = [0]
for i in range(N):
  a.append(A[i] + a[i])
for i in range(M):
  b.append(B[i] + b[i])
  
ans = 0
j = M
for i in range(N+1):
  if a[i] > K:
    break;
  while b[j] > K-a[i]:
    j -= 1
  ans = max(ans, i+j)
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def num_divisors_table(n):
  table = [0] * (n + 1)
  for i in range(1, n + 1):
    for j in range(i, n + 1, i):
      table[j] += j
  return sum(table)

print(num_divisors_table(N))

Fixed submission:
N = int(input())

def num_divisors_table(n):
  table = [0] * (n + 1)
  for i in range(1, n + 1):
    for j in range(i, n + 1, i):
      table[j] += j
  return sum(table)

print(num_divisors_table(N))

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

ans = 0
for i in range(n):
  ans += i*sympy.divisor_count(i)
print(ans)

Fixed submission:
N = int(input())

def num_divisors_table(n):
  table = [0] * (n + 1)
  for i in range(1, n + 1):
    for j in range(i, n + 1, i):
      table[j] += j
  return sum(table)

print(num_divisors_table(N))

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
ans = 0

def division(n):
  cnt = 0
  for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
      cnt += 1
  cnt *= 2
  if n % math.sqrt(n) == 0:
    cnt -= 1
  return cnt

for i in range(1, N+1):
  ans += i * division(i)
  
print(ans)

Fixed submission:
N = int(input())

def num_divisors_table(n):
  table = [0] * (n + 1)
  for i in range(1, n + 1):
    for j in range(i, n + 1, i):
      table[j] += j
  return sum(table)

print(num_divisors_table(N))

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
ans = 0

def division(n):
  cnt = 0
  for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
      cnt += 1
  cnt *= 2
  if n % math.sqrt(n) == 0:
    cnt -= 1
  return cnt

for i in range(1, N+1):
  ans += i * division(i)
  
print(ans)

Fixed submission:
N = int(input())

def num_divisors_table(n):
  table = [0] * (n + 1)
  for i in range(1, n + 1):
    for j in range(i, n + 1, i):
      table[j] += j
  return sum(table)

print(num_divisors_table(N))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
for i in range(Q):
  b,c = map(int, input().split())
  cnt = A.count(b)
  for i in range(cnt):
    A.remove(b)
    A.append(c)
  ans += (c-b) * cnt
  print(ans)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
C = Counter(A)

for i in range(Q):
  b, c = map(int, input().split())
  if C[b] != 0:
    cnt = C[b]
    C[c] += cnt
    C[b] = 0
    ans += (c-b) * cnt
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
for i in range(Q):
  b,c = map(int, input().split())
  cnt = 0
  while b in A:
    A.remove(b)
    A.append(c)
    cnt += 1
  ans += (c-b) * cnt
  print(ans)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
C = Counter(A)

for i in range(Q):
  b, c = map(int, input().split())
  if C[b] != 0:
    cnt = C[b]
    C[c] += cnt
    C[b] = 0
    ans += (c-b) * cnt
  print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
for i in Q:
  b,c = map(int, input().split())
  cnt = 0
  while b in A:
    A.remove(b)
    A.append(c)
    cnt += 1
  ans += (c-b) * cnt
  
print(ans)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
C = Counter(A)

for i in range(Q):
  b, c = map(int, input().split())
  if C[b] != 0:
    cnt = C[b]
    C[c] += cnt
    C[b] = 0
    ans += (c-b) * cnt
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
minus = []
for i in c.items():
  if i[1] > 1:
    minus.append(i[0])

flag = True
A = sorted(set(A))
i = 0
j = len(A)-1

while i < j:
  if A[j] % A[i] == 0:
    A.pop(j)
  j -= 1
  if j == i:
    j = len(A)-1
    i += 1
  
cnt = 0
for n in minus:
  if n in A:
    cnt += 1
ans = len(A) - cnt
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
l = max(A)+1
li = [0]*(l)
A.sort()

for a in A:
  if li[a] == 0:
    li[a] = 1
    for i in range(a*2, l, a):
      li[i] = 2
  elif li[a] == 1:
    li[a] = 2
print(li.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
minus = []
for i in c.items():
  if i[1] > 1:
    minus.append(i[0])

flag = True
A = sorted(set(A))
i = 0
j = len(A)-1

while i < j:
  if A[j] % A[i] == 0:
    A.pop(j)
  j -= 1
  if j == i:
    j = len(A)-1
    i += 1
  
cnt = 0
for n in minus:
  if n in A:
    cnt += 1
ans = len(A) - cnt
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
l = max(A)+1
li = [0]*(l)
A.sort()

for a in A:
  if li[a] == 0:
    li[a] = 1
    for i in range(a*2, l, a):
      li[i] = 2
  elif li[a] == 1:
    li[a] = 2
print(li.count(1))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
A = [i[0] for i in c.items() if i[1] == 1]

A.sort()
ans = 0
i = 0
j = len(A)-1

while A:
  if A[j] % A[i] == 0:
    A.pop(j)
  j -= 1
  if j == i:
    ans += 1
    j = int(len(A)-1)
    i += 1
  if j == i:
    ans += 1
    break;

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
l = max(A)+1
li = [0]*(l)
A.sort()

for a in A:
  if li[a] == 0:
    li[a] = 1
    for i in range(a*2, l, a):
      li[i] = 2
  elif li[a] == 1:
    li[a] = 2
print(li.count(1))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

A.sort()
ans = 0
i = 0
j = N-1

c = Counter(A)
A = [i[0] for i in c.items() if i[1] == 1]

while A:
  if A[j] % A[i] == 0:
    A.pop(j)
  j -= 1
  if j == i:
    ans += 1
    j = int(len(A)-1)
    i += 1
  if j == i:
    ans += 1
    break;

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
l = max(A)+1
li = [0]*(l)
A.sort()

for a in A:
  if li[a] == 0:
    li[a] = 1
    for i in range(a*2, l, a):
      li[i] = 2
  elif li[a] == 1:
    li[a] = 2
print(li.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
N = int(input())
A = list(map(int, input().split()))

ans = functools.reduce(operator.mul, A)
    
if len(str(ans)) < 19:
  print(ans)
elif ans == 1000000000000000000:
  print(ans)
else:
  print(-1)

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

def main(A):
  if 0 in A:
    print(0)
    return
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
    
main(A)

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
N = int(input())
A = list(map(int, input().split()))

ans = functools.reduce(operator.mul, A)
    
if ans <= 10**18:
  print(ans)
else:
  print(-1)


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

def main(A):
  if 0 in A:
    print(0)
    return
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
    
main(A)

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

ans = 1
for i in range(N):
  ans *= A[i]
    
if ans <= 10**18:
  print(ans)
else:
  print(-1)

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

def main(A):
  if 0 in A:
    print(0)
    return
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
    
main(A)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
was = []
place = 1
cnt = 0

while place not in was:
  if cnt < K:
    was.append(place)
    place = A[place-1]
    cnt += 1
  else:
    print(place)
    break;
else:
  loop = cnt - was.index(place)
  num = (K-cnt) % loop + was.index(place)
  print(was[num])

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
was = []
tf = [False] * N
place = 1
cnt = 0

while tf[place-1] == False:
  if cnt < K:
    tf[place-1] = True
    was.append(place)
    place = A[place-1]
    cnt += 1
  else:
    print(place)
    break;
else:
  loop = cnt - was.index(place)
  num = (K-cnt) % loop + was.index(place)
  print(was[num])

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

num = 1
l = []
l.append(num)
for i in range(K):
  num = A[num-1]
  if num not in l:
    l.append(num)
  else:
    mod = (K-1-i) % (i+1-(l.index(num)))
    break;
    
for i in range(mod):
  num = A[num-1]
  
print(num)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
was = []
tf = [False] * N
place = 1
cnt = 0

while tf[place-1] == False:
  if cnt < K:
    tf[place-1] = True
    was.append(place)
    place = A[place-1]
    cnt += 1
  else:
    print(place)
    break;
else:
  loop = cnt - was.index(place)
  num = (K-cnt) % loop + was.index(place)
  print(was[num])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

num = 1
l = []
l.append(num)
i = 0
while i < K:
  num = A[num-1]
  if num not in l:
    l.append(num)
    i += 1
  else:
    i = K - (K-1-i)%(i+1-(l.index(num)))
    break;
    
while i < K:
  num = A[num-1]
  i += 1
  
print(num)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
was = []
tf = [False] * N
place = 1
cnt = 0

while tf[place-1] == False:
  if cnt < K:
    tf[place-1] = True
    was.append(place)
    place = A[place-1]
    cnt += 1
  else:
    print(place)
    break;
else:
  loop = cnt - was.index(place)
  num = (K-cnt) % loop + was.index(place)
  print(was[num])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

num = 1
l = []
l.append(num)
i = 0
while i < K:
  num = A[num-1]
  if num not in l:
    l.append(num)
    i += 1
  else:
    i = K - (K-1-i)%(i+1-(l.index(num)))
    break;
    
while i < K:
  num = A[num-1]
  i += 1
  
print(num)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
was = []
tf = [False] * N
place = 1
cnt = 0

while tf[place-1] == False:
  if cnt < K:
    tf[place-1] = True
    was.append(place)
    place = A[place-1]
    cnt += 1
  else:
    print(place)
    break;
else:
  loop = cnt - was.index(place)
  num = (K-cnt) % loop + was.index(place)
  print(was[num])
Buggy python submission (verdict: Runtime Error):
X = int(input())
plus = [i**5 for i in range(100)]

for num in plus:
  if abs(X - num) in plus:
    break
    
if (X - num) in plus:
  print(plus.index(num), -1*plus.index(X-num))
else:
  print(plus.index(num), plus.index(num-X))

Fixed submission:
X = int(input())
plus = [i**5 for i in range(1000)]

for num in plus:
  if abs(X - num) in plus:
    break
    
if (X - num) in plus:
  print(plus.index(num), -1*plus.index(X-num))
else:
  print(plus.index(num), plus.index(num-X))
Buggy python submission (verdict: Runtime Error):
import itertools
N, M ,Q = map(int, input().split())
l = []
for i in range(Q):
  a, b, c, d = map(int, input().split())
  l.append([a, b, c, d])
  
num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
nums = list(itertools.combinations_with_replacement(num, 10))
scores = []
for row in nums:
  score = 0
  i = 0
  while i < Q:
    if row[l[i][1]]-row[l[i][0]] == l[i][2]:
      score += l[i][3]
    i += 1
  scores.append(score)
  
print(max(scores))

Fixed submission:
import itertools
N, M ,Q = map(int, input().split())
l = []
for i in range(Q):
  a, b, c, d = map(int, input().split())
  l.append([a, b, c, d])
  
nums = list(itertools.combinations_with_replacement(range(1, M+1), N))
scores = []
for row in nums:
  score = 0
  i = 0
  while i < Q:
    if row[l[i][1]-1]-row[l[i][0]-1] == l[i][2]:
      score += l[i][3]
    i += 1
  scores.append(score)
  
print(max(scores))

Buggy python submission (verdict: Runtime Error):
import itertools
N, M ,Q = map(int, input().split())
l = []
for i in range(Q):
  a, b, c, d = map(int, input().split())
  l.append([a, b, c, d])
  
num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
nums = list(itertools.combinations_with_replacement(nums, 10))
scores = []
for row in nums:
  score = 0
  i = 0
  while i < Q:
    if row[l[i][1]]-row[l[i][0]] == l[i][2]:
      score += l[i][3]
    i += 1
  scores.append(score)
  
print(max(scores))

Fixed submission:
import itertools
N, M ,Q = map(int, input().split())
l = []
for i in range(Q):
  a, b, c, d = map(int, input().split())
  l.append([a, b, c, d])
  
nums = list(itertools.combinations_with_replacement(range(1, M+1), N))
scores = []
for row in nums:
  score = 0
  i = 0
  while i < Q:
    if row[l[i][1]-1]-row[l[i][0]-1] == l[i][2]:
      score += l[i][3]
    i += 1
  scores.append(score)
  
print(max(scores))
Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B, N = map(int, input().split())

l = []
for i in range(1, N+1):
  l.append((A*i//B) - A*(i//B))
    
print(max(l))

Fixed submission:
import math
A, B, N = map(int, input().split())

i = min(B-1, N)
ans = (A*i//B) - A*(i//B)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B, N = map(int, input().split())

ans = 0
for i in range(1, N+1):
  if ans < (math.floor(A*i/B) - A*math.floor(i/B)):
    ans = math.floor(A*i/B) - A*math.floor(i/B)
    
print(ans)

Fixed submission:
import math
A, B, N = map(int, input().split())

i = min(B-1, N)
ans = (A*i//B) - A*(i//B)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N) if input() not in S]
  
print(len(S))


Fixed submission:
N = int(input())
S = []
for i in range(N):
  S.append(input())

print(len(set(S)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for i in range(N):
  moji = input()
  if moji not in S:
    S.append(moji)
  
print(len(S))


Fixed submission:
N = int(input())
S = []
for i in range(N):
  S.append(input())

print(len(set(S)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for i in range(N):
  moji = input()
  if moji not in S:
    S.append(moji)
  
print(len(S))

Fixed submission:
N = int(input())
S = []
for i in range(N):
  S.append(input())

print(len(set(S)))