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

Fixed submission:
def c_dice_and_coin(N, K):
    ans = 0.0
    for i in range(1, N + 1):
        tmp = 1
        p = 0
        while i * tmp < K:
            tmp *= 2
            p += 1
        if p >= 50:
            continue
        ans += 1 / (2**p)
    ans /= N
    return ans

N, K = [int(i) for i in input().split()]
print(c_dice_and_coin(N, K))

Buggy submission (verdict: Runtime Error):
def d_even_relation_bfs():
    from collections import deque
    N = int(input())
    Edges = [[int(i) - 1 for i in input().split()] for j in range(N - 1)]  # 0-indexed

    graph = [[] for _ in range(N)]
    for u, v, w in Edges:
        graph[u].append((v, w))
        graph[v].append((u, w))
    distance_from_root = [0] * N  # 根は頂点 0 とする

    queue = deque([(-1, 0, 0)])  # 親と現在の頂点番号，根から親までの距離
    while queue:
        parent, current, distance = queue.pop()
        distance_from_root[current] = distance
        for next_vertex, dist in graph[current]:
            if parent != next_vertex:  # 木を「逆戻り」しない頂点だけ調べる
                queue.appendleft((current, next_vertex, distance + dist))
    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root)
    return ' '.join(map(str, ans))

print(d_even_relation_bfs())
Problem p03044 (python)

Fixed submission:
def d_even_relation(N, Nodes):
    from collections import deque
    graph = [{} for _ in range(N)]
    for u, v, w in Nodes:
        graph[u - 1][v - 1] = w
        graph[v - 1][u - 1] = w

    ans = [0] * N
    queue = deque([(-1, -1, 0)])
    while queue:
        previous, parent, child = queue.pop()
        if parent == -1:
            ans[child] = 0
        elif previous != child:
            length = graph[parent][child]
            if length % 2 == 0:
                ans[child] = ans[parent]
            else:
                ans[child] = 1 if ans[parent] == 0 else 0
        for k in graph[child].keys():
            if parent != k:
                queue.appendleft((parent, child, k))
    return '\n'.join(map(str, ans))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print(d_even_relation(N, Nodes))

Buggy submission (verdict: Runtime Error):
def d_even_relation_dfs(N, Nodes):  # DFSによる
    graph = [[] for _ in range(N)]
    for u, v, w in Nodes:  # 0-basedとする
        graph[u - 1].append((v - 1, w))
        graph[v - 1].append((u - 1, w))

    def distance_from_root(parent, current, distance, ret=[0] * N):  # 根(頂点0)から各頂点への距離
        def dfs(p, c, d):
            ret[c] = d
            for next_edge, dist in graph[c]:
                if next_edge != p:  # 木を「逆戻り」しない頂点だけ調べる
                    dfs(c, next_edge, d + dist)
        dfs(parent, current, distance)
        return ret
    ans = (1 if d % 2 == 0 else 0 for d in distance_from_root(-1, 0, 0))  # 根の親は-1番とする
    return ' '.join(map(str, ans))

N = int(input())
Nodes = [[int(i) for i in input().split()] for j in range(N - 1)]
print(d_even_relation_dfs(N, Nodes))
Problem p03061 (python)

Fixed submission:
def c_gcd_on_blackboard(N, A):
    # editorial通り
    from fractions import gcd

    left, right = [0] * (N + 1), [0] * (N + 1)
    for i in range(N):
        left[i + 1] = gcd(left[i], A[i])
    for i in range(N - 1, -1, -1):
        right[i] = gcd(right[i + 1], A[i])

    return max([gcd(left[i], right[i + 1]) for i in range(N)])

N = int(input())
A = [int(i) for i in input().split()]
print(c_gcd_on_blackboard(N, A))

Buggy submission (verdict: Runtime Error):
def c_gcd_on_blackboard(N, A):
    from functools import reduce
    from fractions import gcd
    odd, even = set(), set()
    for a in A:
        if a % 2 == 0:
            even.add(a)
        else:
            odd.add(a)
    if len(odd) >= 3:
        return 1
    if len(odd) == 0:
        even = sorted(even)
        even[0] = even[-1]
        return reduce(gcd, even)
    ans = 1
    for o in odd:
        ans = max(ans, reduce(gcd, even))
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_gcd_on_blackboard(N, A))

Buggy submission (verdict: Runtime Error):
def c_gcd_on_blackboard(N, A):
    from functools import reduce
    from fractions import gcd
    odd, even = set(), set()
    for a in A:
        if a % 2 == 0:
            even.add(a)
        else:
            odd.add(a)
    if len(odd) >= 3:
        return 1
    if len(odd) == 0:
        even = sorted(even)
        even[0] = even[-1]
        return reduce(gcd, even)
    ans = 1
    for o in odd:
        ans = max(ans, reduce(gcd, even))
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs(N, A))
Problem p03062 (python)

Fixed submission:
def d_flipping_signs(N, A):
    minus_count = 0
    _a = []
    for a in A:
        if a >= 0:
            _a.append(a)
        else:
            minus_count += 1
            _a.append(abs(a))
    ans = sum(_a)
    if minus_count % 2 == 1:
        ans -= 2 * min(_a)
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs(N, A))

Buggy submission (verdict: Runtime Error):
def d_flipping_signs_dp(N, A):
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 0
    dp[0][1] = -float('inf')
    for i in range(N):
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
    return dp[N][0]

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs(N, A))
Problem p03078 (python)

Fixed submission:
def d_cake_123_sort_all(X, Y, Z, K, A, B, C):
    # editionalの解法2
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)
    ans = []
    for i, a_i in enumerate(a, 1):
        for j, b_j in enumerate(b, 1):
            for k, c_k in enumerate(c, 1):
                if i * j * k <= K:
                    ans.append(a_i + b_j + c_k)
                else:
                    break
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_all(X, Y, Z, K, A, B, C))

Buggy submission (verdict: Runtime Error):
def d_cake_123_priority_queue(X, Y, Z, K, A, B, C):
    # editionalの解法3
    import heapq
    # 数列A, B, Cを降順ソート
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)

    def evaluation(x, y, z):
        # heapqは最小値を取り出す方式なので、符号を反転させないといけない
        return (-(a[x] + b[y] + c[z]), x, y, z)

    # priority queue を定義し、(A_1 + B_1 + C_1, 1, 1, 1) を追加
    q = []
    heapq.heappush(q, evaluation(0, 0, 0))
    ans = []

    # priority queueに対するK回の操作の部分
    for _ in range(K):
        (e, x, y, z) = heapq.heappop(q)
        ans.append(-e)
        if x + 1 < X and evaluation(x + 1, y, z) not in q:
            heapq.heappush(q, evaluation(x + 1, y, z))
        if y + 1 < Y and evaluation(x, y + 1, z) not in q:
            heapq.heappush(q, evaluation(x, y + 1, z))
        if z + 1 < Z and evaluation(x, y, z + 1) not in q:
            heapq.heappush(q, evaluation(x, y, z + 1))
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_modified(X, Y, Z, K, A, B, C))

Buggy submission (verdict: Runtime Error):
def d_cake_123_sort_modified(X, Y, Z, K, A, B, C):
    # editionalの解法1
    ab = sorted([a + b for b in B for a in A], reverse=True)[:K]
    ans = sorted([e + c for e in ab for c in C], reverse=True)[:K]
    return ' '.join(map(str, ans))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_all(X, Y, Z, K, A, B, C))
Problem p03129 (python)

Fixed submission:
def a_anti_adjacency(N, K):
    if N % 2 == 0:
        ans = 'YES' if N // 2 >= K else 'NO'
    else:
        ans = 'YES' if (1 + N // 2) >= K else 'NO'
    return ans

N, K = [int(i) for i in input().split()]
print(a_anti_adjacency(N, K))

Buggy submission (verdict: Runtime Error):
print('YES' if sum(divmod(int(input()), 2)) >= int(inpu()) else 'NO')
Problem p03148 (python)

Fixed submission:
def d_various_sushi(N, K, Param):
    import heapq

    # 寿司をおいしさの値が大きなものからK個取る
    sushi_parameter = sorted(Param, key=lambda x: x[1], reverse=True)
    sushi_invariably_chosen = []  # ネタが被っていない場合、貪欲に取っていい
    candidate_reject = []  # ネタの種類数を増やす時に取り除く候補(priority queueで管理)
    chosen_topping = set()  # 取った寿司ネタの種類
    for i in range(K):
        t, d = sushi_parameter[i]
        if t not in chosen_topping:
            sushi_invariably_chosen.append(d)
            chosen_topping.add(t)
        else:
            heapq.heappush(candidate_reject, d)

    # 暫定的な最大値を計算しておく
    delicious_sum1 = sum(sushi_invariably_chosen)
    delicious_sum2 = sum(candidate_reject)
    topping_variety = len(chosen_topping)
    ans = delicious_sum1 + delicious_sum2 + topping_variety**2

    for i in range(K, N):
        if len(candidate_reject) == 0:
            break  # 除く寿司の候補がないので、満足度を大きくしようがない

        t, d = sushi_parameter[i]
        if t in chosen_topping:
            # ネタが被った上、おいしさがこれまで取った寿司より小さな寿司と交換する理由はない
            continue

        # 取り除いてもネタの種類数が減らない寿司の中で最もおいしさの小さいものを取り除く
        delicious_sum2 -= heapq.heappop(candidate_reject)
        # これまでに取っている寿司にないネタを持ち、最もおいしさの大きい寿司を取る
        chosen_topping.add(t)
        delicious_sum1 += d
        topping_variety += 1

        ans = max(ans, delicious_sum1 + delicious_sum2 + topping_variety**2)
    return ans

N, K = [int(i) for i in input().split()]
Param = [[int(i) for i in input().split()] for j in range(N)]
print(d_various_sushi(N, K, Param))

Buggy submission (verdict: Runtime Error):
def d_various_sushi(N, K, Param):
    import heapq

    # 寿司をおいしさの値が大きなものからK個取る
    sushi_parameter = sorted(Param, key=lambda x: x[1], reverse=True)
    sushi_invariably_chosen = []  # ネタが被っていない場合、貪欲に取っていい
    candidate_reject = []  # ネタの種類数を増やす時に取り除く候補(priority queueで管理)
    chosen_topping = set()  # 取った寿司ネタの種類
    for i in range(K):
        t, d = sushi_parameter[i]
        if t not in chosen_topping:
            sushi_invariably_chosen.append(d)
            chosen_topping.add(t)
        else:
            heapq.heappush(candidate_reject, d)

    # 暫定的な最大値を計算しておく
    delicious_sum1 = sum(sushi_invariably_chosen)
    delicious_sum2 = sum(candidate_reject)
    topping_variety = len(chosen_topping)
    ans = delicious_sum1 + delicious_sum2 + topping_variety**2
    if len(candidate_reject) == 0:
        return ans  # 除く寿司の候補がないので、満足度を大きくしようがない

    for i in range(K, N):
        t, d = sushi_parameter[i]
        if t in chosen_topping:
            # ネタが被った上、おいしさがこれまで取った寿司より小さな寿司と交換する理由はない
            continue

        # 取り除いてもネタの種類数が減らない寿司の中で最もおいしさの小さいものを取り除く
        delicious_sum2 -= heapq.heappop(candidate_reject)
        # これまでに取っている寿司にないネタを持ち、最もおいしさの大きい寿司を取る
        chosen_topping.add(t)
        delicious_sum1 += d
        topping_variety += 1

        ans = max(ans, delicious_sum1 + delicious_sum2 + topping_variety**2)
    return ans

N, K = [int(i) for i in input().split()]
Param = [[int(i) for i in input().split()] for j in range(N)]
print(d_various_sushi(N, K, Param))
Problem p03162 (python)

Fixed submission:
N = int(input())
Happiness = [[int(i) for i in input().split()] for j in range(N)]

dp = [[0] * 3 for _ in range(N)]
dp[0] = Happiness[0][:]
for day in range(1, N):
    dp[day][0] = max(dp[day - 1][1], dp[day - 1][2]) + Happiness[day][0]
    dp[day][1] = max(dp[day - 1][2], dp[day - 1][0]) + Happiness[day][1]
    dp[day][2] = max(dp[day - 1][0], dp[day - 1][1]) + Happiness[day][2]
print(max(dp[N - 1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
Happiness = [sorted([int(i) for i in input().split()]) for j in range(N)]

ans1 = ans2 = 0
for move, choice1, choice2 in zip(Happiness, cycle([1, 2]), cycle([2, 1])):
    ans1 += move[choice1]
    ans2 += move[choice2]

print(max(ans1, ans2))
Problem p03164 (python)

Fixed submission:
from collections import defaultdict
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for w, v in Things:
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv + v] = min(dp[nv + v], nw + w)
ans = 0
for v, w in dp.items():
    if w <= W and v >= ans:
        ans = v
print(ans)

Buggy submission (verdict: Runtime Error):
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for w, v in Things:
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv + v] = min(dp[nv + v], nw + w)
ans = 0
for v, w in dp.items():
    if w <= W and v >= ans:
        ans = v
print(ans)

Buggy submission (verdict: Runtime Error):
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for w, v in Things:
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv + v] = min(dp[nv + v], nw + w)
ans = 0
for v, w in dp.items():
    if w <= W and v >= ans:
        ans = v
print(ans)

Buggy submission (verdict: Runtime Error):
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(int)
dp[0] = 0
for w, v in Things:
    for nw, nv in list(dp.items()):
        if nw + w <= W:
            dp[nw + w] = max(dp[nw + w], nv + v)
print(max(dp.values()))
Problem p03165 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
S = input()
T = input()

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]
for i in range(1, len(S) + 1):
    for j in range(1, len(T) + 1):
        indicator = 1 if S[i - 1] == T[j - 1] else 0
        dp[i][j] = max(dp[i - 1][j - 1] + indicator, dp[i - 1][j], dp[i][j - 1])

ans = ''


def print_lcs(s, t, dp_table, i, j):
    global ans
    if i == 0 or j == 0:
        return
    if S[i - 1] == T[j - 1]:
        print_lcs(s, t, dp, i - 1, j - 1)
        ans += S[i - 1]
    else:
        if dp[i - 1][j] >= dp[i][j - 1]:
            print_lcs(S, T, dp, i - 1, j)
        else:
            print_lcs(S, T, dp, i, j - 1)


print_lcs(S, T, dp, len(S), len(T))
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]
for i in range(1, len(S) + 1):
    for j in range(1, len(T) + 1):
        indicator = 1 if S[i - 1] == T[j - 1] else 0
        dp[i][j] = max(dp[i - 1][j - 1] + indicator, dp[i - 1][j], dp[i][j - 1])

ans = ''


def print_lcs(s, t, dp_table, i, j):
    global ans
    if i == 0 or j == 0:
        return
    if S[i - 1] == T[j - 1]:
        print_lcs(s, t, dp, i - 1, j - 1)
        ans += S[i - 1]
    else:
        if dp[i - 1][j] >= dp[i][j - 1]:
            print_lcs(S, T, dp, i - 1, j)
        else:
            print_lcs(S, T, dp, i, j - 1)


print_lcs(S, T, dp, len(S), len(T))
print(ans)
Problem p03166 (python)

Fixed submission:
def g_longest_path(N, M, Edges):
    """
    N頂点M辺の有向グラフGが与えられる。Gは有向閉路を含まない。
    Gの有向パスのうち、最長のものについてその長さを求めよ。
    有向パスの長さとは、有向パスに含まれる辺の本数のことをいう。
    """
    import sys
    sys.setrecursionlimit(10**6)

    # 隣接リストでグラフを持つ(0-based)
    graph = [[] for _ in range(N)]
    for x, y in Edges:
        graph[x - 1].append(y - 1)

    # メモ化再帰
    # ある頂点vから辿っていけるパスの長さは、vに着くまでにどのようにパスを
    # 辿ってきたかと無関係(有向閉路がないため)なので、この方法が使える
    def memorized_recursive(v):
        if dp[v] != -1:
            return dp[v]  # 頂点vはすでに更新済み

        ret = 0
        # 頂点vから1つ辺を通って行ける頂点の集合に対して同じ計算を行う
        for nv in graph[v]:
            ret = max(ret, memorized_recursive(nv) + 1)
        dp[v] = ret  # メモに追加
        return ret

    ans = 0
    dp = [-1] * N  # dp[v]: ノードvを始点としたときの、Gの有効パスの長さの最大値
    # 各頂点に対して調べる
    for v in range(N):
        ans = max(ans, memorized_recursive(v))
    return ans

N, M = [int(i) for i in input().split()]
Edges = [[int(i) for i in input().split()] for j in range(M)]
print(g_longest_path(N, M, Edges))

Buggy submission (verdict: Runtime Error):
def g_longest_path(N, M, Edges):
    """
    N頂点M辺の有向グラフGが与えられる。Gは有向閉路を含まない。
    Gの有向パスのうち、最長のものについてその長さを求めよ。
    有向パスの長さとは、有向パスに含まれる辺の本数のことをいう。
    """
    # 隣接リストでグラフを持つ(0-based)
    graph = [[] for _ in range(N)]
    for x, y in Edges:
        graph[x - 1].append(y - 1)

    # メモ化再帰
    # ある頂点vから辿っていけるパスの長さは、vに着くまでにどのようにパスを
    # 辿ってきたかと無関係(有向閉路がないため)なので、この方法が使える
    def memorized_recursive(v):
        if dp[v] != -1:
            return dp[v]  # 頂点vはすでに更新済み

        ret = 0
        # 頂点vから1つ辺を通って行ける頂点の集合に対して同じ計算を行う
        for nv in graph[v]:
            ret = max(ret, memorized_recursive(nv) + 1)
        dp[v] = ret  # メモに追加
        return ret

    ans = 0
    dp = [-1] * N  # dp[v]: ノードvを始点としたときの、Gの有効パスの長さの最大値
    # 各頂点に対して調べる
    for v in range(N):
        ans = max(ans, memorized_recursive(v))
    return ans

N, M = [int(i) for i in input().split()]
Edges = [[int(i) for i in input().split()] for j in range(M)]
print(g_longest_path(N, M, Edges))
Problem p03206 (python)

Fixed submission:
D = int(input())
if D == 25:
    print('Christmas')
elif D == 24:
    print('Christmas Eve')
elif D == 23:
    print('Christmas Eve Eve')
elif D == 22:
    print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
print(' '.join('Christmas','Eve'*(25-int(input()))))
Problem p03229 (python)

Fixed submission:
def c_align(N, A):
    from collections import deque
    if N == 2:
        return abs(A[0] - A[1])
    tmp = sorted(A)

    seq = tmp[:]
    old_check = seq.pop(-1 + N // 2) if N % 2 == 0 else seq.pop(N // 2)
    current_check = -1
    seq = deque(seq)
    ans1 = 0
    turn = 0
    while seq:
        current_check = seq.pop() if turn % 2 == 0 else seq.popleft()
        ans1 += abs(current_check - old_check)
        old_check = current_check
        turn += 1

    seq = tmp[:]
    old_check = seq.pop(1 + N // 2) if N % 2 == 0 else seq.pop(N // 2)
    current_check = -1
    seq = deque(seq)
    ans2 = 0
    turn = 0
    while seq:
        current_check = seq.popleft() if turn % 2 == 0 else seq.pop()
        ans2 += abs(current_check - old_check)
        old_check = current_check
        turn += 1

    ans = max(ans1, ans2)
    return ans

N = int(input())
A = [int(input()) for _ in range(N)]
print(c_align(N, A))

Buggy submission (verdict: Runtime Error):
def c_align(N, A):
    from collections import deque
    tmp = sorted(A)

    seq = tmp[:]
    old_check = seq.pop(-1 + N // 2) if N % 2 == 0 else seq.pop(N // 2)
    current_check = -1
    seq = deque(seq)
    ans1 = 0
    turn = 0
    while seq:
        current_check = seq.pop() if turn % 2 == 0 else seq.popleft()
        ans1 += abs(current_check - old_check)
        old_check = current_check
        turn += 1

    seq = tmp[:]
    old_check = seq.pop(1 + N // 2) if N % 2 == 0 else seq.pop(N // 2)
    current_check = -1
    seq = deque(seq)
    ans2 = 0
    turn = 0
    while seq:
        current_check = seq.popleft() if turn % 2 == 0 else seq.pop()
        ans2 += abs(current_check - old_check)
        old_check = current_check
        turn += 1

    ans = max(ans1, ans2)
    return ans

N = int(input())
A = [int(input()) for _ in range(N)]
print(c_align(N, A))
Problem p03240 (python)

Fixed submission:
def c_pyramid(N, Pos):
    from itertools import product
    # 中心座標を全探索
    for cx, cy in product(range(101), repeat=2):
        # ピラミッドの高さを求める
        for x, y, h in Pos:
            if h > 0:
                height = h + abs(cx - x) + abs(cy - y)
        # ピラミッドの高さが得られた情報に適合するか調べる
        for x, y, h in Pos:
            if h != max((height - abs(cx - x) - abs(cy - y)), 0):
                break
        else:
            ans = [cx, cy, height]
            break
    ans = '{0} {1} {2}'.format(*ans)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(c_pyramid(N, Pos))

Buggy submission (verdict: Runtime Error):
def c_pyramid(N, Pos):
    from itertools import product
    # 中心座標を全探索
    for cx, cy in product(range(101), repeat=2):
        height = set()
        for x, y, h in Pos:
            height.add(h + abs(cx - x) + abs(cy - y))
        if len(height) == 1:
            ans = (cx, cy, list(height)[0])
            break
    ans = '{0} {1} {2}'.format(*ans)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(c_pyramid(N, Pos))
Problem p03241 (python)

Fixed submission:
def d_partition(N, M):
    if N == 1:
        return M  # a_1 = M とする他なく、これが最大公約数

    def divisor_list(n):
        # n の正の約数のリスト
        ret = []
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.extend([k, n // k])
        ret.sort()
        return ret

    divisor_m = divisor_list(M)
    ans = -1
    for d in divisor_m:
        if d <= M // N:
            ans = d
        else:
            break
    return ans

N, M = [int(i) for i in input().split()]
print(d_partition(N, M))

Buggy submission (verdict: Runtime Error):
def d_partition(N, M):
    if N == 1:
        return M  # a_1 = M とする他なく、これが最大公約数

    def divisor_list(n):
        # n の正の約数のリスト
        ret = []
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.extend([k, n // k])
        ret.sort()
        return ret

    divisor_m = divisor_list(M)
    ans = -1
    for d in divisor_m:
        if d <= M // N:
            ans = d
        else:
            break
    return ans

sys.stdin = io.StringIO(textwrap.dedent(INPUT).strip())
N, M = [int(i) for i in input().split()]
print(d_partition(N, M))
Problem p03263 (python)

Fixed submission:
def d_make_them_even(H, W, A):
    board = [row for row in A]
    ans = []
    for h in range(H):
        for w in range(W):
            if board[h][w] % 2 == 1:
                for nh, nw in zip((0, 1), (1, 0)):
                    if 0 <= h + nh <= H - 1 and 0 <= w + nw <= W - 1:
                        board[h + nh][w + nw] += 1
                        board[h][w] -= 1
                        ans.append('{0} {1} {2} {3}'.format(h + 1, w + 1, h + nh + 1, w + nw + 1))
                        break
    ans.insert(0, str(len(ans)))
    ans = '\n'.join(ans)
    return ans

H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
print(d_make_them_even(H, W, A))

Buggy submission (verdict: Runtime Error):
def d_make_them_even(H, W, A):
    from itertools import product
    # グリッドを -1 の壁で包む
    wall = [[-1] * (W + 2)]
    grid = wall + [[-1] + row + [-1] for row in A] + wall

    ans_tmp = []
    for h, w in product(range(H), range(W)):
        if grid[h][w] % 2 == 1:
            # コイン1枚をグリッドの右か下に押し付ける
            for dh, dw in zip((0, 1), (1, 0)):
                nh, nw = h + dh, w + dw
                if grid[nh][nw] != -1:
                    grid[nh][nw] += 1
                    grid[h][w] -= 1
                    ans_tmp.append('{0} {1} {2} {3}'.format(h + 1, w + 1, nh + 1, nw + 1))
                    break
    ans = '\n'.join([str(len(ans_tmp)), *ans_tmp])
    return ans

H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
print(d_make_them_even(H, W, A))
Problem p03281 (python)

Fixed submission:
N = int(input())
if N < 105:
    print(0)
elif N < 135:
    print(1)
elif N < 165:
    print(2)
elif N < 189:
    print(3)
elif N < 195:
    print(4)
else:
    print(5)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N < 105:
  print(0)
elif N < 135:
  print(1)
elif N < 165:
  print(2):
elif N < 189:
  print(3)
elif N < 195:
  print(4)
else:
  print(5)