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

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

h, w = map(int, input().split())
s = [input() for _ in range(h)]

is_used = [[False] * w for _ in range(h)]

di = [+1, 0, -1, 0]
dj = [0, +1, 0, -1]


def dfs(i, j):
    if s[i][j] == '#':
        cnt_w, cnt_b = 0, 1
    else:
        cnt_w, cnt_b = 1, 0

    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if ni < 0 or ni >= h or nj < 0 or nj >= w:
            continue
        if is_used[ni][nj]:
            continue
        if s[i][j] == s[ni][nj]:
            continue

        is_used[ni][nj] = True
        cw, cb = dfs(ni, nj)
        cnt_w += cw
        cnt_b += cb
    return (cnt_w, cnt_b)


ans = 0
for i in range(h):
    for j in range(w):
        if not is_used[i][j]:
            is_used[i][j] = True
            cnt_w, cnt_b = dfs(i, j)
            ans += cnt_w * cnt_b

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

is_used = [[False] * w for _ in range(h)]

di = [+1, 0, -1, 0]
dj = [0, +1, 0, -1]


def dfs(i, j):
    if s[i][j] == '#':
        cnt_w, cnt_b = 0, 1
    else:
        cnt_w, cnt_b = 1, 0

    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if ni < 0 or ni >= h or nj < 0 or nj >= w:
            continue
        if is_used[ni][nj]:
            continue
        if s[i][j] == s[ni][nj]:
            continue

        is_used[ni][nj] = True
        cw, cb = dfs(ni, nj)
        cnt_w += cw
        cnt_b += cb
    return (cnt_w, cnt_b)


ans = 0
for i in range(h):
    for j in range(w):
        if not is_used[i][j]:
            is_used[i][j] = True
            cnt_w, cnt_b = dfs(i, j)
            ans += cnt_w * cnt_b

print(ans)
Problem p03241 (python)

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

p = m // n
while m % p != 0:
    p -= 1

print(p)

Buggy submission (verdict: Runtime Error):
#include <cstdio>
#include <vector>
using namespace std;

vector<int> divisor(int m) {
    vector<int> divs;
    for (int i = 1; i*i <= m; i++) {
        if (m % i == 0) {
            divs.push_back(i);
            if (m != i*i) {
                divs.push_back(m / i);
            }
        }
    }
    sort(divs.begin(), divs.end());

    return divs;
}

int main() {
    int n, m;

    scanf("%d%d", &n, &m);
    vector<int> divs = divisor(m);

    for (int i = divs.size()-1; i >= 0; i--) {
        if (divs[i] * n <= m) {
            printf("%d\n", divs[i]);
            break;
        }
    }
    return 0;
}
Problem p03274 (python)

Fixed submission:
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
if 0 in x:
    x.remove(0)
    k -= 1
    n -= 1

if n == 0:
    print(0)
else:
    si = bisect_left(x, 0)

    ans = (x[-1] - x[0]) * 2
    if si + k - 1 < len(x):
        ans = min(ans, x[si + k - 1])
    if si - k >= 0:
        ans = min(ans, abs(x[si - k]))

    for i in range(n):
        tmp_ans = 0
        if i < si and i + k -1 < len(x):
            tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
            ans = min(ans, tmp_ans)
        elif i >= si and i - k + 1 >= 0:
            tmp_ans = x[i] * 2 + abs(x[i - k + 1])
            ans = min(ans, tmp_ans)

    print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
# if 0 in x:
#     x.remove(0)
#     k -= 1
#     n -= 1
#
# if n == 0:
#     print(0)

si = bisect_left(x, 0)


ans = x[-1] - x[0]
if si + k - 1 < len(x):
    ans = min(ans, x[si + k - 1])
if si - k >= 0:
    ans = min(ans, abs(x[si - k]))

for i in range(n):
    tmp_ans = 0
    if i < si:
        tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
        ans = min(ans, tmp_ans)
    elif i - k + 1 >= 0:
        tmp_ans = x[i] * 2 + abs(x[i - k + 1])
        ans = min(ans, tmp_ans)

print(ans)
Problem p03282 (python)

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

ans = s[0]
for i in range(min(k, len(s))):
    if s[i] != '1':
        ans = s[i]
        break

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

for i in range(min(k, len(s))):
    if s[i] != "1":
        ans = s[i]
        break

print(ans)
Problem p03340 (python)

Fixed submission:
import math

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

m = 20

ans = n
index = 0
cs = [[0 for i in range(m)] for i in range(n+1)]
bit = [0 for i in range(m)]
for i in range(n):
    for j in range(m):
        cs[i+1][j] = cs[i][j] + ((a[i]>>j)&1)

    bit = [cs[i+1][j] - cs[index][j] for j in range(m)]
    if max(bit) >= 2:
        while max(bit) >= 2:
            k = max(i - index - 1, 0)
            ans += k
            index += 1
            bit = [cs[i+1][j] - cs[index][j] for j in range(m)]

    # print("{:2d} {:2d}".format(i, index), ans, "".join([str((a[i]>>j)&1) for j in reversed(range(m))]))

k = max(n - index - 1, 0)
ans += k * (k+1) // 2
# print(cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

if max(a) > 0:
    m = math.ceil(math.log2(max(a)))
else:
    m = 1

ans = n
index = 0
cs = [[0 for i in range(m)] for i in range(n+1)]
bit = [0 for i in range(m)]
for i in range(n):
    for j in range(m):
        cs[i+1][j] = cs[i][j] + ((a[i]>>j)&1)

    bit = [cs[i+1][j] - cs[index][j] for j in range(m)]
    if max(bit) >= 2:
        while max(bit) >= 2:
            k = max(i - index - 1, 0)
            ans += k
            index += 1
            bit = [cs[i+1][j] - cs[index][j] for j in range(m)]

    # print("{:2d} {:2d}".format(i, index), ans, "".join([str((a[i]>>j)&1) for j in reversed(range(m))]))

k = max(n - index - 1, 0)
ans += k * (k+1) // 2
# print(cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

if max(a) > 0:
    m = math.ceil(math.log2(max(a)))
else:
    m = 1

ans = n
index = 0
cs = [[0 for i in range(m)] for i in range(n+1)]
bit = [0 for i in range(m)]
for i in range(n):
    for j in range(m):
        cs[i+1][j] = cs[i][j] + ((a[i]>>j)&1)

    bit = [cs[i+1][j] - cs[index][j] for j in range(m)]
    if max(bit) >= 2:
        while max(bit) >= 2:
            k = max(i - index - 1, 0)
            ans += k
            index += 1
            bit = [cs[i+1][j] - cs[index][j] for j in range(m)]

    # print("{:2d} {:2d}".format(i, index), ans, "".join([str((a[i]>>j)&1) for j in reversed(range(m))]))

k = max(n - index - 1, 0)
ans += k * (k+1) // 2
# print(cs)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

if max(a) > 0:
    m = math.ceil(math.log2(max(a)))
else:
    m = 1

ans = n
cs = [[0 for i in range(m)] for i in range(n+1)]
bit = [0 for i in range(m)]

for i in range(n):
    for j in range(m):
        cs[i+1][j] = cs[i][j] + ((a[i]>>j)&1)

for i in range(n):
    for j in range(i+1, n+1):
        bit = [cs[j][k] - cs[i][k] for k in range(m)]

        if max(bit) >= 2:
            break
    else:
        j += 1

    k = max(j - i - 2, 0)
    ans += k

    # print("{:2d} {:2d}".format(i, j), ans, "".join([str((a[i]>>j)&1) for j in reversed(range(m))]))

print(ans)
Problem p03361 (python)

Fixed submission:
h, w = map(int, input().split())
s = ['.'*(w+2)] + ['.' + input() + '.' for i in range(h)] + ['.'*(w+2)]
d = [[1, 0], [0, 1], [-1, 0], [0, -1]]

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            continue
        c = 0
        for k in range(4):
            if s[i+d[k][0]][j+d[k][1]] == "#":
                c += 1
        if c == 0:
            ans = -1

if ans == -1:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = ['.'*(h+2)] + ['.' + input() + '.' for i in range(h)] + ['.'*(h+2)]
d = [[1, 0], [0, 1], [-1, 0], [0, -1]]

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            continue
        c = 0
        for k in range(4):
            if s[i+d[k][0]][j+d[k][1]] == "#":
                c += 1
        if c == 0:
            ans = -1

if ans == -1:
    print("No")
else:
    print("Yes")
Problem p03372 (python)

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

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0

cand1 = [0] * n
v_sum = 0
for i in range(n):
    v_sum += sushi[i][1]
    cand1[i] = v_sum - sushi[i][0]
    if i > 0:
        cand1[i] = max(cand1[i], cand1[i-1])

cand2 = [0] * n
v_sum = 0
for i in reversed(range(n)):
    v_sum += sushi[i][1]
    cand2[i] = v_sum - (c - sushi[i][0])
    if i != n - 1:
        cand2[i] = max(cand2[i], cand2[i+1])

ans = max(ans, max(cand1), max(cand2))

v_sum = 0
for i in reversed(range(1, n)):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - (c - sushi[i][0]) * 2 + cand1[i-1])

v_sum = 0
for i in range(n-1):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - sushi[i][0] * 2 + cand2[i+1])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0

cand1 = [0] * n
v_sum = 0
for i in range(n):
    v_sum += sushi[i][1]
    cand1[i] = v_sum - sushi[i][0]
    if i > 0:
        cand1[i] = max(cand1[i], cand1[i-1])

cand2 = [0] * n
v_sum = 0
for i in reversed(range(n)):
    v_sum += sushi[i][1]
    cand2[i] = v_sum - (c - sushi[i][0])
    if i != n - 1:
        cand2[i] = max(cand2[i], cand2[i+1])

ans = max(ans, *cand1, *cand2)

v_sum = 0
for i in reversed(range(1, n)):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - (c - sushi[i][0]) * 2 + cand1[i-1])

v_sum = 0
for i in range(n-1):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - sushi[i][0] * 2 + cand2[i+1])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0

cand1 = [0] * n
v_sum = 0
for i in range(n):
    v_sum += sushi[i][1]
    cand1[i] = v_sum - sushi[i][0]
    if i > 0:
        cand1[i] = max(cand1[i], cand1[i-1])

cand2 = [0] * n
v_sum = 0
for i in reversed(range(n)):
    v_sum += sushi[i][1]
    cand2[i] = v_sum - (c - sushi[i][0])
    if i != n - 1:
        cand2[i] = max(cand2[i], cand2[i+1])

ans = max(ans, *cand1, *cand2)

v_sum = 0
for i in reversed(range(1, n)):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - (c - sushi[i][0]) * 2 + cand1[i-1])

v_sum = 0
for i in range(n-1):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - sushi[i][0] * 2 + cand2[i+1])

print(ans)
Problem p03423 (python)

Fixed submission:
n = int(input())

print(n // 3)

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

print(m // 3)
Problem p03458 (python)

Fixed submission:
import gc
n, k = map(int, input().split())
k2 = k * 2
b = [[0] * (k * 3) for _ in range(k * 3)]
for i in range(n):
    x, y, c = input().split()
    x = int(x) % k2
    y = int(y) % k2
    if c == 'W':
        x = (x + k) % k2

    b[x][y] += 1
    if x < k:
        b[x + k2][y] += 1
    if y < k:
        b[x][y + k2] += 1
    if x < k and y < k:
        b[x + k2][y + k2] += 1

b_cs = [[0] * (k * 3 + 1) for _ in range(k * 3 + 1)]
for i in range(k * 3):
    for j in range(k * 3):
        b_cs[i + 1][j +
                    1] = b_cs[i + 1][j] + b_cs[i][j + 1] - b_cs[i][j] + b[i][j]


def func_b(x, y):
    return b_cs[x + k][y + k] - b_cs[x + k][y] - b_cs[x][y + k] + b_cs[x][y]


# print('black')
# print(*b, sep='\n')
# print(*b_cs, sep='\n')

ans = 0
for i in range(k):
    for j in range(k):
        cand = 0
        cand += func_b(i, j)
        cand += func_b(i + k, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

        cand = 0
        cand += func_b(i + k, j)
        cand += func_b(i, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

print(ans)

Buggy submission (verdict: Runtime Error):
import gc
n, k = map(int, input().split())
k2 = k * 2
b = [[0] * (k * 3) for _ in range(k * 3)]
for i in range(n):
    x, y, c = input().split()
    x = int(x) % k2
    y = int(y) % k2
    if c == 'W':
        x = (x + k) % k2

    b[x][y] += 1
    if x < k:
        b[x + k2][y] += 1
    if y < k:
        b[x][y + k2] += 1
    if x < k and y < k:
        b[x + k2][y + k2] += 1

b_cs = [[0] * (k * 3 + 2) for _ in range(k * 3 + 2)]
for i in range(k * 3 + 1):
    for j in range(k * 3 + 1):
        b_cs[i + 1][j +
                    1] = b_cs[i + 1][j] + b_cs[i][j + 1] - b_cs[i][j] + b[i][j]


def func_b(x, y):
    return b_cs[x + k][y + k] - b_cs[x + k][y] - b_cs[x][y + k] + b_cs[x][y]


# print('black')
# print(*b, sep='\n')
# print(*b_cs, sep='\n')

ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        cand = 0
        cand += func_b(i, j)
        cand += func_b(i + k, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

print(ans)
Problem p03476 (python)

Fixed submission:
import math
q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r) + 10
is_prime = [True] * (r_max+1)
is_prime[0] = is_prime[1] = False
for i in range(2, r_max):
    if is_prime[i]:
        for j in range(2, r_max // i + 1):
            is_prime[i*j] = False

# print(is_prime)
a = [0] * r_max
for i in range(3, r_max):
    a[i] = a[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i]-1])

Buggy submission (verdict: Runtime Error):
q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r) + 10
is_prime = [True] * r_max
is_prime[0] = False
is_prime[1] = False
for i in range(2, r_max):
    if is_prime[i]:
        for j in range(2, r_max // i + 1):
            is_prime[i*j] = False

# print(is_prime)
a = [0] * r_max
for i in range(3, r_max):
    a[i] = a[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i]-1])

Buggy submission (verdict: Runtime Error):
q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r) + 10
is_prime = [True] * r_max
is_prime[0] = is_prime[1] = False
for i in range(2, r_max):
    if is_prime[i]:
        for j in range(2, r_max // i + 1):
            is_prime[i*j] = False

# print(is_prime)
a = [0] * r_max
for i in range(3, r_max):
    a[i] = a[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i]-1])
Problem p03558 (python)

Fixed submission:
from heapq import heappush, heappop


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


k = int(input())

graph = [[] for _ in range(k)]
for i in range(1, k):
    graph[i].append((1, (i + 1) % k))
    graph[i].append((0, 10 * i % k))

dist = dijkstra(graph, k, 1)
ans = dist[0] + 1
print(ans)

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


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


k = int(input())

graph = [[] for _ in range(k)]
for i in range(1, k):
    graph[i].append((1, i + 1))
    graph[i].append((0, 10 * i % k))

dist = dijkstra(graph, k, 1)
ans = dist[0] + 1
print(ans)

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


def dijkstra(graph: list, n: int, v_s: int, INF: int = float('inf')) -> list:
    # graph[v_from] = [(cost, v_to), ...]
    dist = [INF] * n

    dist[v_s] = 0
    heap = [(0, v_s)]  # heap = [(dist[v], v), ...]
    while heap:
        dist2v, v_from = heappop(heap)
        if dist[v_from] < dist2v:
            continue
        for cost, v_to in graph[v_from]:
            dist_cand = dist2v + cost
            if dist_cand < dist[v_to]:
                dist[v_to] = dist_cand
                heappush(heap, (dist[v_to], v_to))
    return dist


k = int(input())

graph = [[] for _ in range(k)]
for i in range(1, k):
    graph[i - 1].append((1, i + 1))
    graph[i].append((0, 10 * i % k))

dist = dijkstra(graph, k, 1)
ans = dist[0]
print(ans)
Problem p03625 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for ai in a:
    d[ai] += 1

cand = [k for k, v in d.items() if v >= 2]
cand.sort()

ans = 0
if len(cand) >= 1 and d[cand[-1]] >= 4:
    ans = cand[-1] ** 2
elif len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for ai in a:
    d[ai] += 1

cand = [k for k, v in d.items() if v >= 2]
cand.sort()

ans = 0
if len(cand) >= 1 and d[cand[-1]] >= 4:
    and = cand[-1] ** 2
if len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)
Problem p03633 (python)

Fixed submission:
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)
def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)

n = int(input())
t = [int(input()) for _ in range(n)]

ans = t[0]
if n > 1:
    ans = LCM(t[0], t[1])
    for i in range(2, n):
        ans = LCM(ans, t[i])

print(ans)

Buggy submission (verdict: Runtime Error):
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)
def LCM(a: int, b: int) -> int:
    return a // GCD(a, b) * b 

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)

Buggy submission (verdict: Runtime Error):
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)
def LCM(a: int, b: int) -> int:
    return a * b // GCD(a, b)

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)
Problem p03672 (python)

Fixed submission:
s = input()

for i in reversed(range(1, len(s)//2)):
    if s[:i] == s[i:2*i]:
        ans = i * 2
        break

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()

abaababaabfor i in reversed(range(1, len(s)//2)):
    if s[:i] == s[i:2*i]:
        ans = i * 2
        break

print(ans)
Problem p03730 (python)

Fixed submission:
a, b, c = map(int, input().split())

if a % b == 0:
    if c == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"
    for i in range(1, b+1):
        if (a*i) % b == c:
            ans = "YES"
            break

print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a % b == 0:
    if c == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"
    for i in range(1, b+1):
        if c % pow(a, i, b) == 0:
            ans = "YES"
            break

print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a % b == 0:
    if c == 0:
        ans = "YES"
    else:
        ans = "NO"
else:
    ans = "NO"
    for i in range(1, b+1):
        if c % ((a**i) % b) == 0:
            ans = "YES"
            break

print(ans)
Problem p03854 (python)

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

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']
def dfs(idx):
    if idx == len(s):
        return True
    ans = False
    for word in words:
        if s[idx:idx+len(word)] == word:
            ans = ans or dfs(idx + len(word))

    return ans

if dfs(0):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']
def dfs(t):
    if t == '':
        return True
    ans = False
    for word in words:
        if t[:len(word)] == word:
            ans = ans or dfs(t[len(word):])

    return ans

if dfs(s):
    print("YES")
else:
    print("NO")
Problem p04014 (python)

Fixed submission:
def func(b, n):
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res


def solve():
    n = int(input())
    s = int(input())

    if n == s:
        return n + 1
    elif n < s:
        return -1

    for b in range(2, n + 1):
        if b**2 > n:
            break
        if func(b, n) == s:
            return b

    b_cand = []
    for p in range(1, n + 1):
        if p**2 > n:
            break
        b = (n - s) // p + 1
        if b > 1:
            b_cand.append(b)
    b_cand = b_cand[::-1]

    for b in b_cand:
        # print(b)
        if func(b, n) == s:
            return b

    return -1


ans = solve()
print(ans)

Buggy submission (verdict: Runtime Error):
def func(b, n):
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res


def solve():
    n = int(input())
    s = int(input())

    if n == s:
        return n + 1
    # elif n < s:
    #     return -1

    for b in range(2, n + 1):
        if b**2 > n:
            break
        if func(b, n) == s:
            return b

    for p in range(1, n + 1):
        if p**2 > n:
            break

        b = (n - s) // p + 1
        if func(b, n) == s:
            return b

    return -1


ans = solve()
print(ans)
Problem p03493 (python)

Fixed submission:
s = input()
numbers = [int(number) for number in s]
print(numbers.count(1))

Buggy submission (verdict: Runtime Error):
N = int(input())
numbers = list(map(int, input().split()))
canDevide = True
count = 0;
while canDevide :
  for i in range(N) :
    if numbers[i]%2 == 0 :
      numbers[i] /= 2
    else :
      canDevide = False
      break
  if canDevide :
    count += 1
print(count)
Problem p03737 (python)

Fixed submission:
a, b, c = map(lambda s: s.strip(), input().split())

print("{0}{1}{2}".format(a[0].upper(), b[0].upper(), c[0].upper()))

Buggy submission (verdict: Runtime Error):
a, b, c = map(lambda s: s.strip(), input().split())

print(f"{a[0].upper()}{b[0].upper()}{c[0].upper()}")