Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def dfs(v):
    for u, d in es[v]:
        if x[u] == None:
            x[u] = x[v] + d
            dfs(u)
        elif x[u] != x[v] + d:
            return False
    return True

N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for i in range(M):
    L, R, D = map(int, input().split())
    es[L].append((R, D))
    es[R].append((L, -D))
x = [None for i in range(N+1)]
flag = True
for v in range(1, N+1):
    if x[v] == None:
        x[v] = 0
        if dfs(v) == False:
            flag = False
            break
if flag:
    print("Yes")
else:
    print("No")


Fixed submission:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

def dfs(v):
    ret = True
    for u, d in es[v]:
        if x[u] == None:
            x[u] = x[v] + d
            ret = ret and dfs(u)
        elif x[u] != x[v] + d:
            return False
    return ret

N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for i in range(M):
    L, R, D = map(int, input().split())
    es[L].append((R, D))
    es[R].append((L, -D))
x = [None for i in range(N+1)]
flag = True
for v in range(1, N+1):
    if x[v] == None:
        x[v] = 0
        if dfs(v) == False:
            flag = False
            break
if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ans = 0
for i in range(n + 1):
  x = 0
  while i > 0:
    x += i % 10
    i //= 10
  if A <= x <= B:
    ans += 1
print(ans)


Fixed submission:
n, a, b = map(int, input().split())
ans = 0
for i in range(n + 1):
  x, j = 0, i
  while j > 0:
    x += j % 10
    j //= 10
  if a <= x <= b:
    ans += i
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ans = 0
for i in range(n + 1):
  x = sum(list(str(i)))
  if A <= x <= B:
    ans += 1
print(ans)

Fixed submission:
n, a, b = map(int, input().split())
ans = 0
for i in range(n + 1):
  x, j = 0, i
  while j > 0:
    x += j % 10
    j //= 10
  if a <= x <= b:
    ans += i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
_a = set(a)
for x in _a:
    y = a.count(x)
    if y < x:
        ans += y
    elif y > x:
        ans += y - x
print(ans)


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
c = Counter(a)
for key in c:
    if c[key] < key:
        ans += c[key]
    elif c[key] > key:
        ans += c[key] - key
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
_a = set(a)
for x in _a:
    y = a.count(x)
    if y < x:
        ans += y
    elif y > x:
        ans += y - x
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
c = Counter(a)
for key in c:
    if c[key] < key:
        ans += c[key]
    elif c[key] > key:
        ans += c[key] - key
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = list(map(int, input().split()))
ans = 0
f = 0
while 1:
  for x in lst:
    if x % 2:
      f = 1
    else:
      x /= 2
  if f:
    break
  ans += 1
print(ans)

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
ans = 1000000000
for x in lst:
  c = 0
  while x % 2 == 0:
    x //= 2
    c += 1
  if ans > c:
    ans = c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bs
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for a in A:
    _b = bs.bisect_right(B, a)
    for b in range(_b, N):
        ans += N - bs.bisect(C, B[b])
print(ans)

Fixed submission:
import bisect as bs
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
    a = bs.bisect_left(A, b)
    c = N - bs.bisect_right(C, b)
    ans += a * c
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
flag = False
for i in range(len(S) - len(T) + 1):
    k = i
    for j in range(len(T)):
        if S[k] == T[j] or S[k] == '?':
            k += 1
        else:
            break
    if k == i + len(T):
        flag = True
        st = i
        break
ret = ""
print(st)
if flag:
    for i in range(st):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
    ret += T
    for i in range(st + len(T), len(S)):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
else:
    ret = "UNRESTORABLE"
print(ret)

Fixed submission:
S = input()
T = input()
flag = False
for i in range(len(S)):
    k = len(S) - i - len(T)
    for j in range(len(T)):
        if k >= 0 and (S[k] == T[j] or S[k] == '?'):
            k += 1
            if j == len(T) - 1:
                flag = True
                st = len(S) - len(T) - i
        else:
            break
    if flag:
        break
ret = ""
if flag:
    for i in range(st):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
    ret += T
    for i in range(st + len(T), len(S)):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
else:
    ret = "UNRESTORABLE"
print(ret)
Buggy python submission (verdict: Runtime Error):
l = input().split()
for i in range(3):
  if l[i].count() == 1:
    print(l[i])

Fixed submission:
l = input().split()
for i in range(3):
  if l.count(l[i]) == 1:
    print(l[i])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
f = [input() for _ in range(h)]
for i in range(h):
  for j in range(w):
    if f[i][w] == '#':
      print('#', end = "")
      continue
    cnt = 0
    for k in range(i-1, i+2):
      if k < 0 or h <= k:
        continue
      for l in range(j-1, j+2):
        if l < 0 or w <= l:
          continue
        if f[k][l] == '#':
          cnt += 1
    print(cnt, end = "")
  print()
  

Fixed submission:
h, w = map(int, input().split())
f = [input() for _ in range(h)]
for i in range(h):
  for j in range(w):
    if f[i][j] == '#':
      print('#', end = "")
      continue
    cnt = 0
    for k in range(i-1, i+2):
      if k < 0 or h <= k:
        continue
      for l in range(j-1, j+2):
        if l < 0 or w <= l:
          continue
        if f[k][l] == '#':
          cnt += 1
    print(cnt, end = "")
  print()
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())
s = 0
for _ in range(n):
  x = int(input())
  s += min(x * 2, (k - x) * 2)
print(s)

Fixed submission:
n = int(input())
k = int(input())
s = 0
l = list(map(int, input().split()))
for _ in range(n):
  x = l[_]
  s += min(x * 2, (k - x) * 2)
print(s)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

import sys
input = sys.stdin.readline
N = int(input())
T = [int(input()) for _ in range(N)]
if N == 1:
    ans = T[0]
else:
    ans = lcm(T[0], T[1])
    for i in range(2, N):
    ans = lcm(ans, T[i])
print(ans)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

import sys
input = sys.stdin.readline
N = int(input())
if N == 1:
    print(input())
else:
    T = [int(input()) for _ in range(N)]
    ans = lcm(T[0], T[1])
    for i in range(2, N):
        ans = lcm(ans, T[i])
    print(ans)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

import sys
input = sys.stdin.readline
N = int(input())
T = [int(input()) for _ in range(N)]
ans = lcm(T[0], T[1])
for i in range(2, N):
    ans = lcm(ans, T[i])
print(ans)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

import sys
input = sys.stdin.readline
N = int(input())
if N == 1:
    print(input())
else:
    T = [int(input()) for _ in range(N)]
    ans = lcm(T[0], T[1])
    for i in range(2, N):
        ans = lcm(ans, T[i])
    print(ans)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, b % a)

import sys
input = sys.stdin.readline
N = int(input())
T = [int(input()) for _ in range(N)]
ans = T[0] * T[1] // gcd(T[0], T[1])
for i in range(2, N):
    ans = ans * T[i] // gcd(ans, T[i])
print(ans)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

import sys
input = sys.stdin.readline
N = int(input())
if N == 1:
    print(input())
else:
    T = [int(input()) for _ in range(N)]
    ans = lcm(T[0], T[1])
    for i in range(2, N):
        ans = lcm(ans, T[i])
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
from heapq import *

def dfs(s, es):
    dist = [None] * len(es)
    dist[s] = 0
    def ret(v, d):
        for u, c in es[v]:
            if dist[u] == None:
                dist[u] = dist[v] + c
                ret(u, dist[u])
    ret(s, 0)
    return dist

N = int(input())
es = [[] for i in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    es[a].append((b, c))
    es[b].append((a, c))
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(Q)]
dist = dfs(K, es)
for i in range(Q):
    print(dist[xy[i][0]] + dist[xy[i][1]])

Fixed submission:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
from heapq import *

INF = 10 ** 20
def dijkstra(s, edges):
    dist = [INF for _ in range(len(edges))]
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist

N = int(input())
es = [[] for i in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    es[a].append((b, c))
    es[b].append((a, c))
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(Q)]
dist = dijkstra(K, es)
for i in range(Q):
    print(dist[xy[i][0]] + dist[xy[i][1]])
Buggy python submission (verdict: Runtime Error):
n = int(input())
M = 0
for i in range(1, n + 1):
  t = i
  s = 0
  while t % 2 == 0:
    t /= 2
    s += 1
  if M < s:
    M = s
    ans = i
print(ans)

Fixed submission:
n = int(input())
M = 0
ans = 1
for i in range(1, n + 1):
  t = i
  s = 0
  while t % 2 == 0:
    t /= 2
    s += 1
  if M < s:
    M = s
    ans = i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def Dijkstra(N, edges, s):
    from heapq import heappush, heappop, heapify
    dist = [10**20 for _ in range(N)]
    dist[s], h = 0, [[0, s]]
    while (len(h)):
        p = heappop(h)
        d, v = p[0], p[1]
        if d > dist[v]:
            continue
        for i in range(len(edges[v])):
            u = edges[v][i]
            if d + 1 < dist[u]:
                dist[u] = d + 1
                heappush(h, [dist[u], u])
    return dist

N, M = map(int, input().split())
es = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    es[a].append(b)
    es[b].append(a)
dist = Dijkstra(N, es, 0)
if dist[N - 1] == 2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

def Dijkstra(N, edges, s):
    from heapq import heappush, heappop, heapify
    dist = [10**18 for _ in range(N)]
    dist[s], h = 0, [[0, s]]
    while (len(h)):
        p = heappop(h)
        d, v = p[0], p[1]
        if d > dist[v]:
            continue
        for i in range(len(edges[v])):
            u = edges[v][i]
            if d + 1 < dist[u]:
                dist[u] = d + 1
                heappush(h, [dist[u], u])
    return dist

N, M = map(int, input().split())
es = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    es[a].append(b)
    es[b].append(a)
dist = Dijkstra(N, es, 0)
if dist[N - 1] == 2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

def arc079():
    K = int(input())
    k = K//50
    a = [i+k*50 for i in range(50)]
    for i in range(K-k):
        a[i] += 51
    for i in range(50):
        a[i] -= K-k
    print(50)
    print(*a)

arc079()

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

def arc079():
    K = int(input())
    k = K//50
    a = [i+k*50 for i in range(50)]
    for i in range(K%50):
        a[i] += 51
    for i in range(50):
        a[i] -= K-k
    print(50)
    print(*a)

arc079()
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(a+b+c-max(a,b.c))

Fixed submission:
a,b,c=map(int,input().split())
print(a+b+c-max(a,b,c))
Buggy python submission (verdict: Runtime Error):
X, A, B = input().split()
if B <= A:
  print("delicious")
else:
  if B - A <= X:
    print("safe")
  else:
    print("dangerous")

Fixed submission:
X, A, B = map(int, input().split())
if B <= A:
  print("delicious")
else:
  if B - A <= X:
    print("safe")
  else:
    print("dangerous")
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
btn = [int(input()) for _ in range(N)]
i, ans = 0, 0
checked = defaultdict(int)
while 1:
  next = btn[i]
  ans += 1
  if next == 2:
    print(ans)
  	break
  if checked[next] == 1:
    print(-1)
    break
  i = next
  checked[i] = 1

Fixed submission:
from collections import defaultdict
N = int(input())
btn = [0] + [int(input()) for _ in range(N)]
i, ans = 1, 0
checked = defaultdict(int)
while 1:
  next = btn[i]
  ans += 1
  if next == 2:
    print(ans)
    break
  if checked[next] == 1:
    print(-1)
    break
  i = next
  checked[i] = 1
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
def Mod_Permutation(n, k, mod):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = ret * i % mod
    return ret
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(int(Mod_Permutation(N, N, MOD) * (2 * Mod_Permutation(N, M, MOD) % MOD) % MOD))
else:
    if N < M:
        swap(N, M)
    print(int(Mod_Permutation(N, N, MOD) * Mod_Permutation(M, M, MOD) % MOD))

Fixed submission:
MOD = 10**9 + 7
def Mod_Permutation(n, k, mod):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = ret * i % mod
    return ret
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(int(Mod_Permutation(N, N, MOD) * (2 * Mod_Permutation(N, M, MOD) % MOD) % MOD))
else:
    if N < M:
        T = N
        N = M
        M = T
    print(int(Mod_Permutation(N, N, MOD) * Mod_Permutation(M, M, MOD) % MOD))

Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
def Mod_Permutation(n, k, mod):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = ret * i % mod
    return ret
N, M = map(int, input().split())
print(Mod_Permutation(N, N, MOD) * P(N+1, M, MOD) % MOD)

Fixed submission:
MOD = 10**9 + 7
def Mod_Permutation(n, k, mod):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = ret * i % mod
    return ret
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(int(Mod_Permutation(N, N, MOD) * (2 * Mod_Permutation(N, M, MOD) % MOD) % MOD))
else:
    if N < M:
        T = N
        N = M
        M = T
    print(int(Mod_Permutation(N, N, MOD) * Mod_Permutation(M, M, MOD) % MOD))
Buggy python submission (verdict: Runtime Error):
s=input()
from collections import Counter
c=Counter(s)
if most_common(c)[0]>1:
  print("no")
else:
  print("yes")

Fixed submission:
s=input()
from collections import Counter
c=Counter(s)
if c.most_common()[0][1]>1:
  print("no")
else:
  print("yes")
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=['#'(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
for x in a:
  print(x)


Fixed submission:
h,w=map(int,input().split())
a=['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
for x in a:
  print(x)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
elif H % 2 and W % 2:
    ans = float("inf")
    for h in range(1, H):
        y = (H - h) * W
        x = h * (W // 2)
        z = h * W - x
        ans = min(ans, max(a, b, c) - min(a, b, c))
    print(ans)
else:
    if W % 2:
        t = H
        H = W
        W = t
    ans = float("inf")
    for h in range(1, H):
        x = h * W // 2
        y = W * (H - h)
        ans = min(ans, abs(y - x))
    print(ans)

Fixed submission:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    ans = min(H, W)
    for h in range(1, H):
        y = (H - h) * W
        x = h * (W // 2)
        z = h * W - x
        ans = min(ans, max(x, y, z) - min(x, y, z))
    t = H
    H = W
    W = t
    for h in range(1, H):
        y = (H - h) * W
        x = h * (W // 2)
        z = h * W - x
        ans = min(ans, max(x, y, z) - min(x, y, z))
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
es = [[] for _ in range(n)]
for _ in range(m):
  s, t = map(int, input().split())
  es[s].append(t)
  es[t].append(s)
for i in range(n):
  print(len(list(set(es[i]))))
  


Fixed submission:
n, m = map(int, input().split())
es = [[] for _ in range(n)]
for _ in range(m):
  s, t = map(int, input().split())
  es[s-1].append(t-1)
  es[t-1].append(s-1)
for i in range(n):
  print(len(es[i]))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, k = map(int, input().split())
dic = defaultdict(int)
for _ in range(n):
  a, b = map(int, input().split())
  dic[a] += b
dic = sorted(dic, key = lambda x: x[0])
cnt = 0
for key in dic:
  if cnt + dic[key] < k:
    cnt += dic[key]
  else:
    print(key)
    break
    

Fixed submission:
from collections import defaultdict
n, k = map(int, input().split())
dic = defaultdict(int)
for _ in range(n):
  a, b = map(int, input().split())
  dic[a] += b
cnt = 0
for key in sorted(dic):
  if cnt + dic[key] < k:
    cnt += dic[key]
  else:
    print(key)
    break
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if len(a)>len(b):
  print("GREATER")
elif len(a)<len(b):
  print("LESS")
else:
  i=0
  while 1:
    if int(a[i])>int(b[i]):
      f=1
      break
    elif int(a[i])<int(b[i]):
      f=2
      break
    i+=1
  if f==1:
    print("GREATER")
  else:
    print("LESS")


Fixed submission:
a=input()
b=input()
if len(a)>len(b):
  print("GREATER")
elif len(a)<len(b):
  print("LESS")
else:
  i=0
  f=0
  while len(a)>i:
    if int(a[i])>int(b[i]):
      f=1
      break
    elif int(a[i])<int(b[i]):
      f=2
      break
    i+=1
  if f==0:
    print("EQUAL")
  elif f==1:
    print("GREATER")
  else:
    print("LESS")

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if len(a)>len(b):
  print("GREATER")
elif len(a)<len(b):
  print("LESS")
else:
  i=0
  while 1:
    if int(a[i])>int(b[i]):
      f=1
    elif int(a[i]<int(b[i]):
      f=2
    i+=1
  if f==1:
    print("GREATER")
  else:
    print("LESS")


Fixed submission:
a=input()
b=input()
if len(a)>len(b):
  print("GREATER")
elif len(a)<len(b):
  print("LESS")
else:
  i=0
  f=0
  while len(a)>i:
    if int(a[i])>int(b[i]):
      f=1
      break
    elif int(a[i])<int(b[i]):
      f=2
      break
    i+=1
  if f==0:
    print("EQUAL")
  elif f==1:
    print("GREATER")
  else:
    print("LESS")
Buggy python submission (verdict: Runtime Error):
o=input()
e=input()
j,k=0,0
for i in range(len(o)+len(e)):
  if i %2:
    res+=e[k]
    k+=1
  else:
    res+=o[j]
    j+=1
print(res)

Fixed submission:
o=input()
e=input()
j,k,res=0,0,""
for i in range(len(o)+len(e)):
  if i %2:
    res+=e[k]
    k+=1
  else:
    res+=o[j]
    j+=1
print(res)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a_b=[list(map(int,input().split()) for _ in range(n)]
c_d=sorted([list(map(int,input().split()) for _ in range(m)])
for i in range(n):
  res=1
  d=abs(a_b[i][0]-c_d[0][0])+abs(a_b[i][1]-c_d[0][1])
  for j in range(m):
    t=abs(a_b[i][0]-c_d[j][0])+abs(a_b[i][1]-c_d[j][1])
    if t<d:
      d=t
      res=j+1
  print(res)
    
  

Fixed submission:
n,m=map(int,input().split())
a_b=[list(map(int,input().split())) for _ in range(n)]
c_d=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
  res=1
  d=abs(a_b[i][0]-c_d[0][0])+abs(a_b[i][1]-c_d[0][1])
  for j in range(1,m):
    t=abs(a_b[i][0]-c_d[j][0])+abs(a_b[i][1]-c_d[j][1])
    if t<d:
      d=t
      res=j+1
  print(res)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(0, M - N):
  for j in range(0, M - N):
    if A == B[i:i+N+1][j:j+N+1]:
      flag = True
    if flag:
      break
  if flag:
    break
if flag:
  print("Yes")
else:
  print("No")

Fixed submission:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False
for i in range(0, N - M + 1):
  for j in range(0, N - M + 1):
    if B == [x[j:j+M] for x in A[i:i+M]]:
      flag = True
    if flag:
      break
  if flag:
    break
if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from bisect import bisect_right
INF = float('inf')
N, Ma, Mb = map(int, input().split())
a, b, c = [None] * N, [None] * N, [None] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
hN = N // 2
dic1 = defaultdict(lambda : INF)
for i in range(1 << hN):
    _a, _b, _c = 0, 0, 0
    for j in range(hN):
        if (i >> j) & 1:
            _a += a[j]
            _b += b[j]
            _c += c[j]
    if _c < dic1[(_a, _b)]:
        dic1[(_a, _b)] = _c
dic2 = defaultdict(lambda : INF)
for i in range(1 << (N - hN)):
    _a, _b, _c = 0, 0, 0
    for j in range(N - hN):
        if (i >> j) & 1:
            _a += a[hN+j]
            _b += b[hN+j]
            _c += c[hN+j]
    if _c < dic2[(_a, _b)]:
        dic2[(_a, _b)] = _c
ans = INF
for k in dic1:
    _a, _b = k
    v = dic1[k]
    for i in range(1, N+1):
        ans = min(ans, v + dic2[(Ma*i-_a,Mb*i-_b)])
ans = ans if ans < INF else -1
print(ans)

Fixed submission:
from collections import defaultdict
N, Ma, Mb = map(int, input().split())
INF, MAX = 1000000000, 10 * N + 1
dp = defaultdict(lambda : INF)
dp[(0, 0)] = 0
for i in range(N):
    a, b, c = map(int, input().split())
    predp = dp.copy()
    for ab, v in predp.items():
        _a, _b = ab
        dp[(_a+a, _b+b)] = min(dp[(_a+a, _b+b)], v+c)
ans = INF
for i in range(1, N+1):
    ans = min(ans, dp[(Ma*i, Mb*i)])
ans = -1 if ans == INF else ans
print(ans)