Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [-1] * (n + 1)
def dfs(now):
    if dp[now] != -1:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [-1] * (n + 1)
def dfs(now):
    if dp[now] != -1:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [None] * (n + 1)
def dfs(now):
    if dp[now] is not None:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [-1] * (n + 1)
def dfs(now):
    if dp[now] != -1:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [None] * (n + 1)
def dfs(now):
    if dp[now] is not None:
        return dp[now]

    if not graph[now]:
        return 0

    return max(dfs(parent) for parent in graph[now]) + 1

print(max(dfs(i) for i in range(1, n + 1)))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for _ in range(n + 1)]

for i in range(m):
    f, t = map(int, input().split())
    graph[t].append(f)

dp = [-1] * (n + 1)
def dfs(now):
    if dp[now] != -1:
        return dp[now]

    if not graph[now]:
        return 0

    r = max(dfs(parent) for parent in graph[now]) + 1
    dp[now] = r
    return r

print(max(dfs(i) for i in range(1, n + 1)))
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

field = [list(input()) for _ in range(h)]

dp = [[None] * w for _ in range(h)]
def dfs(hindex=h - 1, windex=w - 1):
    if field[hindex][windex] == "#":
        return 0
    if hindex == windex == 0:
        return 1

    if dp[hindex][windex] is not None:
        return dp[hindex][windex]
    r = (hindex and dfs(hindex - 1, windex)) + (windex and dfs(hindex, windex - 1))
    dp[hindex][windex] = r
    return r

print(dfs() % (10**9 + 7))


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
h, w = map(int, input().split())

field = [list(input()) for _ in range(h)]

dp = [[None] * w for _ in range(h)]
def dfs(hindex=h - 1, windex=w - 1):
    if field[hindex][windex] == "#":
        return 0
    if hindex == windex == 0:
        return 1

    if dp[hindex][windex] is not None:
        return dp[hindex][windex]
    r = (hindex and dfs(hindex - 1, windex)) + (windex and dfs(hindex, windex - 1))
    dp[hindex][windex] = r
    return r

print(dfs() % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)];

# import numpy as np
# n = 50
# k = 50
# a = np.random.randint(0, 2, size=(n, n))

graph = [[] for _ in range(n)]
for i, row in enumerate(a):
    for j, value in enumerate(row):
        if value:
            graph[i].append(j)

# dp = [[None] * (k + 1) for _ in range(n)]
# def dfs(i, at=k):
#     if dp[i][at] is not None:
#         return dp[i][at]
#     if at == 1:
#         r = len(graph[i])
#         dp[i][at] = r
#         return dp[i][at]
#
#     cnt = 0
#     for nxt in graph[i]:
#         cnt += dfs(nxt, at - 1)
#     dp[i][at] = cnt
#     return cnt
#
# print([dfs(i, at=k) for i in range(n)])
#
# for v in dp:
#     print(v)

# -------
import numpy as np
a = np.array(a)

M = 10**9 + 7
def powmod(a, n):
    if n == 0:
        return np.eye(np.alen(a), dtype=int)
    if n % 2:
        return (powmod(a, n - 1) @ a) % M
    r = powmod(a, n // 2)
    return (r @ r) % M

print(powmod(a, k).sum() % M)

# v = a
# for _ in range(k - 1):
#     v = v @ a
# print(v)


Fixed submission:
n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)];

import numpy as np
# n = 30
# k = 100
# np.random.seed(100)
# a = np.random.randint(0, 2, size=(n, n))

graph = [[] for _ in range(n)]
for i, row in enumerate(a):
    for j, value in enumerate(row):
        if value:
            graph[i].append(j)

# dp = [[None] * (k + 1) for _ in range(n)]
# def dfs(i, at=k):
#     if dp[i][at] is not None:
#         return dp[i][at]
#     if at == 1:
#         r = len(graph[i])
#         dp[i][at] = r
#         return dp[i][at]
#
#     cnt = 0
#     for nxt in graph[i]:
#         cnt += dfs(nxt, at - 1)
#     dp[i][at] = cnt
#     return cnt
#
# print([dfs(i, at=k) for i in range(n)])
#
# for v in dp:
#     print(v)

# -------
import numpy as np
a = np.array(a, dtype=int)

M = 10**9 + 7
def powmod(a, n):
    if n == 0:
        return np.eye(np.alen(a), dtype=int)
    if n % 2:
        return (powmod(a, n - 1).dot(a)) % M
    r = powmod(a, n // 2)

    calc = []
    for row in r.T:
        calc.append(((row * r) % M).sum(axis=-1))
    return np.array(calc).T % M

print(powmod(a, k).sum() % M)
#
# v = a
# for _ in range(k - 1):
#     v = (v @ a) % M
# print(v.sum() % M)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
a = [int(input()) for x in range(n)]
a.sort()
a = np.array(a)
print(np.min(a[k - 1:] - a[:k]))


Fixed submission:
import numpy as np
n, k = map(int, input().split())
a = [int(input()) for x in range(n)]
a.sort()
a = np.array(a)
print(np.min(a[k - 1:] - a[:n - k + 1]))
Buggy python submission (verdict: Runtime Error):
print("YES" input() in "753" else "NO")

Fixed submission:
print("YES" if input() in "753" else "NO")
Buggy python submission (verdict: Runtime Error):
import math
n, m = map(int, input().split())
ns = input()
ms = input()

# n, m = 10**5, 31111
# print(math.gcd(n, m))

gcd = math.gcd(n, m)
lcm = n * m // gcd
# print(lcm, lcm // n, lcm // m)
lcmN = lcm // n
lcmM = lcm // m

# for i in range(lcm):
#     if (i % (lcmN)) == 0:
#         print(ns[i // lcmN], end="")
#     else:
#         print(".", end="")
# print()
# for i in range(lcm):
#     if (i % (lcmM)) == 0:
#         print(ms[i // lcmM], end="")
#     else:
#         print(".", end="")

s = []
for i in range(0, n, lcmM):
    s.append(ns[i])
for i in range(0, m, lcmN):
    if ms[i] != s[i // lcmN]:
        print(-1)
        exit()
print(lcm)


Fixed submission:
import fractions
n, m = map(int, input().split())
ns = input()
ms = input()

# n, m = 10**5, 31111
# print(math.gcd(n, m))

gcd = fractions.gcd(n, m)
lcm = n * m // gcd
# print(lcm, lcm // n, lcm // m)
lcmN = lcm // n
lcmM = lcm // m

# for i in range(lcm):
#     if (i % (lcmN)) == 0:
#         print(ns[i // lcmN], end="")
#     else:
#         print(".", end="")
# print()
# for i in range(lcm):
#     if (i % (lcmM)) == 0:
#         print(ms[i // lcmM], end="")
#     else:
#         print(".", end="")

s = []
for i in range(0, n, lcmM):
    s.append(ns[i])
for i in range(0, m, lcmN):
    if ms[i] != s[i // lcmN]:
        print(-1)
        exit()
print(lcm)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
if n == 1: print(m)
else: print(max(i for i in range(2, 100050) if m % i == 0 and m / i >= n))


Fixed submission:
n, m = map(int, input().split())
values = []

def pfac(n):
    values = [1, n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            values.append(i)
            values.append(n // i)
    return values


for i in pfac(m):
    if m % i == 0 and m / i >= n:
        values.append(i)
print(max(values))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
print(max(i for i in range(2, 100000) if m % i == 0 and m / i >= n))

Fixed submission:
n, m = map(int, input().split())
values = []

def pfac(n):
    values = [1, n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            values.append(i)
            values.append(n // i)
    return values


for i in pfac(m):
    if m % i == 0 and m / i >= n:
        values.append(i)
print(max(values))
Buggy python submission (verdict: Runtime Error):
a = input()
for i in a:
    print(i == "1" and "9" or "1" end="")


Fixed submission:
print(1110 - int(input()))
Buggy python submission (verdict: Runtime Error):
prin

Fixed submission:
a = list(map(int, input().split()))
print(max(a) * 9 + sum(a))
Buggy python submission (verdict: Runtime Error):
import numpy as np
a = np.array(list(map(int, input().split())))
p1, p2 = a[:2], a[2:]

h1, h2 = p2 - p1
print(*(p2 + [-h2, h1]), *(p1 + [-h2, h1]))


Fixed submission:
import numpy as np
a = list(map(int, input().split()))
p1, p2 = a[:2], a[2:]

h1, h2 = p2[0] - p1[0], p2[1] - p1[1]
print(p2[0] - h2, p2[1] + h1, p1[0] - h2, p1[1] + h1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
a = np.array(list(map(int, input().split())))
p1, p2 = a[:2], a[2:]

h1, h2 = p2 - p1
print(*p2 + [-h2, h1], *p1 + [-h2, h1])


Fixed submission:
import numpy as np
a = list(map(int, input().split()))
p1, p2 = a[:2], a[2:]

h1, h2 = p2[0] - p1[0], p2[1] - p1[1]
print(p2[0] - h2, p2[1] + h1, p1[0] - h2, p1[1] + h1)

Buggy python submission (verdict: Runtime Error):
import numpy as np
a = np.array(list(map(int, input().split())))
p1, p2 = np.split(a, 2)

h1, h2 = p2 - p1
print(*p2 + [-h2, h1], *p1 + [-h2, h1])


Fixed submission:
import numpy as np
a = list(map(int, input().split()))
p1, p2 = a[:2], a[2:]

h1, h2 = p2[0] - p1[0], p2[1] - p1[1]
print(p2[0] - h2, p2[1] + h1, p1[0] - h2, p1[1] + h1)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())


for i, v in enumerate(s):
    if v != "1":
        break
after = "1" * i + v * 100
print(after[min(len(s), k)])


Fixed submission:
s = input()
k = int(input())

import random
for i, v in enumerate(s):
    if v != "1":
        break
after = "1" * i + v * 100
print(after[min(len(s), k) - 1])
Buggy python submission (verdict: Runtime Error):
import re
s = input()
ci = s.index("C")
if s.index("A") == 0 and 2 <= ci < len(s) - 2:
  tmp = list(s)
  del tmp[0]
  del tmp[ci - 1]
  if re.match("^[a-z]*$", "".join(tmp)):
    print("AC")
    exit()
print("WA")

Fixed submission:
import re
s = input()
ci = s.find("C")
if s.find("A") == 0 and 2 <= ci <= len(s) - 2:
  tmp = list(s)
  del tmp[0]
  del tmp[ci - 1]
  if re.match("^[a-z]*$", "".join(tmp)):
    print("AC")
    exit()
print("WA")

Buggy python submission (verdict: Runtime Error):
import re
s = input()
ci = s.index("C")
if s.index("A") == 0 and 2 <= ci < len(s) - 2:
  tmp = list(s)
  del tmp[0]
  del tmp[ci]
  if re.match("^[a-z]*$", "".join(tmp)):
    print("AC")
    exit()
print("WA")

Fixed submission:
import re
s = input()
ci = s.find("C")
if s.find("A") == 0 and 2 <= ci <= len(s) - 2:
  tmp = list(s)
  del tmp[0]
  del tmp[ci - 1]
  if re.match("^[a-z]*$", "".join(tmp)):
    print("AC")
    exit()
print("WA")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
q = int(input())

def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return n > 1

s = [False] + [is_prime(i) for i in range(1, 10**5 + 1)]
s = [False] + [s[i] and s[(i + 1) // 2] for i in range(1, 10**5 + 1)]
cs = np.cumsum(s)

for i in range(q):
    l, r = list(map(int, input().split()))
    print(cs[r] - cs[l - 1])



Fixed submission:
import numpy as np
q = int(input())

def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return n > 1

s = [False] + [is_prime(i) for i in range(1, 10**5 + 1)]
s = [False] + [s[i] and s[(i + 1) // 2] for i in range(1, 10**5 + 1)]
cs = np.cumsum(s)

results = []
for i in range(q):
    l, r = list(map(int, input().split()))
    results.append(str(cs[r] - cs[l - 1]))
print("\n".join(results))
Buggy python submission (verdict: Runtime Error):
a = list(input())
b = list(input())

a.sort()
b.sort()

print("Yes" if "".join(a) <　"".join(b) else "No")

Fixed submission:
a = list(input())
b = list(input())

a.sort()
b.sort(reverse=True)

a = "".join(a)
b = "".join(b)

print("Yes" if a < b else "No")
Buggy python submission (verdict: Runtime Error):
# 4
# 3 3 3 3
n = int(input())
a = list(map(int, input().split()))
m = {}

for i in a:
  m[i] = m.get(i, 0) + 1

result = 0
for i in range(n):
  v = a.get(i, 0)
  if v >= i:
    result += v - i
  else:
    result += v
print(result)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = {}

for i in a:
    m[i] = m.get(i, 0) + 1

result = 0
for i in m.keys():
    v = m.get(i, 0)
    if v >= i:
        result += v - i
    else:
        result += v
print(result)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
 if a[i] & 1: break
 a[i] = x//2
print(i)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while True:
 for i in range(n):
  if a[i] & 1:
    print(cnt)
    __import__("sys").exit(0)
  a[i] //= 2
 cnt += 1
Buggy python submission (verdict: Runtime Error):
# 5 2
# 1 1 2 2 5
n, k = map(int, input().split())
a = list(map(int, input().split()))
countup = [0 for x in range(n)]
for i in a:
  countup[i] += 1

result = 0
f = list(filter(lambda x: x != 0, countup.sort()))

for i, v in enumerate(f):
 if i >= len(f) - k:
    print(result)
    break
 result += v


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
countup = [0 for x in range(n + 1)]
for i in a:
  countup[i] += 1

countup.sort()
result = 0
f = list(filter(lambda x: x != 0, countup))

for i, v in enumerate(f):
 if i >= len(f) - k:
    print(result)
    break
 result += v
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
init = np.expand_dims(np.array([2, 1]), 0)
to_next = np.array([
    [1, 1],
    [1, 2],
])
for i in range(n // 2):
    init = init @ to_next
print(init[0][n & 1])


Fixed submission:
import numpy as np
n = int(input())
init = np.expand_dims(np.array([2, 1]), 0)
to_next = np.array([
    [1, 1],
    [1, 2],
])
for i in range(n // 2):
    init = init.dot(to_next)
print(init[0][n & 1])
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

def match(s1, s2):
    if len(s1) < len(s2):
        return False
    for i, j in zip(s1, s2):
        if i != j and i != "?":
            return False
    return True

result = []
for i in range(50):
    if match(s[i:], t):
        result.append((s[:i] + t + s[i + len(t):]).replace("?", "a"))
result.sort()
print(result[0])


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

def match(s1, s2):
    if len(s1) < len(s2):
        return False
    for i, j in zip(s1, s2):
        if i != j and i != "?":
            return False
    return True

result = []
for i in range(50):
    if match(s[i:], t):
        result.append((s[:i] + t + s[i + len(t):]).replace("?", "a"))
result.sort()
if not result:
    print("UNRESTORABLE")
else:
    print(result[0])
Buggy python submission (verdict: Runtime Error):
import numpy as np
n = int(input())
ab = [list(map(int, input().split())) for x in range(n)]

cnt = 0
for a, b in reversed(ab):
    diff = a - b + cnt
    if diff == -b:
        pass
    elif diff < 0:
        cnt -= diff
    else:
        diffb = diff % b
        if diffb:
            cnt += b - diffb
print(int(cnt))



Fixed submission:
import sys
n, m, k = map(int, input().split())

for x in range(n + 1):
    for y in range(m + 1):
        if m * x + n * y - x * y * 2 == k:
            print("Yes")
            sys.exit()
print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(range(n**2))
a = list(map(int, input().split()))
flg = False
cnt = 0
for i, v in enumerate(a, 1):
    if flg:
        flg = False
        continue

    if i is v:
        cnt += 1
        flg = True
print(cnt)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
flg = False
cnt = 0
for i, v in enumerate(a, 1):
    if flg:
        flg = False
        continue

    if i == v:
        cnt += 1
        flg = True
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
input()
a=sorted(list(map(int,input().split())))
e=[1 for x in range(10**9+1)]
r=[]
for i in a:
  if e[i]:
    e[i]=0
  else:
    e[i]=1
    r.append(i)
print(0 if len(r) < 2 else r[-1] * r[-2])

Fixed submission:
input()
a=sorted(list(map(int,input().split())))
e={}
r=[]
for i in a:
  if not e.get(i):
    e[i]=1
  else:
    e[i]=0
    r.append(i)
print(0 if len(r) < 2 else r[-1] * r[-2])
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = [int(input()) for i in range(n)]

b = a[0]
for i in range(1, n):
    b = (b * a[i]) // math.gcd(b, a[i])
print(b)


Fixed submission:
import fractions
n = int(input())
a = [int(input()) for i in range(n)]

b = a[0]
for i in range(1, n):
    b = (b * a[i]) // fractions.gcd(b, a[i])
print(b)
Buggy python submission (verdict: Runtime Error):

a, b, c = map(int, input().split())
print("YES" if b - a == c - b else "NO")


Fixed submission:
print("ABC"+input())
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0] + [int(input()) for i in range(n)]

end = {}

end[1] = True
to = a[1]

cnt = 0
while True:
    cnt += 1
    if to == 2:
        print(cnt)
        __import__("sys").exit()
    if end.get(to) == None:
        to = a[to]
    else:
        break

print(-1)


Fixed submission:
n = int(input())
a = [0] + [int(input()) for i in range(n)]

end = {}

end[1] = True
to = a[1]

cnt = 0
while True:
    cnt += 1
    if to == 2:
        print(cnt)
        __import__("sys").exit()
    if end.get(to) == None:
        end[to] = True
        to = a[to]
    else:
        break

print(-1)
Buggy python submission (verdict: Runtime Error):
s = input()

def resolve(target):
    depth = 0
    now = s
    while len(set(now)) > 1:
        result = list(now[:-1])
        for i, x in enumerate(now[:-1]):
            result[i] = now[i + 1] if now[i + 1] == target else now[i]
        now = "".join(result)
        depth += 1
    return "".join(result), depth


print(min([resolve(chr(target)) for target in range(ord("a"), ord("x") + 1)], key=lambda x: x[1])[1])


Fixed submission:
s = input()
if len(set(s)) <= 1:
    print(0)
    import sys
    sys.exit()

def resolve(target):
    depth = 0
    now = s
    while len(set(now)) > 1:
        result = list(now[:-1])
        for i, x in enumerate(now[:-1]):
            result[i] = now[i + 1] if now[i + 1] == target else now[i]
        now = "".join(result)
        depth += 1
    return "".join(result), depth


print(min([resolve(chr(target)) for target in range(ord("a"), ord("x") + 1)], key=lambda x: x[1])[1])
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input())
print("Yes" if a<=c<=b else "No")

Fixed submission:
a,b,c=map(int,input().split())
print("Yes" if a <= c <= b else "No")
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())

ab = [list(map(int, input().split())) for x in range(n)]
tk = k

ends = [0 for x in range(10**5)]
for a, b in ab:
    ends[a] += b
    
    k -= b
    if k <= 0:
        break


for i, e in enumerate(ends):
    tk -= e
    if tk <= 0:
        print(i)
        break


Fixed submission:
n, k = map(int, input().split())

ab = [list(map(int, input().split())) for x in range(n)]

ends = [0 for x in range(10**5 + 1)]
for a, b in ab:
    ends[a] += b

for i, e in enumerate(ends):
    k -= e
    if k <= 0:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

def calc(a):
    value = a[0]
    sign = value >= 0
    result = 0
    for i in a[1:]:
        value += i
        diff = 0
        if sign and value >= 0:
            diff = value + 1
        elif not sign and value < 0:
            diff = value - 1
        result += abs(diff)
        sign = not sign
        value -= diff
        if value == 0:
            diff += sign
            value += diff
            result += diff
    return result

r1 = calc(a[:])
diff = -a[0] - a[0] // abs(a[0])
a[0] += diff
r2 = calc(a[:]) + abs(diff)
print(min(r1, r2))


Fixed submission:
import numpy as np

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

def calc(a):
    value = a[0]
    sign = value >= 0
    result = 0
    for i in a[1:]:
        value += i
        diff = 0
        if sign and value >= 0:
            diff = value + 1
        elif not sign and value < 0:
            diff = value - 1
        result += abs(diff)
        sign = not sign
        value -= diff
        if value == 0:
            diff += sign
            value += diff
            result += diff
    return result

if a[0] == 0:
    a[0] = 1
    r1 = calc(a[:])
    a[0] = -1
    r2 = calc(a[:])
    print(min(r1, r2) + 1)
else:
    r1 = calc(a[:])
    diff = -a[0] - a[0] // abs(a[0])
    a[0] += diff
    r2 = calc(a[:]) + abs(diff)
    print(min(r1, r2))
Buggy python submission (verdict: Runtime Error):

print("ABC" if int(input()) < 1000 else "ABD")


Fixed submission:
a, b, c = map(int, input().split())
print("YES" if b - a == c - b else "NO")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

img = [input() for i in range(n)]
template = [input() for i in range(m)]

for i in range(n - m + 1):
    if len({v.index(t) for v, t in zip(img[i:i + m], template)}) == 1:
        print("Yes")
        break
else:
    print("No")


Fixed submission:
import numpy as np
n, m = map(int, input().split())

img = np.array([list(input()) for i in range(n)])
w = img.shape[-1]
template = np.array([list(input()) for i in range(m)])
tw = template.shape[-1]

for y in range(n - m + 1):
    for x in range(w - tw + 1):
        if np.all(img[y:y + m, x:x + tw] == template):
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(m)]

abmap = {}
for a, b in ab:
    atarget = abmap.get(a)
    if atarget == None:
        abmap[a] = []
    abmap[a].append(b)

    btarget = abmap.get(b)
    if btarget == None:
        abmap[b] = []
    abmap[b].append(a)

que = [[1, abmap[1], []]]
ends = []
while que:
    now, nextnodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in nextnodes:
        if node in visited:
            continue
        mvisited = visited[:]
        que.append([node, abmap[node], mvisited])

print(len(filter(lambda x: len(x) == n, ends)))


Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for x in range(m)]

abmap = {}
for a, b in ab:
    atarget = abmap.get(a)
    if atarget == None:
        abmap[a] = []
    abmap[a].append(b)

    btarget = abmap.get(b)
    if btarget == None:
        abmap[b] = []
    abmap[b].append(a)

que = [[1, abmap[1], []]]
ends = []
while que:
    now, nextnodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in nextnodes:
        if node in visited:
            continue
        mvisited = visited[:]
        que.append([node, abmap[node], mvisited])

print(len(list(filter(lambda x: len(x) == n, ends))))