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

Fixed submission:
N, *B = map(int, open(0).read().split())

ans = B[0] + B[-1]
for i in range(N - 2):
    ans += min(B[i], B[i + 1])
    
print(ans)

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

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N * N)]
ins = [0] * (N * N)

for i, nodes in enumerate(X):
    for j1, j2 in zip(nodes[:-1], nodes[1:]):
        n1 = max(i, j1 - 1) * N + min(i, j1 - 1)
        n2 = max(i, j2 - 1) * N + min(i, j2 - 1)
        graph[n1].append(n2)
        ins[n2] += 1

dist = [0] * (N * N)
visited = [False] * (N * N)
q = deque()
for i in range(N):
    visited[N * i + i] = True

for i, v in enumerate(ins):
    if v == 0:
        q.append(i)
        visited[i] = True
        dist[i] = 1

while q:
    u = q.popleft()
    for v in graph[u]:
        if visited[v]:
            continue

        ins[v] -= 1
        if ins[v] == 0:
            visited[v] = True
            dist[v] = dist[u] + 1
            q.append(v)
            
print(max(dist) if all(visited) else -1)

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

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N * N)]
ins = [0] * (N * N)

for i, nodes in enumerate(X):
    for j1, j2 in zip(nodes[:-1], nodes[1:]):
        n1 = max(i, j1 - 1) * N + min(i, j1 - 1)
        n2 = max(i, j2 - 1) * N + min(i, j2 - 1)
        graph[n1].append(n2)
        ins[n2] += 1

dist = [0] * (N * N)
visited = [False] * (N * N)
q = deque()
for i in range(N):
    visited[N * i + i] = True

for i, v in enumerate(ins):
    if v == 0:
        q.append(i)
        visited[i] = True
        dist[i] = 1

while q:
    u = q.popleft()
    for v in graph[u]:
        if visited[v]:
            continue

        ins[v] -= 1
        if ins[v] == 0:
            visited[v] = True
            dist[v] = dist[u] + 1
            q.append(v)
            
print(max(dist) if all(visited) else -1)

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

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

graph = [[] for _ in range(N * N)]
ins = [0] * (N * N)

for i, nodes in enumerate(X):
    for j1, j2 in zip(nodes[:-1], nodes[1:]):
        n1 = max(i, j1 - 1) * N + min(i, j1 - 1)
        n2 = max(i, j2 - 1) * N + min(i, j2 - 1)
        graph[n1].append(n2)
        ins[n2] += 1

dist = [0] * (N * N)
visited = [False] * (N * N)
q = deque()
for i in range(N):
    visited[N * i + i] = True

for i, v in enumerate(ins):
    if v == 0:
        q.append(i)
        visited[i] = True
        dist[i] = 1

while q:
    u = q.popleft()
    for v in graph[u]:
        if visited[v]:
            continue

        ins[v] -= 1
        if ins[v] == 0:
            visited[v] = True
            dist[v] = dist[u] + 1
            q.append(v)
            
print(max(dist) if all(visited) else -1)
Problem p02936 (python)

Fixed submission:
from collections import deque

N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N - 1)]
Y = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N + 1)]
for a, b in X:
    graph[a].append(b)
    graph[b].append(a)

ctr = [0] * (N + 1)
for p, x in Y:
    ctr[p] += x

# BFS
visited = [False] * (N + 1)
visited[1] = True
q = deque([1])
while q:
    u = q.popleft()
    for v in graph[u]:
        if visited[v]:
            continue
            
        ctr[v] += ctr[u]
        visited[v] = True
        q.append(v)
        
print(*ctr[1:])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N - 1)]
P = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N + 1)]
for a, b in X:
    tree[a].append(b)

def dfs(u, x):
    ctr[u] += x
    for v in tree[u]:
        dfs(v, x)

ctr = [0] * (N + 1)
for p, x in P:
    dfs(p, x)
    
print(*ctr[1:])
Problem p02937 (python)

Fixed submission:
from collections import defaultdict
from bisect import bisect_left

s = input()
t = input()

if set(s) >= set(t):
    d = defaultdict(list)
    for i, x in enumerate(s * 2):
        d[x].append(i)
    
    ans = 0
    cur = 0
    N = len(s)
    for x in t:
        cur_new = d[x][bisect_left(d[x], cur)]
        ans += cur_new - cur + 1
        cur = (cur_new + 1) % N

    print(ans)
else:
    print(-1)

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

s = input()
t = input()

indices = defaultdict(list)
for i, v in enumerate(s):
    indices[v].append(i)

cnt = 0
cur = -1
mod = len(s)
flag = False
for v in t:
    if v not in indices:
        flag = True
        break

    i = bisect_right(indices[v], cur)
    if i == len(indices[v]):
        j = indices[v][0]
    else:
        j = indices[v][i]

    if cur >= j:
        cnt += 1
    cur = j

if flag:
    print(-1)
else:
    print(cnt * mod + cur + 1)
Problem p02973 (python)

Fixed submission:
from bisect import bisect
N, *A = map(int, open(0).read().split())

INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
for i in range(N):
    dp[bisect(dp, -A[i])] = -A[i]

print(sum(dp[i] < INF for i in range(N)))

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

INF = 10 ** 6
dp = [INF] * (N + 1)
ans = 0
for i in range(N):
    idx = bisect_left(dp, A[i])
    dp[idx] = A[i]
    ans += 1 if idx == 0 else 0
print(ans)
Problem p02985 (python)

Fixed submission:
from collections import deque
N, K = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7

def dfs(u, par):
    q = deque()
    q.append((u, par))
    ret = 1

    while q:
        u, par = q.pop()
        color_num = K - 1 if par == -1 else K - 2
        
        if len(graph[u]) > K:
            return 0
            
        for v in graph[u]:
            if v == par:
                continue
                
            ret *= color_num
            ret %= MOD
            color_num -= 1
            
            q.append((v, u))

    return ret

graph = [[] for _ in range(N)]
for u, v in edges:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

print(dfs(0, -1) * K % MOD)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 10 ** 9 + 7

def dfs(u, par):
    color_num = K - 1 if par == -1 else K - 2

    if len(graph[u]) > K:
        return 0
    
    cnt = 1
    for v in graph[u]:
        if v == par:
            continue

        cnt *= color_num
        cnt %= MOD
        color_num -= 1

    for v in graph[u]:
        if v == par:
            continue

        cnt *= dfs(v, u)
        cnt %= MOD
        
    return cnt

graph = [[] for _ in range(N)]
for u, v in edges:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

print(dfs(0, -1) * K % MOD)
Problem p03006 (python)

Fixed submission:
from itertools import combinations
from collections import Counter

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

if N == 1:
    print(1)
    quit()

X.sort()
diff = []
for i, j in combinations(range(N), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print(N - Counter(diff).most_common()[0][1])

Buggy submission (verdict: Runtime Error):

from collections import defaultdict

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
    for j in range(i + 1, N):
        p = X[i][0] - X[j][0]
        q = X[i][1] - X[j][1]
        ctr[(p, q)] += 1
        ctr[(-p, -q)] += 1

print(N - max(ctr.values()))

Buggy submission (verdict: Runtime Error):
from itertools import combinations
from collections import Counter

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
diff = []
for i, j in combinations(range(N), 2):
    diff.append((X[i][0] - X[j][0], X[i][1] - X[j][1]))
print(N - Counter(diff).most_common()[0][1])
Problem p03007 (python)

Fixed submission:
N, *A = map(int, open(0).read().split())

x = sorted([v for v in A if v >= 0])
y = sorted([v for v in A if v < 0], reverse=True)

ans = []
if len(y) == 0:
    cnt = x[0]
    for v in x[1:-1]:
        ans.append((cnt, v))
        cnt -= v
    ans.append((x[-1], cnt))
    print(x[-1] - cnt)
elif len(x) == 0:
    cnt = y[0]
    for v in y[1:]:
        ans.append((cnt, v))
        cnt -= v
    print(cnt)
else:
    for v in x[:-1]:
        ans.append((y[0], v))
        y[0] -= v
        
    cnt = x[-1]
    for v in y:
        ans.append((cnt, v))
        cnt -= v
    print(cnt)
    
for v in ans:
    print(*v)

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

A_MAX = max(abs(A[0]), abs(A[-1]))
A.remove(A_MAX)
X = sorted(A)
x = X[0]
ans = []
for v in X[1:]:
    ans.append((x, v))
    x -= v

if x <= 0:
    print(A_MAX - x)
    ans.append((A_MAX, x))
else:
    print(x - A_MAX)
    ans.append((x, A_MAX))
for i in range(N - 1):
    print(*ans[i])

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

B = A[:]
A_MAX = max(B)
B.remove(A_MAX)

ans = []
while len(B) > 1:
    B.sort()
    x = B.pop()
    y = B.pop()
    if y >= 0:
        idx = bisect(B, x - y)
        B = B[:idx] + [x - y] + B[idx:]
        ans.append([x, y])
    else:
        idx = bisect(B, y - x)
        B = B[:idx] + [y - x] + B[idx:]
        ans.append([y, x])
    
if B[0] <= 0:
    print(A_MAX - B[0])
    ans.append([A_MAX, B[0]])
else:
    print(B[0] - A_MAX)
    ans.append([B[0], A_MAX])
for i in range(N - 1):
    print(*ans[i])
Problem p03030 (python)

Fixed submission:
N = int(input())
X = [list(input().split()) for _ in range(N)]
for i, t in sorted(enumerate(X), key=lambda x: (x[1][0], -int(x[1][1]))):
  print(i + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key=lambda x: (x[0], -x[1]))
for a, b in X:
  print(a, b)
Problem p03043 (python)

Fixed submission:
from math import log2, ceil

N, K = map(int, input().split())
ans = 0
max_pow = ceil(log2(K))
for n in range(1, N + 1):
    ans += 2 ** (max_pow - max(0, ceil(log2(K / n))))
print(ans / (N * 2 ** max_pow))

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

ans = 0
max_pow = ceil(log2(K))
for n in range(1, N + 1):
    ans += 2 ** (max_pow - max(0, ceil(log2(K / n))))
    
print(ans / (N * 2 ** max_pow))
Problem p03061 (python)

Fixed submission:
from fractions import gcd
from itertools import accumulate

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

b = list(accumulate([0] + a, gcd))
c = list(accumulate([0] + a[::-1], gcd))
l = list(gcd(s, t) for s, t in zip(b[:-1], c[::-1][1:]))
print(max(l))

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

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

b = list(accumulate([0] + a, gcd))
c = list(accumulate([0] + a[::-1], gcd))
l = list(gcd(s, t) for s, t in zip(b[:-1], c[::-1][1:]))
print(max(l))

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

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

l = set(gcd(x, y) for x, y in list(combinations(a, 2)))
if 1 in l:
    remove(1)
print(max(l))

Buggy submission (verdict: Runtime Error):
from math import gcd
# from fractions import gcd
from itertools import combinations

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

l = set(gcd(x, y) for x, y in list(combinations(a, 2)))
if 1 in l:
    remove(1)
print(max(l))

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

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

l = set(gcd(x, y) for x, y in list(permutations(a, 2)))
if 1 in l:
    remove(1)
print(min(l))

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

N = 3
a = [12, 15, 18]

l = set(gcd(x, y) for x, y in list(permutations(a, 2)))
if 1 in l:
    remove(1)
print(min(l))

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

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

l = set(gcd(x, y) for x, y in list(permutations(a, 2)))
if 1 in l:
    remove(1)
print(min(l))
Problem p03087 (python)

Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
  l, r = map(int, input().split())
  print(len(re.findall('AC', S[l - 1:r])))
Problem p03103 (python)

Fixed submission:
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(res)
Problem p03112 (python)

Fixed submission:
from bisect import bisect_right

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
x = [int(input()) for _ in range(Q)]

INF = 10 ** 18
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for i in range(Q):
    b = bisect_right(s, x[i])
    d = bisect_right(t, x[i])
    res = INF
    for n in [s[b - 1], s[b]]:
        for m in [t[d - 1], t[d]]:
            d1 = abs(n - x[i]) + abs(m - n)
            d2 = abs(m - x[i]) + abs(n - m)
            res = min(res, d1, d2)
    print(res)

Buggy submission (verdict: Runtime Error):

from bisect import bisect_right

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    # Shrine -> Temple
    idx_s = bisect_right(S, x)
    if abs(S[min(A - 1, idx_s)] - x) > abs(S[max(0, idx_s - 1)] - x):
        x_s = S[max(0, idx_s - 1)]
    else:
        x_s = S[min(A - 1, idx_s)]

    idx_t = bisect_right(T, x_s)
    if abs(T[min(A - 1, idx_t)] - x_s) > abs(T[max(0, idx_t - 1)] - x_s):
        x_t = T[max(0, idx_t - 1)]
    else:
        x_t = T[min(B - 1, idx_t)]

    cand_0 = abs(x_s - x) + abs(x_t - x_s)

    # Temple -> Shrine
    idx_t = bisect_right(T, x)
    if abs(T[min(A - 1, idx_t)] - x) > abs(T[max(0, idx_t - 1)] - x):
        x_t = T[max(0, idx_t - 1)]
    else:
        x_t = T[min(B - 1, idx_t)]

    idx_s = bisect_right(S, x_t)
    if abs(S[min(A - 1, idx_s)] - x_t) > abs(S[max(0, idx_s - 1)] - x_t):
        x_s = S[max(0, idx_s - 1)]
    else:
        x_s = S[min(A - 1, idx_s)]

    cand_1 = abs(x_t - x) + abs(x_s - x_t)

    print(min(cand_0, cand_1))

Buggy submission (verdict: Runtime Error):

from bisect import bisect_right

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    # Shrine -> Temple
    idx_s = bisect_right(S, x)
    if abs(S[min(A - 1, idx_s)] - x) > abs(S[max(0, idx_s - 1)] - x):
        x_s = S[max(0, idx_s - 1)]
    else:
        x_s = S[min(A - 1, idx_s)]

    idx_t = bisect_right(T, x_s)
    if abs(T[min(A - 1, idx_t)] - x_s) > abs(T[max(0, idx_t - 1)] - x_s):
        x_t = T[max(0, idx_t - 1)]
    else:
        x_t = T[min(A - 1, idx_t)]

    cand_0 = abs(x_s - x) + abs(x_t - x_s)

    # Temple -> Shrine
    idx_t = bisect_right(T, x)
    if abs(T[min(A - 1, idx_t)] - x) > abs(T[max(0, idx_t - 1)] - x):
        x_t = T[max(0, idx_t - 1)]
    else:
        x_t = T[min(A - 1, idx_t)]

    idx_s = bisect_right(S, x_t)
    if abs(S[min(A - 1, idx_s)] - x_t) > abs(S[max(0, idx_s - 1)] - x_t):
        x_s = S[max(0, idx_s - 1)]
    else:
        x_s = S[min(A - 1, idx_s)]

    cand_1 = abs(x_t - x) + abs(x_s - x_t)

    print(min(cand_0, cand_1))
Problem p03151 (python)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if v < 0]
total = sum(neg)
num = len(neg)

if sum(c) < 0:
    print(-1)
elif num == 0:
    print(0)
else:
    for v in reversed(c[num:]):
        total += v
        num += 1
        if total >= 0:
            break
    print(num)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if c < 0]
total = abs(sum(neg))
num = len(neg)
for i, v in enumerate(reversed(pos(c[num:]))):
    total += v
    if total >= 0:
        break

print(num + i)

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

c = [a[i] - b[i] for i in range(n)]
c.sort()

neg = [v for v in c if c < 0]
total = abs(sum(neg))
num = len(neg)
for i, v in enumerate(reversed(pos(c[num:]))):
    total += v
    if total >= 0:
        break

print(num + i)

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

c = [a[i] - b[i] for i in range(12)]
c.sort()

if sum(c) < 0:
    print(-1)

neg = [v for v in c if c < 0]
pos = [v for v in c if c > 0]
total = abs(sum(neg))

k = 0
for i, v in enumerate(reversed(pos)):
    k += v
    if k >= total:
        break

print(len(neg) + i + 1)
Problem p03244 (python)

Fixed submission:
from collections import Counter

n, *v = map(int, open(0).read().split())
c1 = Counter(v[::2]).most_common()
c2 = Counter(v[1::2]).most_common()

c1.append([0, 0])
c2.append([0, 0])

if c1[0][0] != c2[0][0]:
  print(n - c1[0][1] - c2[0][1])
else:
  print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

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

n, *v = map(int, open(0).read().split())
if v[::2] == v[1::2]:
        print(n // 2)
    else:
        print(n - Counter(v[::2]).most_common()[0][1] - Counter(v[1::2]).most_common()[0][1])
Problem p03262 (python)

Fixed submission:
from fractions import gcd
N, *X = map(int, open(0).read().split())
X.sort()
y = [X[i + 1] - X[i] for i in range(N)]

ans = y[0]
for v in y[1:]:
  ans = gcd(ans, v)
print(ans)

Buggy submission (verdict: Runtime Error):
N, *X = map(int, open(0).read().split())
X.sort()
y = []
for i in range(N):
  y.append(X[i + 1] - X[i])

ans = y[0]
for v in y[1:]:
  ans = gcd(ans, v)
print(ans)
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

ans = []
idx_list = [(i, j) if i % 2 == 0 else (i, W - j - 1) 
            for i in range(H) for j in range(W)]
        
for i, (x, y) in enumerate(idx_list[:-1]):
    if A[x][y] % 2 == 1:
        A[idx_list[i + 1][0]][idx_list[i + 1][1]] += 1
        ans.append([x, y, idx_list[i + 1][0], idx_list[i + 1][1]])
        
print(len(ans))
for v in ans:
    print(*[c + 1 for c in v])

Buggy submission (verdict: Runtime Error):

H, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(H)]
ans = []


def dfs(u, v):
    for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        if 0 <= u + i < H and 0 <= v + j < W and X[u + i][v + j] > 0:
            ans.append((u + 1, v + 1, u + i + 1, v + j + 1))
            X[u + i][v + j] += X[u][v]
            X[u][v] = 0
            dfs(u + i, v + j)


for u in range(H):
    for v in range(W):
        if X[u][v] > 0:
            dfs(u, v)

for t in ans:
    print(*t)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
while S[0] == '1' and len(S) > 1 and K > 1:
    S = S[1:]
    K -= 1
print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
print(S[:K].replace('1', '')[0] or '1')

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == '1' and len(S) > 1:
    while S[0] == '1':
        S = S[1:]
print(S[0])
Problem p03290 (python)

Fixed submission:
D, G = map(int, input().split())
X = [0] + [list(map(int, input().split())) for _ in range(D)]

def func(i, t):
    if i == 0 or i > D:
        return 10 ** 9
    
    # Solve all problems, or part of them
    k = min(t // (100 * i), X[i][0])
    s = 100 * i * k
    
    # If all problems are solved, add bonus
    if k == X[i][0]:
        s += X[i][1]
        
    # If score < objective, go next step
    if s < t:
        k += func(i - 1, t - s)
        
    # Select minimum number of solved problems
    # k: solve i-th line
    # func(i-1,t): pass i-th line
    return min(k, func(i - 1, t))

# Solve backward
print(func(D, G))

Buggy submission (verdict: Runtime Error):
D, G = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(D)]

def func(i, t):
    if i == 0 or i > D:
        return 10 ** 9
    
    # Solve all problems, or part of them
    k = min(t // (100 * i), X[i][0])
    s = 100 * i * k
    
    # If all problems are solved, add bonus
    if k == X[i][0]:
        s += X[i][1]
        
    # If score < objective, go next step
    if s < t:
        k += func(i - 1, t - s)
        
    # Select minimum number of solved problems
    # k: solve i-th line
    # func(i-1,t): pass i-th line
    return min(k, func(i - 1, t))

# Solve backward
print(func(D, G))
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
ans = [s[l:l + r + 1] for l in range(len(s)) for r in range(K)]
print(sorted(set(ans))[K - 1])

Buggy submission (verdict: Runtime Error):
ans = []
for l in range(len(s)):
    for r in range(l + 1, K + 1):
        ans.append(s[l:r])
        
print(sorted(set(ans))[K - 1])
Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
s = ['.' + input() +'.' for _ in range(H)]
s = ['.' * (W + 2)] + s + ['.' * (W + 2)]
flag = True
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if (s[h][w] == '#' and (not '#' in [s[h - 1][w], s[h + 1][w], s[h][w - 1], s[h][w + 1]])):
            flag = False
                
print('Yes' if flag else 'No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = ['.' + input() +'.' for _ in range(H)]
s = ['.'] * (W + 2) s + ['.'] * (W + 2)
flag = True
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if (s[h][w] == '#' and s[h - 1][w] == '.' and s[h + 1][w] == '.'
               and s[h][w - 1] == '.' and s[h][w + 1] == '.'):
            flag = False
                
print('Yes' if flag else 'No')
Problem p03409 (python)

Fixed submission:
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
y = sorted([list(map(int, input().split())) for _ in range(N)])

cnt = 0
for c, d in y:
  for a, b in x:
    if a < c and b < d:
      x.remove([a, b])
      cnt += 1
      break

print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)
y = sorted([list(map(int, input().split())) for _ in range(N)], reverse=True)

i = 0
j = 0
cnt = 0
while j < N:
    if x[i][0] < y[j][0] and x[i][1] < y[j][1]:
        cnt += 1
        i += 1
        j += 1
        continue
    else:
	    i += 1
    if i >= N:
      i = 0
      j += 1
print(cnt)