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

Fixed submission:
inf = 10 ** 18
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [inf] * (h + max_a)
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = min(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))
Problem p02803 (python)

Fixed submission:
def bfs(start, maze, visited):
    queue = [start]
    visited[start[0]][start[1]] = True
    dist = {(start[0], start[1]): 0}
    max_dist = 0
    while queue:
        y, x = queue.pop(0)
        for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            x_, y_ = x + i, y + j
            if y_ >= 0 and y_ < h and x_ >= 0 and x_ < w and maze[y_][x_] == "." and not visited[y_][x_]:
                queue.append((y_, x_))
                visited[y_][x_] = True
                dist[y_, x_] = dist[y, x] + 1
                max_dist = max(max_dist, dist[y_, x_])
    return max_dist


h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
max_dist = 0
for sy in range(h):
    for sx in range(w):
        if maze[sy][sx] == ".":
            visited = [[False for _ in range(w)] for _ in range(h)]
            max_dist = max(max_dist, bfs((sy, sx), maze, visited))
print(max_dist)

Buggy submission (verdict: Runtime Error):
def bfs(start, maze, visited):
    queue = [start]
    visited[start[0]][start[1]] = True
    dist = {(start[0], start[1]): 0}
    max_dist = 0
    while queue:
        y, x = queue.pop(0)
        for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            x_, y_ = x + i, y + j
            if y_ >= 0 and y_ < h and x_ >= 0 and x_ < w and maze[y_][x_] == "." and not visited[y_][x_]:
                queue.append((y_, x_))
                visited[y_][x_] = True
                dist[y_, x_] = dist[y, x] + 1
                max_dist = max(max_dist, dist[y_, x_])
    return max_dist


h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
max_dist = 0
for sy in range(h):
    for sx in range(w):
        if maze[sy][sx] == "." and maze[gy][gx] == ".":
            visited = [[False for _ in range(w)] for _ in range(h)]
            max_dist = max(max_dist, bfs((sy, sx), maze, visited))
print(max_dist)
Problem p02850 (python)

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

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


num_children = -1


def dfs(graph, cur, parent, num_children):
    if 0 == len(graph[cur]):
        return num_children
    num_edges = len(graph[cur])
    if not (None == parent):
        num_edges += 1
    num_children = max(num_children, num_edges)
    for child in graph[cur]:
        num_children = dfs(graph, child[0], cur, num_children)
    return num_children


def dfs_color(graph, cur, parent_edge_color, num_colors):
    color = 0
    for child in graph[cur]:
        if parent_edge_color == color:
            color += 1
        colors[child[1]] = color+1
        dfs_color(graph, child[0], color, num_colors)
        color += 1


num_children = dfs(graph, 0, None, num_children)
dfs_color(graph, 0, -1, num_children)
print(num_children)
for color in colors:
    print(color)

Buggy submission (verdict: Runtime Error):
n = int(input())
graph = [[] for _ in range(n)]
colors = [-1 for _ in range(n-1)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    graph[a].append([b, i])


num_children = -1


def dfs(graph, cur, parent, num_children):
    if 0 == len(graph[cur]):
        return num_children
    num_edges = len(graph[cur])
    if not (None == parent):
        num_edges += 1
    num_children = max(num_children, num_edges)
    for child in graph[cur]:
        num_children = dfs(graph, child[0], cur, num_children)
    return num_children


def dfs_color(graph, cur, parent_edge_color, num_colors):
    color = 0
    for child in graph[cur]:
        if parent_edge_color == color:
            color += 1
        colors[child[1]] = color+1
        dfs_color(graph, child[0], color, num_colors)
        color += 1


num_children = dfs(graph, 0, None, num_children)
dfs_color(graph, 0, -1, num_children)
print(num_children)
for color in colors:
    print(color)
Problem p02882 (python)

Fixed submission:
import math
(a, b, x) = map(int, input().split())

theta = 0
if x < (a ** 2) * b / 2:
    theta = math.pi / 2 - math.atan(2 * x / a / b ** 2)
else:
    if a ** 2 * b == x:
        theta = 0
    else:
        theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)

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

theta = 0
if x < (a ** 2) * b / 2:
  theta = math.pi / 2 - math.atan(2 * x / a / b ** 2)
else:
  theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)

Buggy submission (verdict: Runtime Error):
import math
(a, b, x) = map(int, input().split())
theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)
Problem p02911 (python)

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

for i, answer in enumerate(a):
    points[answer-1] += 1

for i, p in enumerate(points):
    result = "Yes" if k - q + p > 0 else "No"
    print(result)

Buggy submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
a = []
for i in range(q):
    a[i] = int(input()) - 1
score = [0 for _ in range(n)]

for a_i in a:
    score[a_i] += 1

for i in range(n):
    result = k - q + score[i]
    print("Yes" if result > 0 else "No")

Buggy submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
a = []
for i in range(q):
    a[i] = int(input()) - 1
score = [0 for _ in range(n)]

for a_i in a:
    score[a_i] += 1

for i in range(n):
    result = k - q + score[i]
    print("YES" if result > 0 else "NO")
Problem p02947 (python)

Fixed submission:
n = int(input())
s = [sorted(input()) for _ in range(n)]
sorted_s = sorted(s)

num = 0
num_same = 1
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += int(num_same * (num_same - 1) / 2)
        num_same = 1
        prev = sorted_s[i]
    else:
        num_same += 1
num += int(num_same * (num_same - 1) / 2)
print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for _ in range(n)]


def is_anagram(s_i, s_j):
    for k in range(10):
        found = False
        for l in range(10):
            if s_i[k] == s_j[l]:
                found = True
                break
        if not found:
            return False
    return True


num = 0
for i in range(n):
    for j in range(i + 1, n):
        if i == j:
            continue
        if is_anagram(s[i], s[j]):
            num += 1
            records[i].append(j)
print(num)
Problem p03044 (python)

Fixed submission:
from collections import deque

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    (u, v, w) = map(int, input().split())
    graph[u-1].append([v-1, w])
    graph[v-1].append([u-1, w])


q = deque()
ans = [-1 for _ in range(n)]
q.append(0)
ans[0] = 0
while 0 != len(q):
    v = q.popleft()
    for neigbhor in graph[v]:
        u = neigbhor[0]
        w = neigbhor[1]
        if -1 != ans[u]:
            continue
        ans[u] = (ans[v] + w) % 2
        q.append(u)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
"""
dfs活用問題
- 2部グラフ作成
- https://atcoder.jp/contests/abc126/tasks/abc126_d
"""
from collections import deque

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    (u, v, w) = map(int, input().split())
    graph[u-1].append([v-1, w])
    graph[v-1].append([u-1, w])


def dfs_recursive(n, graph):
    def dfs(graph, colors, cur, depth):
        colors[cur] = depth % 2
        for child in graph[cur]:
            child_index = child[0]
            if -1 != colors[child_index]:
                continue
            dfs(graph, colors, child_index, depth + child[1])
    colors = [-1 for _ in range(n)]
    dfs(graph, colors, 0, 0)
    for i in colors:
        print(i)


def dfs_with_queue(n, grpah):
    q = deque()
    ans = [-1 for _ in range(n)]
    q.append(0)
    ans[0] = 0
    while 0 != len(q):
        v = q.popleft()
        for neigbhor in graph[v]:
            u = neigbhor[0]
            w = neigbhor[1]
            if -1 != ans[u]:
                continue
            ans[u] = (ans[v] + w) % 2
            q.append(u)
        for i in ans:
            print(i)


dfs_recursive(n, graph)
Problem p03111 (python)

Fixed submission:
"""
できなかった

- 操作 = 四則演算 or 関数
- 交換法則などが成り立つかどうか確認する必要がある
- 再帰的(dfs)に実装する場合、何を初期値として終了条件とするかの理解が必要
  - 前提として全探索であること => 1の解に収束する必要がない
    全ての葉を訪れたときに最小・最大値・解への到達が判定できれば良い

- dfsの実装: いまどの高さにいるかを引数として渡す = 何を高さとして定義するか
  - 階層のインデックスは選択可能な配列のインデックス
  - 同階層のノードは選択肢
  - ノードが持つ値は、その選択をした時の合計の値
  - 終了条件A, B, Cを満たす

- 求める長さA, B, Cの竹 -> 選択肢

"""
(N, A, B, C) = map(int, input().split())
l = [int(input()) for _ in range(N)]


def dfs(index, a, b, c):
    if N == index:
        if 0 < min(a, b, c):
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return 10 ** 9
    costs = []
    costs.append(dfs(index + 1, a, b, c))
    costs.append(dfs(index + 1, a + l[index], b, c) + 10)
    costs.append(dfs(index + 1, a, b + l[index], c) + 10)
    costs.append(dfs(index + 1, a, b, c + l[index]) + 10)
    return min(costs)


print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
ｖn, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
inf = 10 ** 18


def dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print(dfs(0, 0, 0, 0))
Problem p03126 (python)

Fixed submission:
(n, m) = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
    a[-1].pop(0)

score = [0 for _ in range(m)]
for i in a:
    for food_index in i:
        score[food_index - 1] += 1
print(score.count(n))

Buggy submission (verdict: Runtime Error):
(n, m) = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

score = [0 for _ in range(m)]
for i in a:
    for food_index in range(1, len(i)):
        if 0 >= food_index:
            continue
        score[i[food_index - 1]] += 1
print(score.count(n))

Buggy submission (verdict: Runtime Error):
(n, m) = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

score = [0 for _ in range(m)]
for i in a:
    for food_index in range(1, len(i)):
        score[i[food_index - 1]] += 1
print(score.count(n))
Problem p03160 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
dp = [float('INF') for _ in range(n)]
for i in range(n):
    if 0 == i:
        dp[i] = 0
    elif 1 == i:
        dp[i] = abs(h[i-1] - h[i])
    else:
        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]),
                    dp[i-2] + abs(h[i-2] - h[i]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
dp = [10 ** 18 for _ in range(n)]
dp = [0]
for i in range(1, n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),
                dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
dp = [0 for _ in range(n)]

def f(cur, prev1, prev2, dp):
    if len(dp) == cur:
        return
    prev1_cost = 100000000 if prev1 < 0 else dp[prev1] + abs(h[cur] - h[prev1])
    prev2_cost = 100000000 if prev2 < 0 else dp[prev2] + abs(h[cur] - h[prev2])
    dp[cur] = prev1_cost if prev1_cost < prev2_cost else prev2_cost
    f(cur + 1, prev1 + 1, prev2 + 1, dp)

f(1, 0, -1, dp)
print(dp[-1])
Problem p03164 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    INF = 10**10
    VMAX=10**3*N
    dp=[[INF for j in range(VMAX+1)] for i in range(N+1)]
    dp[0][0] = 0
    for i in range(1,N+1):
        for j in range(VMAX+1):
            if j-v[i-1] >=0:
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1])
            else:
                dp[i][j] = dp[i-1][j]

    for i in range(VMAX,-1,-1):
        if dp[-1][i] <= W:
            print(i)
            break
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
v_max = 10 ** 3
w_max = 10 ** 18
dp = [[w_max for _ in range(v_max + 1)] for _ in range(n + 1)]
dp[0][0] = 0

for i in range(1, n + 1):
    for j in range(v_max + 1):
        if 0 == j:
            dp[i][j] = 0
        else:
            w_ = wv[i-1][0]
            v_ = j - wv[i-1][1]
            if v_ >= 0:
                dp[i][j] = min(dp[i-1][v_] + w_, dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]


for i in range(len(dp[-1]), -1, -1):
    if dp[-1][i] <= w:
        print(i)
        exit(0)
Problem p04030 (python)

Fixed submission:
s = input()
result = []
for i in range(len(s)):
  if 'B' == s[i]:
    if 0 == len(result):
      pass
    else:
      result.pop()
  else:
    result.append(s[i])    
print("".join(result))

Buggy submission (verdict: Runtime Error):
s = input()
result = []
for i in range(len(s)):
  if '0' == i[s]:
    result.append(0)
  elif '1' == i[s]:
    result.append(1)
  elif 'B' == i[s]:
    if 0 == len(result):
      pass
    else:
      result.pop()
print(result)
Problem p02632 (python)

Fixed submission:
k=int(input())
s=input()
ans=0
mod=1000000007
x=2200000
fact=[0]*x
invfact=[0]*x
fact[0]=1
for i in range(1,x):
    fact[i]=fact[i-1]*i%mod
invfact[x-1]=pow(fact[x-1],mod-2,mod)
for i in range(x-2,-1,-1):
    invfact[i]=invfact[i+1]*(i+1)%mod
def nCk(n,k):
    return(fact[n]*invfact[k]*invfact[n-k])%mod
for i in range(0,k+1):
    # print(nCk(len(s)+i-1,i),pow(25,i,mod),pow(26,k-i,mod))
    ans+=nCk(len(s)+i-1,i)*pow(25,i,mod)*pow(26,k-i,mod)
print(ans%mod)

Buggy submission (verdict: Runtime Error):
k=int(input())
s=input()
ans=0
mod=1000000007
x=220000
fact=[0]*x
invfact=[0]*x
fact[0]=1
for i in range(1,x):
    fact[i]=fact[i-1]*i%mod
invfact[x-1]=pow(fact[x-1],mod-2,mod)
for i in range(x-2,-1,-1):
    invfact[i]=invfact[i+1]*(i+1)%mod
def nCk(n,k):
    return(fact[n]*invfact[k]*invfact[n-k])%mod
for i in range(0,k+1):
    # print(nCk(len(s)+i-1,i),pow(25,i,mod),pow(26,k-i,mod))
    ans+=nCk(len(s)+i-1,i)*pow(25,i,mod)*pow(26,k-i,mod)
print(ans%mod)
Problem p02658 (python)

Fixed submission:

a=int(input())
b=list(map(int, input().split()))
c=1
d=0
if 0 in b:
    print(0)
    exit()
for i in range(a):
    c*=b[i]
    if c>10**18:
        print(-1)
        exit()


print(c)

Buggy submission (verdict: Runtime Error):

a=int(input())
b=list(map(int, input().split()))
c=1
if 0 in b:
    d=1
for i in range(a):
    c*=b[i]
    if d!=1 and c>10**18:
        print(-1)
        exit()


print(c)
Problem p02684 (python)

Fixed submission:

n,k=map(int,input().split())
a=list(map(int, input().split()))
b=[1]
ba={1}
c=0
m=0
# while flag==1:
for i in range(n):
    if a[m] not in ba:
        b.append(a[m])
        ba.add(a[m])
        c+=1
        m=a[m]-1
    else:
        e=a[m]
        break
# print(b,e,c+1)
e=b.index(e)
# print(b,e)
bc=b
b=b[e:c+1]
f=c+1-e
if c>k:
    if c-1>=k:

        print(bc[k])
        exit()
if 1 not in b:
    # print(b,f)
    ans=(k-e)%f
    print(b[ans])
else:

    ans=k%f
    print(b[ans])

Buggy submission (verdict: Runtime Error):

n,k=map(int,input().split())
a=list(map(int, input().split()))
b=[1]
ba={1}
c=0
m=0
# while flag==1:
for i in range(n):
    if a[m] not in ba:
        b.append(a[m])
        ba.add(a[m])
        c+=1
        m=a[m]-1
    else:
        e=a[m]
        break
# print(b,e,c+1)
e=b.index(e)
# print(b,e)
b=b[e:c+1]
f=c+1-e
if c>k:
    if c-1>=k:

        print(b[k])
        exit()
if 1 not in b:
    # print(b,f)
    ans=(k-e)%f
    print(b[ans])
else:

    ans=k%f
    print(b[ans])

Buggy submission (verdict: Runtime Error):

n,k=map(int,input().split())
a=list(map(int, input().split()))
b=[1]
ba={1}
c=0
m=0
# while flag==1:
for i in range(n):
    if a[m] not in ba:
        b.append(a[m])
        ba.add(a[m])
        c+=1
        m=a[m]-1
    else:
        e=a[m]
        break
# print(b,e,c+1)
e=b.index(e)
# print(b,e)
b=b[e:c+1]
f=c+1-e
if n>k:
    print(b[k])
    exit()
if 1 not in b:
    ans=(k-e)%f
    print(b[ans])
else:
    # print(b,f)
    ans=k%f
    print(b[ans])
Problem p02702 (python)

Fixed submission:
s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
f=1
s= ''.join(list(reversed(s)))
for i in s:
    e+=int(i)*f
    g=e%2019
    c[g]+=1
    f*=10
    f%=2019
e = sum(i * (i - 1) // 2 for i in c)
print(e)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
for i in range(m-1,-1,-1):
    a=str(a)
    a=int(s[i]+a)
    d=a%2019
    c[d]=c[d]+1
e = sum(i * (i - 1) // 2 for i in c)
print(e)
Problem p02765 (python)

Fixed submission:
a = input().split()
a=[int(i) for i in a]
n,r=a[0],a[1]
if n>=10:
    b=r
else:
    b=r+1000-100*n
print(b)

Buggy submission (verdict: Runtime Error):
ink= input().split()
ink=[int(i) for i in ink]
in1=ink[0]
in2=ink[1]
in3=ink[2]

def nibun(a,e,h):
    #a=int(input("何乗？"))
    b=2#何進法でもできるようにする予定だった
    c=[]
    d=0
    while d==0:
        for i in range(999):
            if b**i<=a and a<b**(i+1):
                c.append(1)
                d=i

    a=a-b**d
    for x in range(d-1,-1,-1):
        if b**(x)<=a:
            a=a-(b**x)
            c.append(1)
        else:
            c.append(0)
        d=d-1
    #print(c)

    #e=int(input("何を？"))
    f=1
    g=0
    #h=int(input("mod?"))#mod
    j=1
    for i in range(len(c)-1,-1,-1):
        j=e
        if c[i]==1:
            for x in range(g):
                j=j*j%h
            f=f*j%h
        g=g+1
    return f
f=nibun(in1,2,10**9+7)

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

######################################################
p=10**6

#pは素数とする

#fact[i] : i! modp (0<= i <p) O(p)
fact = [1]
k = 1
for i in range(1,p):
    k = k*i%p
    fact.append(k)


#n! = a p^eとしたときのeを求める (O(logp n)
def mod_e(n,p):
    res = 0
    while n >= p:
        res += n//p
        n = n//p
    return res

#n! = a p^eとしたときのa mod pを求める  (O(logp n)
def mod_fact(n,p):
    if n==0:
        return 1


    res = mod_fact(n//p,p)

    if n//p %2 != 0:
        return res*(p-fact[n%p])%p
    return res*fact[n%p]%p

######################################################

#nCk mod p
def mod_comb(n,k,p):
    if n < 0 or k < 0 or n<k:
        return 0
    e1 = mod_e(n,p)
    e2 = mod_e(k,p)
    e3 = mod_e(n-k,p)
    #pで割り切れる場合
    if e1 > e2 + e3:
        return 0

    #pで割り切れない場合
    a1 = mod_fact(n,p)
    a2 = mod_fact(k,p)
    a3 = mod_fact(n-k,p)
    return a1 * mod_inv(a2*a3%p,p) %p

p =10**9+7

#fact[i] : i! modp (0<= i <p) O(p)
#上だとO(p)なのでnまでにして O(n)にする
fact = [1]
k = 1
for i in range(1,10**5+1):
    k = k*i%p
    fact.append(k)

#10000C4000 mod 10**9+7

j=mod_comb(in1,in2,p)
k=mod_comb(in1,in3,p)
x=(f-1-j-k)
print(x)
Problem p02630 (python)

Fixed submission:
N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())

N_list=[0]*(100001)
sumn=0

for a in a_list:
    N_list[a]+=1
    sumn+=a


for i in range(Q):
    b,c=map(int,input().split())
    henka=(c-b)*N_list[b]

    sumn+=henka

    N_list[c]+=N_list[b]
    N_list[b]=0

    print(sumn)

Buggy submission (verdict: Runtime Error):
N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())

N_list=[0]*(10001)
sumn=0

for a in a_list:
    N_list[a]+=1
    sumn+=a


for i in range(Q):
    b,c=map(int,input().split())
    henka=(c-b)*N_list[b]

    sumn+=henka

    N_list[c]+=N_list[b]
    N_list[b]=0

    print(sumn)

Buggy submission (verdict: Runtime Error):
N=int(input())
a_list=list(map(int,input().split()))
Q=int(input())

N_list=[0]*(N+1)
sumn=0

for a in a_list:
    N_list[a]+=1
    sumn+=a


for i in range(Q):
    b,c=map(int,input().split())
    henka=(c-b)*N_list[b]

    sumn+=henka

    N_list[c]+=N_list[b]
    N_list[b]=0

    print(sumn)
Problem p02783 (python)

Fixed submission:
H,A = map(int,input().split())

N=0
while H > 0:
    N+=1
    H-=A

print(N)

Buggy submission (verdict: Runtime Error):
import math

H,N=map(int,input().split())
A_list=[]
B_list=[]
for i in range(N):
    A,B=map(int,input().split())
    A_list.append(A)
    B_list.append(B)

amax=max(A_list)

inf=float('inf')
dp=[0]+[inf]*(H+amax)

for i in range(N):
    A=A_list[i]
    B=B_list[i]
    if A > H and B<dp[-1]:
        dp[-1]=B
        continue

    for j in range(A,1+H):
        if dp[j-A]+B<dp[j]:
            dp[j]=dp[j-A]+B
    
    minA=min(dp[H-A:])+B
    if minA < dp[-1]:
        dp[-1]=minA

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import math
import copy
H,N=map(int,input().split())

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

for i in range(N):
    A,B=map(int,input().split())
    ndp=copy.deepcopy(dp)
    for j in range(A,H+1):
        ndp[j]=min(ndp[j-A]+B,dp[j])

        if j > H-A:
            ndp[-1]=min(ndp[-1],ndp[j]+B)

    dp=ndp

print(dp[-1])