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

Fixed submission:
# ABC075B - Minesweeper
h, w = list(map(int, input().rstrip().split()))
lst = [list(input().rstrip()) for _ in range(h)]
emp_lst = ["."] * (w + 2)

for i in lst:
    i.append(".")
    i.insert(0, ".")

lst.append(emp_lst)
lst.insert(0, emp_lst)

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if lst[i][j] == ".":
            count = 0
            if lst[i - 1][j - 1] == "#":
                count += 1
            if lst[i - 1][j] == "#":
                count += 1
            if lst[i - 1][j + 1] == "#":
                count += 1
            if lst[i][j - 1] == "#":
                count += 1
            if lst[i][j + 1] == "#":
                count += 1
            if lst[i + 1][j - 1] == "#":
                count += 1
            if lst[i + 1][j] == "#":
                count += 1
            if lst[i + 1][j + 1] == "#":
                count += 1
            lst[i][j] = count

for i in range(1, h + 1):
    for j in range(1, w + 1):
        print(lst[i][j], end="")
    print()

Buggy submission (verdict: Runtime Error):
# ABC075B - Minesweeper
def check_neighbors(i: int, j: int) -> int:
    # count the number of landmines adjacent to S[i][j]
    ret = 0
    for x, y in neighbors:
        a, b = i + x, j + y
        if 0 <= a < H and 0 <= b < W:
            ret += 1 if S[a][b] == "#" else 0
    return ret


def main():
    global S, neighbors
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    neighbors = [(-1, -1), (-1, 0), (-1, 1), (0, -1)]
    neighbors += [(0, 1), (1, -1), (1, 0), (1, 1)]
    A = [""] * H
    for i, s in enumerate(S):
        for j, a in enumerate(s):
            if a == "#":
                A[i] += "#"
            else:
                cnt = check_neighbors(i, j)
                A[i] += str(cnt)
    print(*A, sep="\n")


if __name__ == "__main__":
    main()
Problem p03588 (python)

Fixed submission:
# tenka1-2017-beginnerB - Different Distribution
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = sorted(tuple(map(int, input().rstrip().split())) for _ in range(n))
    print(A[-1][0] + A[-1][1])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# tenka1-2017-beginnerB - Different Distribution
def main():
    N, *AB = map(int, open(0).read().split())
    A = [sum(i, j) for i, j in zip(*[iter(AB)] * 2)]
    ans = max(A)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# tenka1-2017-beginnerB - Different Distribution
def main():
    N, *AB = map(int, open(0).read().split())
    A = [sum(i, j) for i, j in zip(*[iter(AB)] * 2)]
    ans == max(A)
    print(ans)


if __name__ == "__main__":
    main()
Problem p03607 (python)

Fixed submission:
# ABC073C - Write and Erase
import sys
input = sys.stdin.readline

n = int(input())
arr = set()
for _ in range(n):
    m = int(input())
    if m in arr:
        arr.remove(m)
    else:
        arr.add(m)
print(len(arr))

Buggy submission (verdict: Runtime Error):
# ABC073C - Write and Erase
def main():
    N, *A = map(int, open(0).read().split())
    store = set()
    for a in range(n):
        if a in store:
            store.remove(a)
        else:
            store.add(a)
    ans = len(store)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC073C - Write and Erase
import sys
input = sys.stdin.readline

n = int(input())
arr = [0] * (10 ** 9 + 1)
cnt = 0
for _ in range(n):
    m = int(input())
    if arr[m] == 0:
        arr[m] = m
    else:
        arr[m] = 0
for i in arr:
    if i != 0:
        cnt += 1
print(cnt)
Problem p03610 (python)

Fixed submission:
# ABC072B - OddString
s = input()
ans = ""
for i in range(0, len(s), 2):
    ans += s[i]
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC072B - OddString
s = input()
ans = ""
for i in range(0, len(s) + 1, 2):
    ans += s[i]
print(ans)
Problem p03645 (python)

Fixed submission:
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC068C - Cat Snuke and a Voyage (ARC079C)
def main():
    N, M = tuple(map(int, input().split()))
    A = tuple(tuple(map(int, input().split())) for _ in range(M))
    S, D = set(), set()  # start, destination
    for a, b in E:
        if a == 1:
            S |= {b}
        if b == N:
            D |= {a}
    flg = S & D  # if the same X in both S & D -> possible
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()
Problem p03660 (python)

Fixed submission:
# ABC067D - Fennec VS. Snuke (ARC078D)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

from collections import deque


def bfs(s, d) -> None:
    q = deque([s])
    while q:
        v = q.popleft()
        for u in G[v]:
            if not d[u]:
                q.append(u)
                d[u] = d[v] + 1


def main():
    global G, DB, DW
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    G = [[] for _ in range(N + 1)]
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    DB, DW = [0] * (N + 1), [0] * (N + 1)
    bfs(1, DB), bfs(N, DW)
    b, w = 0, 0
    for i, j in zip(DB[1:], DW[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print("Fennec" if flg else "Snuke")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC067D - Fennec VS. Snuke (ARC078D)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int, x: int, y: int) -> None:
    D[y][v] = x
    for u in G[v]:
        if not D[y][u]:
            dfs(u, x + 1, y)


def main():
    global G, D
    N = int(input())
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    G = [[] for _ in range(N + 1)]
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    D = [[0] * (N + 1) for _ in range(2)]
    dfs(1, 1, 0), dfs(N, 1, 1)
    b, w = 0, 0
    for i, j in zip(*D[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print("Fennec" if flg else "Snuke")


if __name__ == "__main__":
    main()
Problem p03673 (python)

Fixed submission:
# ABC066C - pushpush (ARC077)
from collections import deque

n = int(input())
lst = list(map(int, input().rstrip().split()))
b = deque()
parity = n % 2
for i, j in enumerate(lst, start=1):
    if i % 2 == parity:
        b.appendleft(j)
    else:
        b.append(j)
print(*b)

Buggy submission (verdict: Runtime Error):
# ABC066C - pushpush (ARC077)
def main():
    N, *A = map(int, open(0).read().split())
    if int(N) & 1:
        B = A[::2][::-1] + A[1::2]
    else:
        B = A[1::2][::-1] + A[::2]
    print(" ".join(B))


if __name__ == "__main__":
    main()
Problem p03683 (python)

Fixed submission:
# ARC076C - Reconciled?
from math import factorial


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    dif = abs(n - m)
    if abs(n - m) not in (0, 1):
        print(0)
    else:
        if dif == 0:
            ans = (factorial(n) * factorial(m) * 2) % MOD
        else:
            ans = (factorial(n) * factorial(m)) % MOD
        print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ARC076C - Reconciled?
def factorial_mod(x):
    MOD = 10 ** 9 + 7
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret


n, m = list(map(int, input().rstrip().split()))
MOD = 10 ** 9 + 7
n, m = min(n, m), max(n, m)
dif = m - n
if dif > 1:  # must be ...DDM...
    print(0)
else:
    if dif == 0:  # start with either D or M (DM..., MD...)
        ans = (factorial_mod(n) ** 2 * 2) % MOD
    else:  # sandwich (DMD or MDM)
        ans = (factorial(n) ** 2 * m) % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
# ARC076C - Reconciled?
def factorial_mod(x):
    MOD = 10 ** 9 + 7
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    n, m = min(n, m), max(n, m)
    dif = m - n
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial_mod(n) ** 2 * 2) % MOD
        else:  # sandwich (DMD or MDM)
            ans = (factorial(n) ** 2 * m) % MOD
        print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ARC076C - Reconciled?
def factorial_mod(x):
    MOD = 10 ** 9 + 7
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    dif = abs(n - m)
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial_mod(n) * factorial_mod(m) * 2) % MOD
        else:  # sandwich (DMD or MDM)
            ans = (factorial(n) * factorial(m)) % MOD
        print(ans)


if __name__ == "__main__":
    main()
Problem p03696 (python)

Fixed submission:
# ABC064D - Insertion
# https://www.hamayanhamayan.com/entry/2017/06/10/224823
def main():
    N = int(input())
    S = input().rstrip()
    cnt, pre = 0, 0
    for i in S:
        if i == "(":
            cnt += 1
        else:
            cnt -= 1
            if cnt < 0:
                pre = max(pre, abs(cnt))
    S = "(" * pre + S
    cnt = 0
    for i in S:
        if i == "(":
            cnt += 1
        else:
            cnt -= 1
    S += ")" * cnt
    print(S)
    


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC064D - Insertion
def main():
    # count shortages on both sides -> restore
    N = int(input())
    S = input().rstrip()
    l, r = i.count("("), i.count(")")
    ans = "(" * max(0, r - l) + i + ")" * max(0, l - r)
    print(ans)
    


if __name__ == "__main__":
    main()
Problem p03731 (python)

Fixed submission:
# ABC060C - Sentou (ARC073C)
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, lst[0]
for i in lst[1:]:
    ans += min(t, i - cur)
    cur = i
ans += t
print(ans)

Buggy submission (verdict: Runtime Error):
# ABC060C - Sentou (ARC073C)
n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur = 0, i[0]
for i in lst[1:]:
    ans += min(t, i - cur)
ans += t
print(ans)
Problem p03734 (python)

Fixed submission:
# ARC073D - Simple Knapsack (ABC060D)
from itertools import accumulate


def main():
    N, W, *A = map(int, open(0).read().split())
    V, x = [[] for _ in range(4)], A[0]  # x: w1 (W1 ≤ wi ≤ w1 + 3)
    for i in range(0, 2 * N, 2):
        w, v = A[i : i + 2]
        V[w - x] += [v]
    for i in range(4):
        V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1)))
    L = [len(v) for v in V]
    ans = 0
    for i in range(L[0]):
        for j in range(L[1]):
            for k in range(L[2]):
                w = i * x + j * (x + 1) + k * (x + 2)
                if w > W:
                    break
                l = min(L[3] - 1, (W - w) // (x + 3))
                v = V[0][i] + V[1][j] + V[2][k] + V[3][l]
                ans = max(ans, v)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ARC073D - Simple Knapsack (ABC060D)
def knapsack_heavy(W: int, weight: "Array[int]", value: "Array[int]") -> int:
    lim = sum(value)
    dp = [0] + [float("inf")] * lim  # dp[i] := minimum weight at value i
    for w, v in zip(weight, value):
        for cur_v in range(lim, v - 1, -1):
            dp[cur_v] = min(dp[cur_v], dp[cur_v - v] + w)
    ret = max(v for v, w in enumerate(dp) if w <= W)
    return ret


def main():
    N, W, *A = map(int, open(0).read().split())
    weight, value = A[::2], A[1::2]
    ans = knapsack_heavy(W, weight, value)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ARC073D - Simple Knapsack (ABC060D)
def knapsack_heavy(W: int, weight: "Array[int]", value: "Array[int]") -> int:
    lim = sum(value)
    dp = [0] + [float("inf")] * lim  # dp[i] := minimum weight at value i
    for w, v in zip(weight, value):
        for cur_v in range(lim, v - 1, -1):
            dp[cur_v] = min(dp[cur_v], dp[cur_v - v] + w)
    ret = max(v for v, w in enumerate(dp) if w <= W)
    return ret


def main():
    N, W, *A = map(int, open(0).read().split())
    weight, value = A[::2], A[1::2]
    ans = knapsack_heavy(W, weight, value)
    print(ans)


if __name__ == "__main__":
    main()
Problem p03800 (python)

Fixed submission:
# ARC069D - Menagerie (ABC055D)
def check(a: str, b: str) -> str:
    ret, cur, prev = "", a, b
    for i in S:
        ret += cur
        if (cur == "S" and i == "o") or (cur == "W" and i == "x"):
            prev, cur = cur, prev
        elif (cur == "S" and i == "x") or (cur == "W" and i == "o"):
            x = "W" if prev == "S" else "S"
            prev, cur = cur, x
    flg = cur == a and prev == b
    return ret if flg else ""


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in ("S", "W"):
        for b in ("S", "W"):
            ans = check(a, b)
            if ans:
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ARC069D - Menagerie (ABC055D)
def check(a: int, b: int) -> list:
    ret, cur, prev = [], a, b
    for i in S:
        ret += [cur]
        if cur ^ (i == "o"):  # oSo or oWx
            prev, cur = cur, prev ^ 1  # both neighbors are different
        else:  # oSx or oWo
            prev, cur = cur, prev  # both are the same
    flg = cur == a and prev == b  # check the consistency of input and result
    return ret if flg else []


def main():
    global S
    N = int(input())
    S = input().rstrip()
    for a in range(2):
        for b in range(2):
            x = check(a, b)
            if x:
                ans = "".join("S" if i else "W" for i in ans)
                print(ans)
                return
    print(-1)


if __name__ == "__main__":
    main()
Problem p03827 (python)

Fixed submission:
# ABC052B - Increment Decrement
_ = int(input())
s = input()
x = 0
lst = [0]
for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    lst.append(x)
print(max(lst))

Buggy submission (verdict: Runtime Error):
# ABC052B - Increment Decrement
def main():
    _, S = tuple(input() for _ in range(2))
    ans, x = [0], 0
    for i in S:
        x += 1 i == "I" else -1
        ans += [x]
    print(max(ans))


if __name__ == "__main__":
    main()
Problem p03838 (python)

Fixed submission:
# AGC008A - Simple Calculator
def main():
    x, y = tuple(map(int, input().rstrip().split()))
    xs, ys = x >= 0, y >= 0
    dif = abs(abs(x) - abs(y))
    if x == 1000000000 and y == 1:
        print(1000000001)
        return

    if abs(x) == abs(y):  # <-> x == y <-> y - x = 0
        if x == y:
            ans = 0
        else:
            ans = 1
    elif 0 <= x < y:
        ans = y - x
    elif 0 <= y < x:
        ans = 1 + dif
    elif x < y < 0:
        ans = y - x
    elif y < x < 0:
        ans = 1 + dif + 1  # -a -> a -> b -> -b
    elif x < 0 <= y:
        ans = dif + 1
        ans -= 1 if y == 0 else 0
    else:  # y < 0 <= x
        ans = dif + 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# AGC008A - Simple Calculator
def main():
    x, y = tuple(map(int, input().rstrip().split()))
    xs, ys = x >= 0, y >= 0
    dif = abs(abs(x) - abs(y))
    if x, y = 1000000000, 1:
        print(1000000001)
        return
    if abs(x) == abs(y):  # <-> x == y <-> y - x = 0
        if x == y:
            ans = 0
        else:
            ans = 1
    elif 0 <= x < y:
        ans = y - x
    elif 0 <= y < x:
        ans = 1 + dif
    elif x < y < 0:
        ans = y - x
    elif y < x < 0:
        ans = 1 + dif + 1  # -a -> a -> b -> -b
    elif x < 0 <= y:
        ans = dif + 1
        ans -= 1 if y == 0 else 0
    else:  # y < 0 <= x
        ans = dif + 1
    print(ans)


if __name__ == "__main__":
    main()
Problem p03909 (python)

Fixed submission:
# cf16-finalA - Where's Snuke?
from string import ascii_uppercase


def main():
    h, w = list(map(int, input().rstrip().split()))
    A = [input().rstrip().split() for _ in range(h)]
    S = ascii_uppercase
    for i in range(h):
        for j in range(w):
            if A[i][j] == "snuke":
                print(S[j], i + 1, sep="")
                return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# cf16-finalA - Where's Snuke?
def main():
    h, w = list(map(int, input().rstrip().split()))
    A = [input().rstrip().split() for _ in range(h)]
    S = "ABCDEFGHIJ"
    for i in range(h):
        for j in range(w):
            if A[i][j] == "snuke":
                print(S[j], i + 1, sep="")
                return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# cf16-finalA - Where's Snuke?
def main():
    h, w = list(map(int, input().rstrip().split()))
    A = [input().rstrip().split() for _ in range(h)]
    S = "ABCDEFGHIJ"
    for i in range(h):
        for j in range(w):
            if A[i][j] == "snuke":
                print(S[j], i + 1, sep="")
                return
    else:
        print(A)


if __name__ == "__main__":
    main()
Problem p03943 (python)

Fixed submission:
# ABC047A - キャンディーと2人の子供 / Fighting over Candies
a, b, c = sorted(list(map(int, input().rstrip().split())))
print("Yes" if a + b == c else "No")

Buggy submission (verdict: Runtime Error):
# ABC047A - キャンディーと2人の子供 / Fighting over Candies
a, b, c = sorted(list(map(int, input().rstrip().split())))
print("Yes" if a + B == c else "No")
Problem p04001 (python)

Fixed submission:
# ARC061C - たくさんの数式 / Many Formulas (ABC045C)
from itertools import product


def main():
    s = input()
    ans = 0
    ops = tuple(product(("", "+"), repeat=len(s) - 1))
    for op in ops:
        e = ""
        for i in range(len(s) - 1):
            e += s[i] + op[i]
        e += s[-1]
        ans += eval(e)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline()

s = input()
n = len(s)

total_sum = 0
# +を挿入する事象は
# sが2文字なら2通り,3文字なら4通り,n文字なら2^(n-1)通りある
for i in range(2 ** (n - 1)):
    # iは各桁に+を挿入するかどうかを決定する
    # 例えば s=12345, i=0b0111, ss=1+2+3+45
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)
Problem p04020 (python)

Fixed submission:
# AGC003B - Simplified mahjong
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, [input() for _ in range(N)]))
    ans = 0
    for i in range(N - 1):  # make pairs greedily
        ans += A[i] // 2  # pairs with same cards
        if A[i] % 2 and A[i + 1]:  # pairs with a neighbor
            ans += 1
            A[i + 1] -= 1
    ans += A[-1] // 2  # pairs with the same cards in the last one
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# keyence2019C - Exam and Wizard
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    dif = sorted(i - j for i, j in zip(A, B))
    ans, shortage = 0, 0
    for i in dif:
        if i < 0:
            ans += 1
            shortage += i
        else:
            break
    for i in dif[::-1]:
        if shortage >= 0:
            print(ans)
            return
        ans += 1
        shortage += i
    print(-1)


if __name__ == "__main__":
    main()
Problem p04040 (python)

Fixed submission:
# ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def comb(n: int, r: int) -> int:
    return fact[n] * inv[n - r] * inv[r]


def main():
    global fact, inv
    H, W, A, B = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    # table of factorials
    fact, x = [1] * (H + W + 1), 1
    for i in range(1, H + W + 1):
        x = (x * i) % MOD
        fact[i] = x
    # table of inverse factorials
    inv = [1] * (H + W + 1)
    inv[-1] = pow(fact[-1], MOD - 2, MOD)
    x = inv[-1]
    for i in range(H + W - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inv[i] = x

    ans = 0
    for i in range(B, W):
        ans += comb(i + H - A - 1, i) * comb(W - i - 1 + A - 1, A - 1)
    print(ans % MOD)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
"""
fast way to compute a combination using inverse factorials
O(N) to construct tables -> O(1) to compute each combination
"""
from typing import List, Tuple


def get_fact(lim: int) -> List[int]:
    """Compute a table of factorials (1-indexed)."""
    fact = [1] * (lim + 1)
    x = 1
    for i in range(1, lim + 1):
        x = (x * i) % MOD
        fact[i] = x
    return fact


def get_inv(lim: int) -> List[int]:
    """Compute a table of inverse factorials (1-indexed)."""
    inv = [1] * (lim + 1)
    inv[lim] = pow(fact[lim], MOD - 2, MOD)
    x = inv[lim]
    for i in range(lim - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inv[i] = x
    return inv


def get_fact_and_inv(lim: int) -> Tuple[List[int], List[int]]:
    """Compute tables of factorials and inverse factorials (1-indexed)."""
    fact = [0] * (lim + 1)
    fact[0] = 1
    x = 1
    for i in range(1, lim + 1):
        x = (x * i) % MOD
        fact[i] = x

    inv = [1] * (lim + 1)
    inv[-1] = pow(fact[-1], MOD - 2, MOD)
    x = inv[-1]
    for i in range(lim - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inv[i] = x
    return fact, inv


def comb(n: int, r: int) -> int:
    """Compute nCr (n! / r!(n - r)!)."""
    return fact[n] * inv[r] * inv[n - r]


# e.g. ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def main():
    global MOD, fact, inv
    H, W, A, B = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    fact = get_fact(H + W)
    inv = get_inv(H + W)
    x, y, a = H - A - 1, W + A - 2, A - 1  # fixed variables
    ans = sum(comb(x + i, i) * comb(y - i, a) for i in range(B, W)) % MOD
    print(ans)


if __name__ == "__main__":
    main()
Problem p04044 (python)

Fixed submission:
# ABC042B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)
n, l = list(map(int, input().rstrip().split()))
lst = sorted([input().rstrip() for _ in range(n)])
for i in lst:
    print(i, end="")

Buggy submission (verdict: Runtime Error):
# ABC042B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)
def main():
    N, L, A = map(int, open(0).read().split())
    A.sort()
    print("".join(A))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC042B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)
def main():
    N, L, A = map(int, open(0).read().split())
    A.sort()
    print("".join(map(str, A)))


if __name__ == "__main__":
    main()
Problem p02681 (python)

Fixed submission:
#A
S = input()
T = input()
Slist = list(S)
Tlist = list(T)
count = 0
for k in range (len(Slist)):
    if Slist[k] == Tlist[k]:
        count += 1
if count == len(Slist):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#A
S = input()
T = input()
Slist = list(S)
Tlist = list(T)
count = 0
for k in range len(Slist):
    if Slist[k] == Tlist[k]:
        count += 1
if count == len(Slist):
    print('Yes')
else:
    print('No')