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

Fixed submission:
import sys

import numpy as np
from numba import njit, i8


def input():
    return sys.stdin.readline().strip()


def convert(S):
    i, *d = S.split(".")
    i = int(i) * 1_000_000_000
    if d:
        return i + int(d[0].ljust(9, "0"))
    else:
        return i


def div_cnt(n, d):
    res = 0
    while n % d == 0:
        res += 1
        n //= d
    return res


@njit(i8(i8[:, :]), cache=True)
def solve(table):
    ans = 0
    for i in range(19):
        for j in range(19):
            cur = table[i][j]
            if cur == 0:
                continue
            for k in range(18 - i, 19):
                for l in range(18 - j, 19):
                    if k == i and j == l:
                        ans += cur * (cur - 1)
                    else:
                        ans += cur * table[k][l]
    return ans


N = int(input())
A = list(convert(input()) for _ in range(N))
divs = [(div_cnt(a, 2), div_cnt(a, 5)) for a in A]

table = np.zeros((19, 19), np.int64)
for t, f in divs:
    table[min(t, 18)][min(f, 18)] += 1
print(solve(table) // 2)

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def div_cnt(n, d):
    res = 0
    while n % d == 0:
        res += 1
        n //= d
    return res


N = int(input())
A = list(int(float(input()) * 1_000_000_000) for _ in range(N))
divs = [(div_cnt(a, 2), div_cnt(a, 5)) for a in A]

table = [[0] * 19 for _ in range(19)]
for t, f in divs:
    table[t][f] += 1

ans = 0
for t, f in divs:
    for i in range(19):
        for j in range(19):
            if t + i >= 18 and f + j >= 18:
                ans += table[i][j]
                if t == i and f == j:
                    ans -= 1

print(ans // 2)
Problem p02609 (python)

Fixed submission:
def pop_count(n):
    return sum(n >> i & 1 for i in range(n.bit_length()))


def f(n):
    if n == 0:
        return 0
    return f(n % pop_count(n)) + 1


N = int(input())
X = input()
p = X.count("1")
rem_plus = 0
rem_minus = 0
for i in range(N):
    k = N - i - 1
    if X[i] == "0":
        continue
    elif p > 1:
        rem_minus = (rem_minus + pow(2, k, p - 1)) % (p - 1)
    rem_plus = (rem_plus + pow(2, k, p + 1)) % (p + 1)
for i in range(N):
    k = N - i - 1
    if X[i] == "0":
        print(f((rem_plus + pow(2, k, p + 1)) % (p + 1)) + 1)
    elif p > 1:
        print(f((rem_minus - pow(2, k, p - 1)) % (p - 1)) + 1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
def pop_count(n):
    return bin(n).count("1")


N = int(input())
X = list(map(int, input()))
X_m = 0
X_p = 0
pop_X = 0
if 1 in X:
    pop_X += X.count(1)
    for i in range(N):
        if X[N - i - 1]:
            X_m += pow(2, i, pop_X - 1)
            X_m %= pop_X - 1
            X_p += pow(2, i, pop_X + 1)
            X_p %= pop_X + 1

for i in range(N):
    ans = 1
    n = 0
    if X[i]:
        n += X_m
        n -= pow(2, N - i - 1, pop_X - 1)
        n %= pop_X - 1
    else:
        n += X_p
        n += pow(2, N - i - 1, pop_X + 1)
        n %= pop_X + 1
    while n:
        n %= pop_count(n)
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
def pop_count(n):
    return bin(n).count("1")


N = int(input())
X = list(map(int, input()))
pop_X = X.count(1)
X_m = 0
X_p = 0
for i in range(N):
    if X[N - i - 1]:
        X_p += pow(2, i, pop_X + 1)
        X_p %= pop_X + 1
        X_m += pow(2, i, pop_X - 1)
        X_m %= pop_X - 1

for i in range(N):
    ans = 1
    n = 0
    if X[i]:
        n += X_m
        n -= pow(2, N - i - 1, pop_X - 1)
        n %= pop_X - 1
    else:
        n += X_p
        n += pow(2, N - i - 1, pop_X + 1)
        n %= pop_X + 1
    while n:
        n %= pop_count(n)
        ans += 1
    print(ans)
Problem p02647 (python)

Fixed submission:
import numpy as np
from numba import njit


@njit
def solve(N, K, A):
    for _ in range(K):
        B = np.zeros(N + 1, dtype=np.int64)
        for i in range(N):
            a = A[i]
            B[max(0, i - a)] += 1
            B[min(N, i + a + 1)] -= 1
        A = np.cumsum(B)[:-1]
        if np.all(A == N):
            return A
    return A


N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
print(' '.join(map(str, solve(N, K, A))))

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


N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
for k in range(K):
    B_acc = np.zeros(N + 1, dtype=int)
    for i in range(N):
        a = A[i]
        B_acc[max(0, i - a)] += 1
        B_acc[min(N, i + a + 1)] -= 1
    B_acc = np.cumsum(B_acc)
    A = B_acc[:-1]
    if all(a == N for a in A):
        break
print(' '.join(map(str, A)))
Problem p02658 (python)

Fixed submission:
N = input()
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(-1)
        break
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, open(0).read().split())
if 0 in A:
    print(0)
    exit()
ans = 1
for a in A:
    ans *= a
    if ans > 10 ** 18:
        print(-1)
        break
else:
    print(ans)
Problem p02684 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

pos = A[1]
path = [1]
visited = {1}
cycle_start = -1
for _ in range(N):
    if pos in visited:
        cycle_start = pos
        break
    visited.add(pos)
    path.append(pos)
    pos = A[pos]

if cycle_start > 0:
    cycle_start_idx = path.index(cycle_start)
    acyclic_path = path[:cycle_start_idx]
    cyclic_path = path[cycle_start_idx:]
    if K < len(acyclic_path):
        print(acyclic_path[K])
    else:
        print(cyclic_path[(K - len(acyclic_path)) % len(cyclic_path)])
else:
    print(path[K])

Buggy submission (verdict: Runtime Error):
def dfs(v):
    path.append(v)
    visited[v] = 1
    nv = A[v]
    if visited[nv] == 1:
        return nv
    return dfs(nv)


N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
visited = [-1] * N
path = []
cycle_start = dfs(0)
cycle_len = len(path) - path.index(cycle_start)
head_len = len(path) - cycle_len
if K <= head_len:
    print(path[K] + 1)
else:
    K -= head_len
    print(path[head_len + K % cycle_len] + 1)
Problem p02714 (python)

Fixed submission:
from itertools import accumulate
n = int(input())
s = input()

r_acc = [0] + list(accumulate([int(s[i] == 'R') for i in range(n)]))
g_acc = [0] + list(accumulate([int(s[i] == 'G') for i in range(n)]))
b_acc = [0] + list(accumulate([int(s[i] == 'B') for i in range(n)]))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        si = s[i]
        sj = s[j]
        if si == sj:
            continue
        if (si == 'R' and sj == 'G') or (si == 'G' and sj == 'R'):
            ans += b_acc[n] - b_acc[j]
            if n >= j + j - i + 1:
                ans -= b_acc[j + j - i + 1] - b_acc[j + j - i]
        elif (si == 'R' and sj == 'B') or (si == 'B' and sj == 'R'):
            ans += g_acc[n] - g_acc[j]
            if n >= j + j - i + 1:
                ans -= g_acc[j + j - i + 1] - g_acc[j + j - i]
        else:
            ans += r_acc[n] - r_acc[j]
            if n >= j + j - i + 1:
                ans -= r_acc[j + j - i + 1] - r_acc[j + j - i]
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
n = int(input())
s = input()

r_acc = list(accumulate([s[i] == 'R' for i in range(n)], initial=0))
g_acc = list(accumulate([s[i] == 'G' for i in range(n)], initial=0))
b_acc = list(accumulate([s[i] == 'B' for i in range(n)], initial=0))

ans = 0
all = {'R', 'G', 'B'}
for i in range(n):
    for j in range(i + 1, n):
        si = s[i]
        sj = s[j]
        if si == sj:
            continue
        if (si == 'R' and sj == 'G') or (si == 'G' and sj == 'R'):
            ans += b_acc[n] - b_acc[j]
            if n >= j + j - i + 1:
                ans -= b_acc[j + j - i + 1] - b_acc[j + j - i]
        elif (si == 'R' and sj == 'B') or (si == 'B' and sj == 'R'):
            ans += g_acc[n] - g_acc[j]
            if n >= j + j - i + 1:
                ans -= g_acc[j + j - i + 1] - g_acc[j + j - i]
        else:
            ans += r_acc[n] - r_acc[j]
            if n >= j + j - i + 1:
                ans -= r_acc[j + j - i + 1] - r_acc[j + j - i]
print(ans)
Problem p02778 (python)

Fixed submission:
print("x" * len(input()))

Buggy submission (verdict: Runtime Error):
print(“x” * len(input()))
Problem p02783 (python)

Fixed submission:
H, A = map(int, input().split())
print((H + A - 1) // A)

Buggy submission (verdict: Runtime Error):
H, A = map(isn’t, input().split())
print((H + A - 1) // A)
Problem p02787 (python)

Fixed submission:
H, N, *AB = map(int, open(0).read().split())
A = []
B = []
for a, b in zip(*[iter(AB)] * 2):
    A.append(a)
    B.append(b)

dp = [float("inf")] * (H + 1)
dp[0] = 0

for i in range(N):
    for h in range(H):
        dec_health = min(h + A[i], H)
        dp[dec_health] = min(dp[dec_health], dp[h] + B[i])
print(dp[-1])

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


H, N, *AB = map(int, open(0).read().split())
A = np.array(AB[::2])
B = np.array(AB[1::2])
max_A = A.max()

dp = np.zeros(H, dtype=np.int64)
for h in range(H):
    dp[h] = np.min(dp[h - A] + B)

print(dp[-1])
Problem p02802 (python)

Fixed submission:
from collections import defaultdict

n, m = map(int, input().split())
ps = []
for _ in range(m):
    ps.append(input().split())

sub_st = defaultdict(list)
for p, s in ps:
    sub_st[p].append(s)

solved = 0
error = 0
for k, v in sub_st.items():
    temp_error = 0
    for history in v:
        if 'AC' in history:
            error += temp_error
            solved += 1
            break
        temp_error += 1

print(solved, error)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n, m = map(int, input().split())
ps = []
for _ in range(n):
  ps.append(map(int, input().split()))

sub_st = defaultdict(list)
for p, s in ps:
  sub_st[p].append(s)

solved = 0
error = 0
for k, v in sub_st.items():
  temp_error = 0
  for history in v:
    temp_error += 1
    if 'AC' in v:
      error += temp_error
      solved += 1
      break

priny(solved, error)
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
if 500 * k >= x:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
 k, x = map(int, input().split())
 if 500 * k >= x:
  print('Yes')
 else:
  print('No)
Problem p02814 (python)

Fixed submission:
from functools import reduce


def count_factors(a, factor):
    count = 0
    while a % factor == 0:
        count += 1
        a //= factor
    return count


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


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


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(set(map(lambda x: int(x) // 2, input().split())))
    num_of_two = count_factors(a[0], 2)
    for ai in a[1:]:
        if count_factors(ai, 2) != num_of_two:
            print(0)
            exit()

    a_lcm = reduce(lambda x, y: lcm(x, y), a)
    if a_lcm > m:
        print(0)
        exit()

    print((m // a_lcm + 1) // 2)

Buggy submission (verdict: Runtime Error):
from math import gcd, ceil


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


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    twos_cnt = {prime_factor(num).count(2) for num in a}
    if len(twos_cnt) > 1:
        print(0)
        exit()

    num_two = twos_cnt.pop()
    a_div = [x >> num_two for x in a]

    a_div_lcm = a_div[0]
    for i in range(1, n):
        a_div_lcm = a_div_lcm * a_div[i] // gcd(a_div_lcm, a_div[i])
    print(ceil(m / a_div_lcm * 0.5 - 0.5))

Buggy submission (verdict: Runtime Error):
from math import gcd, ceil


def ramp(x):
    if x > 0:
        return x
    else:
        return 0


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a_lcm = a[0]
    for i in range(1, n):
        a_lcm = a_lcm * a[i] // gcd(a_lcm, a[i])
    print(ramp(ceil(m / a_lcm - 0.5)))

Buggy submission (verdict: Runtime Error):
from math import gcd


if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a_lcm = a[0]
    for i in range(1, n):
        a_lcm = a_lcm * a[i] // gcd(a_lcm, a[i])
    print(int(m / a_lcm - 0.5) + 1)
Problem p02903 (python)

Fixed submission:
H, W, A, B = map(int, input().split())
for _ in range(B):
    print("0" * A + "1" * (W - A))
for _ in range(H - B):
    print("1" * A + "0" * (W - A))

Buggy submission (verdict: Runtime Error):
from math import gcd


H, W, A, B = map(int, input().split())
gcd_hw = gcd(H, W)
gcd_ab = gcd(A, B)
if H == 1:
    print("1" * A + "0" * (W - A))
    exit()
if W == 1:
    print(*("1" * B + "0" * (H - B)), sep="\n")
    exit()

if H // gcd_hw == B // gcd_ab and W // gcd_hw == A // gcd_ab:
    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(A):
            ans[i][(j + B * i) % W] = 1
    [print("".join(map(str, row))) for row in ans]
else:
    print("No")
Problem p02937 (python)

Fixed submission:
from bisect import bisect_left


def solve():
    S = input()
    T = input()
    if not set(T) <= set(S):
        return -1

    pos = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, c in enumerate(S):
        pos[c].append(i)
    ans = 0
    cur_pos = 0
    for t in T:
        nxt_idx = bisect_left(pos[t], cur_pos)
        if nxt_idx == len(pos[t]):
            ans += len(S)
            cur_pos = 0
            nxt_idx = bisect_left(pos[t], cur_pos)
            cur_pos = pos[t][nxt_idx] + 1
        else:
            cur_pos = pos[t][nxt_idx] + 1

    return ans + cur_pos


print(solve())

Buggy submission (verdict: Runtime Error):
N, *A = map(int, open(0).read().split())

A = [0] + A
B = [0] * (N + 1)
sum_B = 0
for i in range(N, 0, -1):
    if sum(B[j] for j in range(i, N + 1, i)) % 2 != A[i]:
        B[i] = 1
        sum_B += 1
print(sum_B)
print(*[i for i, b in enumerate(B) if b])
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
MOD = 2019
ans = float("inf")
for i in range(L, R):
    for j in range(i + 1, R + 1):
        ans = min(ans, i * j % MOD)
        if ans == 0:
            print(0)
            exit()
print(ans)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
MOD = 2019
L %= MOD
R %= MOD
print(min(i * j % 2019 for i in range(L, R) for j in range(i + 1, R + 1)))
Problem p03014 (python)

Fixed submission:
import numpy as np


H, W = map(int, input().split())
field = [[c == "." for c in input()] for _ in range(H)]
field = np.array(field, dtype=np.int16)

u = field.copy()
d = field.copy()
l = field.copy()
r = field.copy()

for i in range(1, H):
    u[i] = (u[i - 1] + 1) * u[i]
    d[-i - 1] = (d[-i] + 1) * d[-i - 1]

for j in range(1, W):
    l[:, j] = (l[:, j - 1] + 1) * l[:, j]
    r[:, -j - 1] = (r[:, -j] + 1) * r[:, -j - 1]

print((u + d + l + r - 3).max())

Buggy submission (verdict: Runtime Error):
from copy import deepcopy

import numpy as np


H, W = map(int, input().split())
field = np.array([[c == "." for c in input()] for _ in range(H)], dtype=np.int16)

u = deepcopy(field)
d = deepcopy(field)
l = deepcopy(field)
r = deepcopy(field)

for i in range(H):
    for j in range(1, W):
        if field[i, j]:
            l[i, j] = l[i, j - 1] + 1
        if field[i, W - j - 1]:
            r[i, W - j - 1] = r[i, W - j] + 1

for j in range(W):
    for i in range(1, H):
        if field[i, j]:
            u[i, j] = u[i - 1, j] + 1
        if field[H - i - 1, j]:
            d[H - i - 1, j] = d[H - i, j] + 1

print((u + d + l + r - 3).max())

Buggy submission (verdict: Runtime Error):
import sys


sys.setrecursionlimit(10 ** 6)


def f(n):
    if memo[n] > 0:
        return memo[n]
    memo[n] = f(n - 1) + f(n - 2)
    return memo[n]


N, M, *A = map(int, open(0).read().split())
memo = [1, 1] + [-1] * N
A = list(A) + [N + 1]
MOD = 10 ** 9 + 7
ans = 1
prev = 0
for a in A:
    if a == prev:
        ans = 0
        break
    ans *= f(a - 1 - prev)
    ans %= MOD
    prev = a + 1
print(ans)
Problem p03032 (python)

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

ans = 0
for a_plus_b in range(min(N, K) + 1):
    for a in range(a_plus_b + 1):
        b = a_plus_b - a
        gems = V[:a]
        if b > 0:
            gems += V[-b:]
        gems.sort()
        negative_gems = [g for g in gems if g < 0]
        ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b]))
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heapify


N, K, *V = map(int, open(0).read().split())

# i: 操作回数
# j: iのうち戻す回数
# k: i - j のうち左から取り出す範囲 [0, k)
ans = 0
for i in range(K + 1):
    res = 0
    pq = []
    for j in range(i // 2 + 1):
        for k in range(i - j + 1):
            put_out_cnt = j
            tmp = V[:k]
            l = i - j - k
            if l > 0:
                tmp += V[-l:]
            heapify(tmp)
            while put_out_cnt > 0:
                heappop(tmp)
                put_out_cnt -= 1
            ans = max(ans, sum(tmp))
print(ans)
Problem p03157 (python)

Fixed submission:
from sys import setrecursionlimit


def dfs(i, j, c):
    visited[i][j] = 1
    current.append((i, j))
    for di, dj in (1, 0), (-1, 0), (0, 1), (0, -1):
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W and not visited[ni][nj]):
            continue
        if S[ni][nj] == c:
            continue
        dfs(ni, nj, not c)


setrecursionlimit(2 * 10 ** 5)
H, W = map(int, input().split())
S = [[c == "#" for c in input()] for _ in range(H)]

ans = 0
visited = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] and not visited[i][j]:
            current = []
            dfs(i, j, True)
            b, w = 0, 0
            for k, l in current:
                if S[k][l]:
                    b += 1
                else:
                    w += 1
            ans += b * w
print(ans)

Buggy submission (verdict: Runtime Error):
def dfs(i, j, c):
    visited[i][j] = 1
    current.append((i, j))
    for di, dj in (1, 0), (-1, 0), (0, 1), (0, -1):
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W and not visited[ni][nj]):
            continue
        if S[ni][nj] == c:
            continue
        dfs(ni, nj, not c)


H, W = map(int, input().split())
S = [[c == "#" for c in input()] for _ in range(H)]

ans = 0
visited = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] and not visited[i][j]:
            current = []
            dfs(i, j, True)
            b, w = 0, 0
            for k, l in current:
                if S[k][l]:
                    b += 1
                else:
                    w += 1
            ans += b * w
print(ans)
Problem p03161 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


n, k = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 9
dp = [INF] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, k + 1):
        if j >= n - i:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
h = list(map(int, input().split()))

# 足場iに到るコスト
dp = [math.inf] * n
dp[0] = 0

for i in range(1, n):
    for j in range(1, k + 1):
        if i < j:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[-1])
Problem p03166 (python)

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


def input():
    return sys.stdin.readline().strip()


def dfs(v):
    if dp[v] >= 0:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


n, m = map(int, input().split())
g = {i: set() for i in range(1, n + 1)}
for _ in range(m):
    x, y = map(int, input().split())
    g[x].add(y)

dp = [-1] * (n + 1)
for v in g:
    dp[v] = max(dp[v], dfs(v))
print(max(dp))

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def dfs(v):
    if dp[v] >= 0:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


n, m = map(int, input().split())
g = {i: set() for i in range(1, n + 1)}
for _ in range(m):
    x, y = map(int, input().split())
    g[x].add(y)

dp = [-1] * (n + 1)
for v in g:
    dp[v] = max(dp[v], dfs(v))
print(max(dp))

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def dfs(v):
    if dp[v] >= 0:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


n, m = map(int, input().split())
g = {i: set() for i in range(1, n + 1)}
for _ in range(m):
    x, y = map(int, input().split())
    g[x].add(y)

dp = [-1] * (n + 1)
for v in g:
    dp[v] = max(dp[v], dfs(v))
    print(v, dp)

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def dfs(v):
    if dp[v] > 0:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


n, m = map(int, input().split())
g = {i: set() for i in range(1, n + 1)}
for _ in range(m):
    x, y = map(int, input().split())
    g[x].add(y)

dp = [-1] * (n + 1)
for v in g:
    dp[v] = max(dp[v], dfs(v))
    print(v, dp)
Problem p03231 (python)

Fixed submission:
from fractions import gcd


N, M = map(int, input().split())
S = input()
T = input()
g = gcd(N, M)
N //= g
M //= g
for i in range(g):
    if S[i * N] != T[i * M]:
        print(-1)
        break
else:
    print(N * M * g)

Buggy submission (verdict: Runtime Error):
from fractions import gcd


N, M = map(int, input().split())
S = input()
T = input()
LCM = N * M // gcd(N, M)
S_dist = [""] * LCM
T_dist = [""] * LCM
for i in range(N):
    S_dist[i * LCM // N] = S[i]
for i in range(M):
    T_dist[i * LCM // M] = T[i]
for s, t in zip(S_dist, T_dist):
    if s != "" and t != "" and s != t:
        print(-1)
        break
else:
    print(LCM)
Problem p03241 (python)

Fixed submission:
def enum_divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
    return res


N, M = map(int, input().split())
divs = filter(lambda x: x <= M // N, enum_divisors(M))
print(max(divs))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = 0
for i in range(1, (M + N - 2) // (N - 1)):
    if (M - i * (N - 1)) % i == 0:
        ans = i
print(ans)
Problem p03523 (python)

Fixed submission:
candidates = []
seps = ["KIH", "B", "R", ""]
for i in range(1 << 4):
    has_A = []
    for j in range(4):
        if i >> j & 1:
            has_A.append("A")
        else:
            has_A.append("")
    candidate = []
    for a, sep in zip(has_A, seps):
        candidate.append(a + sep)
    candidates.append("".join(candidate))

print("YES") if input() in candidates else print("NO")

Buggy submission (verdict: Runtime Error):
from itertools import product


candidates = []
non_as = ["KIH", "B", "R", ""]
for seps in product(["A", ""], repeat=4):
    candidates.add("".append(sep + non_a for sep, non_a in zip(seps, non_as)))

print("YES") if input() in candidates else print("NO")