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

Fixed submission:
t = input()

stack = ''
for i in range(len(t)):
    word = t[i]
    if word == '?':
        next_word = t[i+1] if i < len(t)-1 else None
        if next_word is None:
            word = 'D'
        else:
            if len(stack) <= 0 and next_word == 'P':
                word = 'D'
            elif len(stack) <= 0 and (next_word == 'D' or next_word == '?'):
                word = 'P'
            elif stack[-1] == 'D' and (next_word == '?' or next_word == 'D'):
                word = 'P'
            else:
                word = 'D'

    stack += word
print(stack)

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

stack = ''
for i in range(len(t)):
    word = t[i]
    if word == '?':
        next_word = t[i+1] if i < len(t)-1 else None
        if len(stack) <= 0 and next_word == 'P':
            word = 'D'
        elif len(stack) <= 0 and (next_word == 'D' or next_word == '?'):
            word = 'P'
        elif stack[-1] == 'D' and (next_word == '?' or next_word == 'D'):
            word = 'P'
        else:
            word = 'D'

    stack += word
print(stack)

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

stack = ''
for s in t:
    if s == '?':
        if stack[-1] == 'P':
            s = 'D'
        else:
            s = 'P'

    stack += s
print(stack)
Problem p02823 (python)

Fixed submission:
N, A, B = map(int, input().split())
diff = abs(A - B)

if diff % 2 == 0:
    print(diff // 2)

else:
    n = (diff // 2) + 1 + min(N-B, A-1)
    print(n)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
diff = abs(A - B)

if diff % 2 == 0:
    print(diff // 2)
else:
  prrint(-1)
Problem p02678 (python)

Fixed submission:
n,m = map(int, input().split())
neighbors = {key:[] for key in range(1, n+1)}
answers = {key:0 for key in range(1, n+1)}
answers[1] = 1
for i in range(m):
    a,b = map(int, input().split())
    neighbors[a].append(b)
    neighbors[b].append(a)

def register(hs):
    newhs = []
    for h in hs:
        for i in neighbors[h]:
            if answers[i] == 0:
                answers[i] = h
                newhs.append(i)
    return newhs

hosts = [1]
while True:
    hosts = register(hosts)
    if len(hosts) == 0:
        break

flag = 0
for key, item in answers.items():
    if item == 0:
        flag = 1
if flag == 0:
    print("Yes")
    for key, item in answers.items():
        if key != 1:
            print(item)
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
neighbors = {key:[] for key in range(1, n+1)}
answers = {key:0 for key in range(1, n+1)}
answers[1] = 1
for i in range(m):
    a,b = map(int, input().split())
    neighbors[a].append(b)
    neighbors[b].append(a)
hosts = neighbors[1]
now = 1
def register(hs, n):
    for h in hs:
        if answers[h] == 0:
            answers[h] = n
            register(neighbors[h], h)
register(hosts, now)
flag = 0
for key, item in answers.items():
    if item == 0:
        flag = 1
if flag == 0:
    print("Yes")
    for key, item in answers.items():
        if key != 1:
            print(item)
else:
    print("No")
Problem p02720 (python)

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

def neighbor(a):
    if a == 0:
        return [0,1]
    if a == 9:
        return [8,9]
    return [a-1,a,a+1]

def make_lunlun(digit, start):
    if digit == 1:
        return [start]
    res = []
    for start_neighbor in neighbor(start):
        b = make_lunlun(digit-1, start_neighbor)
        c = list(map(lambda x:x+(start*(10**(digit-1))), b))
        res.extend(c)
    return res
lunlun = []
for i in range(1,11):
    for j in range(1,10):
        lunlun.extend(make_lunlun(i, j))

k = int(input())
print(lunlun[k-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def neighbor(a):
    if a == 0:
        return [0,1]
    if a == 9:
        return [8,9]
    return [a-1,a,a+1]

def make_lunlun(digit, start):
    if digit == 1:
        return [start]
    res = []
    for start_neighbor in neighbor(start):
        b = make_lunlun(digit-1, start_neighbor)
        c = list(map(lambda x:x+(start*(10**(digit-1))), b))
        res.extend(c)
    return res
lunlun = []
for i in range(1,11):
    for j in range(1,10):
        lunlun.extend(make_lunlun(i, j))

k = int(input())
print(lunlun[k-1])


import sys
sys.setrecursionlimit(10**9)

def neighbor(a):
    if a == 0:
        return [0,1]
    if a == 9:
        return [8,9]
    return [a-1,a,a+1]

def make_lunlun(digit, start):
    if digit == 1:
        return [start]
    res = []
    for start_neighbor in neighbor(start):
        b = make_lunlun(digit-1, start_neighbor)
        c = list(map(lambda x:x+(start*(10**(digit-1))), b))
        res.extend(c)
    return res
lunlun = []
for i in range(1,11):
    for j in range(1,10):
        lunlun.extend(make_lunlun(i, j))

k = int(input())
print(lunlun[k-1])
Problem p02744 (python)

Fixed submission:
n = int(input())
ans = []
def dfs(line, mx):
    if len(line) == n:
        ans.append(line)
    else:
        for i in range(mx+1):
            line_copy = line.copy()
            line_copy.append(i)
            dfs(line_copy, mx)
        line_copy = line.copy()
        line_copy.append(mx+1)
        dfs(line_copy, mx+1)

dfs([0], 0)

figures = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

for a in ans:
    for i in a:
        print(figures[i], end="")
    print()

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = []
def dfs(line, mx):
    if len(line) == n:
        ans.append(line)
    else:
        for i in range(mx+1):
            line_copy = line.copy()
            line_copy.append(i)
            dfs(line_copy, mx)
        line_copy = line.copy()
        line_copy.append(mx+1)
        dfs(line_copy, mx+1)

dfs([0], 0)

figures = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

for a in ans:
    for i in a:
        print(figures[i], end="")
    print()
Problem p02850 (python)

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

n = int(input())
neighbors = [[] for i in range(n+1)]
ab = []
for i in range(n-1):
    line = list(map(int, input().split()))
    neighbors[line[0]].append(line[1])
    neighbors[line[1]].append(line[0])
    ab.append((line[0], line[1]))
maximum = 0
neighbors_max = 0
for i in range(n):
    if maximum < len(neighbors[i]):
        neighbors_max = i
        maximum = len(neighbors[i])
edgecolors = {}
reached = {neighbors_max}
def make_other_colors(c, m):
    res = []
    if c > m:
        res += [i+1 for i in range(m)]
    else:
        res += [i+1 for i in range(c-1)]
        res += [maximum-i for i in range(m-c+1)]
    return res
def coloring(v, c):
    if c == 0:
        reached.add(v)
        for i in range(len(neighbors[v])):
            edgecolors[(v, neighbors[v][i])] = i + 1
            edgecolors[(neighbors[v][i], v)] = i + 1
            reached.add(neighbors[v][i])
            coloring(neighbors[v][i], i+1)
        return
    l = len(neighbors[v])
    if l == 1 and neighbors[v][0] in reached:
        reached.add(v)
        return
    other_colors = make_other_colors(c, l-1)
    i = 0
    j = 0
    while i < l:
        if neighbors[v][i] in reached:
            i += 1
            continue
        edgecolors[(v, neighbors[v][i])] = other_colors[j]
        edgecolors[(neighbors[v][i], v)] = other_colors[j]
        reached.add(neighbors[v][i])
        coloring(neighbors[v][i], other_colors[j])
        i += 1
        j += 1
coloring(neighbors_max, 0)
print(maximum)
for i in ab:
    print(edgecolors[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
neighbors = [[] for i in range(n+1)]
ab = []
for i in range(n-1):
    line = list(map(int, input().split()))
    neighbors[line[0]].append(line[1])
    neighbors[line[1]].append(line[0])
    ab.append((line[0], line[1]))
maximum = 0
neighbors_max = 0
for i in range(n):
    if maximum < len(neighbors[i]):
        neighbors_max = i
        maximum = len(neighbors[i])
edgecolors = {}
reached = {neighbors_max}
def make_other_colors(c, m):
    res = []
    if c > m:
        res += [i+1 for i in range(m)]
    else:
        res += [i+1 for i in range(c-1)]
        res += [maximum-i for i in range(m-c+1)]
    return res
def coloring(v, c):
    if c == 0:
        reached.add(v)
        for i in range(len(neighbors[v])):
            edgecolors[(v, neighbors[v][i])] = i + 1
            edgecolors[(neighbors[v][i], v)] = i + 1
            reached.add(neighbors[v][i])
            coloring(neighbors[v][i], i+1)
        return
    l = len(neighbors[v])
    if l == 1 and neighbors[v][0] in reached:
        reached.add(v)
        return
    other_colors = make_other_colors(c, l-1)
    i = 0
    j = 0
    while i < l:
        if neighbors[v][i] in reached:
            i += 1
            continue
        edgecolors[(v, neighbors[v][i])] = other_colors[j]
        edgecolors[(neighbors[v][i], v)] = other_colors[j]
        reached.add(neighbors[v][i])
        coloring(neighbors[v][i], other_colors[j])
        i += 1
        j += 1
coloring(neighbors_max, 0)
print(maximum)
for i in ab:
    print(edgecolors[i])
Problem p02910 (python)

Fixed submission:
S = input()
l = len(S)
s = list(S)
c = 0
s.append("U")

for i in range(-(-l//2)):
    d = 2*i
    if s[d] == "L":
        print("No")
        c = 1
        break
    if s[d+1] == "R":
        print("No")
        c = 1
        break
if c == 0:
    print("Yes")

Buggy submission (verdict: Runtime Error):
c = 0
s.append("U")

for i in range(-(-l//2)):
    d = 2*i
    if s[d] == "L":
        print("No")
        c = 1
        break
    if s[d+1] == "R":
        print("No")
        c = 1
        break
if c == 0:
    print("Yes")
Problem p02995 (python)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
div_c = b//c + (-a//c) + 1
div_d = b//d + (-a//d) + 1
div_cd = b//(c*d//fractions.gcd(c, d)) + (-a//(c*d//fractions.gcd(c,d))) + 1
print(b-a+1 - div_c - div_d + div_cd)

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
div_c = b//c + (-a//c) + 1
div_d = b//d + (-a//d) + 1
div_cd = b//(c*d//math.gcd(c, d)) + (-a//(c*d//math.gcd(c,d))) + 1
print(b-a+1 - div_c - div_d + div_cd)
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l = list(map(int,input().split()))
pos = 0
count = 0
i=0
while pos <= x and i < n:
    pos += l[i]
    count += 1
    i += 1
if i == n and pos <= x:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int,input().split()))
pos = 0
count = 0
i=0
while pos <= x and i <= n:
    pos += l[i]
    count += 1
    i += 1
print(count)
Problem p02995 (python)

Fixed submission:
def gcd(x, y):
  if y == 0:
    return x
  else:
    x %= y
    x, y = y, x
    return gcd(x, y)

a, b, c, d = map(int, input().split())

x = c * d // gcd(c, d)

t1 = b // c
t2 = (a - 1) // c
u1 = b // d
u2 = (a - 1) // d
v1 = b // x
v2 = (a - 1) // x

ans = (b - a + 1) - (t1 - t2) - (u1 - u2) + (v1 - v2)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())

x = c * d // math.gcd(c, d)

t1 = b // c
t2 = (a - 1) // c
u1 = b // d
u2 = (a - 1) // d
v1 = b // x
v2 = (a - 1) // x

ans = (b - a + 1) - (t1 - t2) - (u1 - u2) + (v1 - v2)
print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())

print(n * (n - 1) // 2)

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

ans = 0
for i in range(len(n)):
  ans += i
  
print(ans)
Problem p02936 (python)

Fixed submission:
import collections

n, q = map(int, input().split())
cnt = [0] * (n + 1)

# adjacency list for tree graph
g = [[] for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

# calc cnt
for _ in range(q):
    v, val = map(int, input().split())
    cnt[v] += val

q = collections.deque()
q.append(1)
checked = [0] * (n + 1)

while q:
    v = q.pop()
    checked[v] = 1
    for u in g[v]:
        if checked[u] == 1:
            continue
        cnt[u] += cnt[v]
        q.append(u)
print(*cnt[1:])

Buggy submission (verdict: Runtime Error):
# グラフ木累積和
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
ans = [0] * n

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

def dfs(v, p=-1):
    for u in tree[v]:
        # 親には戻らないようにする
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

dfs(0)
print(*ans)
Problem p02947 (python)

Fixed submission:
def cmb(n, r):
    if n == 1: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
S = [input() for _ in range(n)]
S_sorted = ["".join(sorted(s)) for s in S]
S_sorted = sorted(S_sorted)

ans = 0
cnt = 1
for i in range(1, len(S_sorted)):
    if S_sorted[i] == S_sorted[i-1]:
        cnt += 1
    else:
        ans += cmb(cnt, 2)
        cnt = 1

if cnt > 1:
    ans += cmb(cnt, 2)

print(int(ans))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

n = int(input())
S = [input() for _ in range(n)]
S_sorted = ["".join(sorted(s)) for s in S]
S_sorted = sorted(S_sorted)

ans = 0
cnt = 1
for i in range(1, len(S_sorted)):
    if S_sorted[i] == S_sorted[i-1]:
        cnt += 1
    else:
        ans += comb(cnt, 2, exact=True)
        cnt = 1

if cnt > 1:
    ans += comb(cnt, 2, exact=True)

print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

n = int(input())
S = [input() for _ in range(n)]
S_sorted = ["".join(sorted(s)) for s in S]
S_sorted = sorted(S_sorted)

ans = 0
cnt = 1
for i in range(1, len(S_sorted)):
    if S_sorted[i] == S_sorted[i-1]:
        cnt += 1
    else:
        ans += comb(cnt, 2, exact=True)
        cnt = 1

if cnt > 1:
    ans += comb(cnt, 2, exact=True)

print(ans)
Problem p02988 (python)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
 
ans = 0
for i in range(1, n - 1):
  if l[i - 1] < l[i] and l[i] < l[i + 1]:
    ans += 1
  elif l[i + 1] < l[i] and l[i] < l[i - 1]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
 
ans = 0
for i in range(1, n - 1):
  if l[i - 1] < l[i] and l[i] < l[i + 1]:
    ans += 1
  elif l[i + 1] < l[i] and l[i] < l[i - 1]:
 	ans += 1
print(ans)
Problem p02995 (python)

Fixed submission:
import fractions


a, b, c, d = list(map(int, input().split()))

def lcm(x, y):
    return x * y // fractions.gcd(x, y)

def get_num(x):
    ans = x - x // c - x // d + x // lcm(c, d)
    return ans


print(get_num(b) - get_num(a -1))

Buggy submission (verdict: Runtime Error):
import math


a, b, c, d = list(map(int, input().split()))

def lcm(x, y):
    return x * y // math.gcd(x, y)

def get_num(x):
    ans = x - x // c - x // d + x // lcm(c, d)
    return ans


print(get_num(b) - get_num(a -1))
Problem p03037 (python)

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

for _ in range(m):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)

l_max = max(ls)
r_min = min(rs)
master_card_num = r_min - l_max

if master_card_num < 0:
    print(0)
else:
    print(master_card_num + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ls = []
rs = []

for _ in range(m):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)

l_max = max(l)
r_min = min(r)
master_card_num = r_min - l_max

if master_card_num < 0:
    print(0)
else:
    print(master_card_num + 1)
Problem p03087 (python)

Fixed submission:
n, q = list(map(int, input().split()))
s = input()
ran = [list(map(int, input().split())) for i in range(q) ]

table = [0] * n
for i in range(1, n):
    if s[i] == "C" and s[i-1] == "A":
        table[i] = table[i - 1] + 1
    else:
        table[i] = table[i - 1]

for l, r in ran:
    print(table[r-1]  - table[l - 1] )

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
q_l = [tuple(map(int, input().split())) for _ in range(q)]

accum_sum = [0] * (len(s)+1)

for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        accum_sum[i+1] = accum_sum[i] + 1
    else:
        accum_sum[i+1] = accum_sum[i]

for l, r in q_l:
    print(accum_sum[r-1]-accum_sum[l-1])
Problem p03106 (python)

Fixed submission:
a, b, k = list(map(int, input().split()))
 
ans_l = []
for num in range(1, min(a, b) + 1):
  if a % num == 0 and b % num == 0:
    ans_l.append(num)


print(ans_l[-k])

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

ans_l = []
for num in range(min(a, b)):
  if a % num == 0 and b % num == 0:
    ans_l.append(num)

sorted(ans_l)

print(ans_l[-k])
Problem p03167 (python)

Fixed submission:
h, w = map(int, input().split())
field = [input() for _ in range(h)]
MOD = 10 ** 9 + 7

dp = [[0] * w for _ in range(h)]
dp[0][0] = 1

for i in range(1, w):
    if field[0][i] == ".":
        dp[0][i] = dp[0][i-1] 

for i in range(1, h):
    if field[i][0] == ".":
        dp[i][0] = dp[i-1][0]

for row in range(1, h):
    for col in range(1, w):
        if field[row][col] == ".":
            dp[row][col] = (dp[row-1][col] + dp[row][col-1]) % MOD
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
field = [input() for _ in range(h)]
MOD = 10 ** 9 + 7

dp = [[0] * w for _ in range(h)]
dp[0][0] = 1

for i in range(1, w):
    if field[0][i] == ".":
        dp[0][i] = dp[0][i-1] 

for i in range(1, h):
    if field[i][0] == ".":
        dp[i][0] = dp[i-1][0]

for row in range(1, h):
    for col in range(1, w):
        if field[i][j] == ".":
            dp[i][j] = dp[i-1][j] + dp[i][j-1]
print(dp[-1][-1])
Problem p03238 (python)

Fixed submission:
age = int(input())

if age == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

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

if age == 1:
    print("Hello World")
    exit(1)
else:
    a = int(input())
    b = int(input())
    print(a+b)
Problem p03285 (python)

Fixed submission:
import sys


n = int(input())

for i in range(100):
    for j in range(100):
        if i * 4 + j * 7 == n:
            print("Yes")
            sys.exit()
print("No")

Buggy submission (verdict: Runtime Error):
import sys


n = int(input())

for i in range(100):
    for j in range(100):
        if i * 4 + j * 7 == n:
            print("Yes")
            sys.exit(1)
print("No")
Problem p02714 (python)

Fixed submission:
import sys
import collections

N = int(input())
S = [ch for ch in input()]
counter = collections.Counter(S)
if len(counter.keys()) != 3:
    print(0)
    sys.exit()
total = 1
for k, v in counter.items():
    total *= v

for i in range(len(S)):
    l, r = i - 1, i + 1
    while 0 <= l and r < len(S):
        if len(set([S[i], S[l], S[r]])) == 3:
            total -= 1
        l -= 1
        r += 1
print(total)

Buggy submission (verdict: Runtime Error):
import sys
import collections

N = int(input())
S = [ch for ch in input()]
counter = collections.Counter(S)
if len(counter.keys()) != 3:
    print(0)
    eys.exit()
total = 1
for k, v in counter.items():
    total *= v

for i in range(len(S)):
    l, r = i - 1, i + 1
    while 0 <= l and r < len(S):
        if len(set([S[i], S[l], S[r]])) == 3:
            total -= 1
        l -= 1
        r += 1
print(total)
Problem p02732 (python)

Fixed submission:
# 解き直し
import collections

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)

total = 0
for v in c.values():
    total += v * (v - 1) // 2

for k_ball in A:
    cnt = c[k_ball]
    print(total - (cnt * (cnt - 1) // 2) + ((cnt - 1) * (cnt - 2) // 2))

Buggy submission (verdict: Runtime Error):
import collections
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
memo = {}
ans = 0
for k, v in c.items():
    if v > 1:
        memo[v] = combinations_count(v, 2)
        ans += memo[v]
total_ans = ans
for i in range(N):
    k_ball = A[i]
    if c[k_ball] > 2:
        if k_ball - 1 in set(memo.keys()):
            print(int(total_ans - (memo[c[k_ball]] - memo[c[k_ball - 1]])))
        else:
            print(
                int(
                    total_ans - (memo[c[k_ball]] - combinations_count(c[k_ball] - 1, 2))
                )
            )
    elif c[k_ball] > 1:
        print(total_ans - 1)
    else:
        print(total_ans)
Problem p02787 (python)

Fixed submission:
# 解き直し
H, N = map(int, input().split())
A_to_minB = {}
max_A = -1
for i in range(N):
    a, b = map(int, input().split())
    max_A = max(max_A, a)
    if a not in set(A_to_minB.keys()):
        A_to_minB[a] = b
    else:
        A_to_minB[a] = min(A_to_minB[a], b)
dp = [float("inf")] * (H + max_A)
dp[0] = 0
for i in range(1, H+max_A):
    tmp = [dp[i-a]+b for a, b in A_to_minB.items() if a<=i]
    if tmp:
        dp[i] = min(tmp)
print(min(dp[H:H+max_A]))

Buggy submission (verdict: Runtime Error):
# 解き直し
H, N = map(int, input().split())
A_to_minB = {}
max_A = -1
for i in range(N):
    a, b = map(int, input().split())
    max_A = max(max_A, a)
    if a not in set(A_to_minB.keys()):
        A_to_minB[a] = b
    else:
        A_to_minB[a] = min(A_to_minB[a], b)
dp = [float("inf")] * (H + max_A)
dp[0] = 0
for i in range(1, H+N):
    tmp = [dp[i-a]+b for a, b in A_to_minB.items() if a<=i]
    if tmp:
        dp[i] = min(tmp)
print(min(dp[H:H+max_A]))
Problem p02797 (python)

Fixed submission:
N, K, S = map(int, input().split())
ans = [S] * K 
if S != 10**9:
    ans += [S+1] * (N-K)
else:
    ans += [1] * (N-K)
print(' '.join([str(x) for x in ans]))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
ans = [str(S)] * K + [str(S//(N-K)+1)] * (N-K)
print(' '.join(ans))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
ans = [S] * K + [S//(N-K)+1] * (N-K)
print(ans)
Problem p03014 (python)

Fixed submission:
import numpy as np
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'

#上下左右方向に塗られるマスの数を格納する配列
up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
 
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)

Buggy submission (verdict: Runtime Error):
import numpy as np
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'

#上下左右方向に塗られるマスの数を格納する配列
up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
 
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)
Problem p03161 (python)

Fixed submission:
import numpy as np

N, K = map(int, input().split(' '))
h = np.array(list(map(int, input().split(' '))))
dp = np.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
if len(h) == 0:
    return 0
dp = [0] + [float('inf')]*(len(h)-1)
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
print(dp[-1])