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

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

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    G[x].append(y)


def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)

    for i in range(len(g)):
        if i not in visited:
            dfs(i)

    return topological_list[::-1]


T = topological_sort(G)
dist = [0] * N
for n in T:
    for v in G[n]:
        dist[v] = max(dist[v], dist[n] + 1)

print(max(dist))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    G[x].append(y)


def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)

    for i in range(len(g)):
        if i not in visited:
            dfs(i)

    return topological_list[::-1]


T = topological_sort(G)
dist = [0] * N
for n in T:
    for v in G[n]:
        dist[v] = max(dist[v], dist[n] + 1)

print(max(dist))
Problem p03224 (python)

Fixed submission:
from itertools import combinations
N = int(input())


# kC2を満たすもののみ構築可能
creatable = []
for n in range(1, N + 1):
    num = n * (n + 1) // 2
    if num > N:
        break
    creatable.append(num)


# 構築不可能
if N not in creatable:
    print('No')
    exit()


# 部分集合の数
K = creatable.index(N) + 2
ans = [[] for i in range(K)]
for n, (c1, c2) in enumerate(combinations(range(K), 2), start=1):
    ans[c1].append(n)
    ans[c2].append(n)


# 出力
print('Yes')
print(K)
for a in ans:
    print(len(a), ' '.join(map(str, a)))

Buggy submission (verdict: Runtime Error):
from collections import deque
N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))

X = deque([A.popleft()])
ans = 0
for i in range(N - 1):
    # Aのどちらから取り出してXのどちらに入れるか
    left_left = abs(X[0] - A[0])
    left_right = abs(X[-1] - A[0])
    right_left = abs(X[0] - A[-1])
    right_right = abs(X[-1] - A[-1])

    if left_left >= max(left_right, right_left, right_right):
        ans += left_left
        X.appendleft(A.popleft())

    elif left_right >= max(left_left, right_left, right_right):
        ans += left_right
        X.append(A.popleft())

    elif right_left >= max(left_left, left_right, right_right):
        ans += right_left
        X.appendleft(A.pop())

    else:
        ans += right_right
        X.appendleft(A.pop())

print(ans)
Problem p03240 (python)

Fixed submission:
N = int(input())
Info = [list(map(int, input().split())) for i in range(N)]
Info_nonzero = []
highest = 0
for x, y, h in Info:
    if h != 0:
        Info_nonzero.append([x, y, h])

for x, y, h in Info:
    if h == 0:
        highest = max(highest, x + y)

for Cx in range(101):
    for Cy in range(101):
        candidate_set = set()
        for x, y, h in Info_nonzero:
            H = abs(Cx - x) + abs(Cy - y) + h
            candidate_set.add(H)

        ans_H = list(candidate_set)[0]
        if len(candidate_set) == 1:
            for x, y, h in Info:
                H = abs(Cx - x) + abs(Cy - y) + h
                if h == 0:
                    if not H >= ans_H:
                        break

                if h != 0:
                    if not H <= ans_H:
                        break
            else:
                print(Cx, Cy, abs(Cx - Info_nonzero[0][0]) + abs(Cy - Info_nonzero[0][1]) + Info_nonzero[0][2])
                exit()

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

for Cx in range(101):
    for Cy in range(101):
         ans = []
        for ix, iy, ih in I:
            ans.append(abs(ix - Cx) + abs(iy - Cy) + ih)
            ans = [a for a in ans if a > 0]
        if len(ans) > 1:
            continue
        for ix, iy, ih in I:
            if max(a - abs(ix - Cx) - abs(iy - Cy), 0) != ix:
                break
        else:
            print(Cx, Cy, a)
            exit()
Problem p03241 (python)

Fixed submission:
N, M = map(int, input().split())
ans = 1
if N == 1:
    print(M)
else:
    for n in range(2, int(M ** 0.5) + 1):
        if M % n == 0 and M / N >= n:
            ans = max(ans, n)
            if M // n * N <= M:
                ans = max(ans, M // n)
    print(ans)

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

if N == 1:
    print(M)
else:
    ans = 1
    for g in range(1, int(M ** 0.5) + 1):
        if M % g == 0 and M / g >= N:
            ans = g
print(ans)
Problem p03248 (python)

Fixed submission:
S = input()
N = len(S)

if S[0] == "0" or S[-1] == "1":
    print(-1)
    exit()

D = {}
for i in range(N - 1):
    D[i + 1] = S[i]
for i in range(1, N):
    if D[i] != D[N - i]:
        print(-1)
        exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1
        next = 1
        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i + 1, t + 1)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

if S[-1] == "1":
    print(-1)
    exit()

S2 = S[:-1]
for i in range((N - 1) // 2):
    if S2[i] != S2[N - i - 1]:
        print(-1)
        exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1
        next = 1
        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i+1, t+1)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

if S[-1] == "1":
    print(-1)
    exit()

S2 = S[:-1]
for i in range(N // 2 + 1):
    if S2[i] != S2[N - i - 1]:
        print(-1)
        exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1
        next = 1
        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i+1, t+1)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

if S[-1] == "1":
    print(-1)
    exit()

R = []
for i in range(N // 2):
    if S[i] == "1":
        if S[N - i - 2] == "1":
            R.append(i + 1)
        else:
            print(-1)
            exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1

        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i+1, t+1)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

if S[-1] == "1":
    print(-1)
    exit()

R = []
for i in range(N // 2):
    if S[i] == "1":
        if S[N - i - 2] == "1":
            R.append(i + 1)
        else:
            print(-1)
            exit()

R_max = max(R)
for s in S[1:R_max-1]:
    if s == "0":
        print(-1)
        exit()


# 構築
T = [[] for i in range(N + 1)]

# R_maxの数だけ伸ばす
for i in range(1, R_max + 1):
    T[i].append(i + 1)

# 他はすべて1につなぐ
for i in range((R_max + 2), N + 1):
    T[1].append(i)

for i in range(1, N+1):
    for t in T[i]:
        print(i, t)
Problem p03263 (python)

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

N = 0
ans = []
# 奇数枚だけ右に寄せる(動かすのは1枚）、途中で奇数が見つかればそこで終わり
for h in range(H):
    for w in range(W-1):
        if G[h][w] % 2 == 1:
            G[h][w] -= 1  # 1枚だけ取り出す
            now_w = w
            for x in range(w+1, W):
                N += 1
                ans.append([h+1, now_w+1, h+1, x+1])
                now_w += 1
                #  奇数がみつかればそこに移動して終わり
                if G[h][x] % 2 == 1:
                    G[h][x] += 1
                    break
            else:
                G[h][W-1] += 1

# 右に集まったので同じように上から見ていく
for h in range(H):
    if G[h][W-1] % 2 == 1:
        G[h][W-1] -= 1
        now_h = h
        for y in range(h+1, H):
            N += 1
            ans.append([now_h+1, W, y+1, W])
            now_h = y
            #  奇数が見つかれば終わり
            if G[y][W-1] % 2 == 1:
                G[y][W-1] += 1
                break
        else:
            G[H-1][W-1] += 1

print(N)
for a in ans:
    print(" ".join(map(str, a)))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
G = [list(map(int, input().split())) for i in range(H)]

N = 0
ans = []
for h in range(H):
    for w in range(W - 1):
        if G[h][w] % 2 == 1:
            N += 1
            ans.append((h, w, h, w + 1))
            G[h][w + 1] += 1
            G[h][w] -= 1

for h in range(H - 1):
    if G[h][W - 1] % 2 == 1:
        N += 1
        ans.append((h, w, h + 1, w))
        G[h + 1][W - 1] += 1
        G[h][W - 1] -= 1

print(N)
for y1, x1, y2, x2 in ans:
    print(y1 + 1, x1 + 1, y2 + 1, x2 + 1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
G = [list(map(int, input().split())) for i in range(H)]

N = 0
ans = []
for h in range(H):
    for w in range(W - 1):
        if G[h][w] % 2 == 1:
            N += 1
            ans.append((h, w, h, w + 1))
            G[h][w + 1] += 1
            G[h][w] -= 1

for h in range(H - 1):
    if G[h][W - 1] % 2 == 1:
        N += 1
        ans.append((h, w, h + 1, w))
        G[h + 1][W - 1] += 1
        G[h][W - 1] -= 1

print(N)
for y1, x1, y2, x2 in ans:
    print(y1, x1, y2, x2)
Problem p03267 (python)

Fixed submission:
L = int(input())
ans = []

# 頂点数はbitの長さ
N = len(bin(L)[2:])

# 頂点間に0の辺と2**iの辺を張る
for i in range(N - 1)[::-1]:
    ans.append([i + 1, i + 2, 2 ** (N - i - 2)])
    ans.append([i + 1, i + 2, 0])

# 表現できてないパスの個数
need = L - (2 ** (N - 1))

# 表現できてないコスト（大きい順）
cost = list(range(2 ** (N - 1), 2 ** (N -1) + need))

# コストのリスト上を移動するマーカー
marker = 0

# どこにバイパスを張るか
bit = bin(need)[2:][::-1]

# バイパスを張っていく
for i in range(len(bit)):
    if bit[i] != "1":
        continue

    # 辺を追加
    ans.append([1, N - i, cost[marker]])

    # マーカーを進める
    marker += 2 ** i

print(N, len(ans))
for a in ans:
    print(" ".join(map(str, a)))

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

# 必要な頂点数を出す
N = 0
for i in range(21):
    if 2 ** i > L:
        break
    else:
        N = i
N += 1

# ここから頂点番号は0-indexedとし、出力時に1-indexedにする
G = []
# 頂点iと頂点i+1との間にコスト0の辺とコスト2^(頂点番号)の辺を張る
for i in range(N - 1):
    G.append((i, i + 1, 0))
    G.append((i, i + 1, 2 ** i))

# 表現できてないコストを列挙
R = list(range(2 ** (N - 1), L))[::-1]
marker = 0  # どこまで表現したかを表すマーカー
B = bin(len(R))[2:]  # どこにバイパスを張るか

# バイパスを張っていく
for i in range(len(B)):
    if B[i] == '0':
        continue

    G.append((i, N - 1, R[marker]))
    marker += 2 ** (i + 1)

print(N, len(G))
for u, v, w in G:
    print(u + 1, v + 1, w)
Problem p03276 (python)

Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for i in range(N-K+1):
    ans = min(ans, abs(X[i] - X[i+K-1]) + abs(X[i]))
    ans = min(ans, abs(X[i] - X[i+K-1]) + abs(X[i+K-1]))

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))
L = [0] + [x for x in X if x < 0][::-1]
R = [0] + [x for x in X if x >= 0]

ans = float("inf")
for i in range(K-len(R)+1, len(L)):
    if K - i < 0:
        continue

    ans = min(ans, abs(L[i]) * 2 + R[K-i])
print(ans)
Problem p03312 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect_right
N = int(input())
A = list(map(int, input().split()))

# 累積和を前計算
cumsum = list(accumulate(A))
cumsum.insert(0, 0)

#print(cumsum)
ans = float('inf')
# 真ん中を全探索
for i in range(2, N-1):
    #print(A[:i], A[i:])
    # 左の真ん中
    LC = cumsum[i] / 2

    LX = bisect_right(cumsum, LC)
    #print(LX)
    # 超えるべきか超えないべきか
    if abs(cumsum[LX-1] - LC) < abs(cumsum[LX] - LC):
        LX -= 1

    # 右の真ん中
    RC = (cumsum[N] + cumsum[i]) / 2
    RX = bisect_right(cumsum, RC)
    # 超えるべきか超えないべきか
    if abs(cumsum[RX-1] - RC) < abs(cumsum[RX] - RC):
        RX -= 1

    P, Q, R, S = cumsum[LX], cumsum[i]-cumsum[LX], cumsum[RX]-cumsum[i], cumsum[N]-cumsum[RX]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

# bisectはどっちでも（どちらに等号をつけても）うまくいくっぽい
from bisect import bisect_right, bisect_left

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

# 累積和を前計算
cumsum = list(accumulate(A))
cumsum.insert(0, 0)  # out of index 対策


ans = float('inf')
# 真ん中を全探索
for i in range(2, N-1):  # 左側は最低2つ残さなきゃいけないから2から(0もあるので）、右も同じ理由でN-1
    # 左の真ん中
    Lmid = cumsum[i] / 2
    
    # 左真ん中がどこに入るべきか
    Lx = bisect_left(cumsum, Lx)
    
    # Lxまで取るのか、Lx-1まで取るのか（どこまで取ると望ましい値Lmidに近づくのか）
    # 左側がLmidに近づくと右側もLmidに近づく→差の絶対値が0に近づく
    if abs(cumsum[Lx-1] - Lmid) < abs(cumsum[Lx] - Lmid):
        Lmid -= 1


    # 右側処理（基本は左と同じ）
    Rmid = (cumsum[N] + cumsum[i]) / 2  # 3分探索に要領でcumsum[i]を加えてやる
    Rx = bisect_left(cumsum, Rmid)
    # 超えるべきか超えないべきか
    if abs(cumsum[Rx-1] - Rmid) < abs(cumsum[Rx] - Rmid):
        Rx -= 1
    
    
    # 左からLx個の和
    P = cumsum[Lx]
    
    # Lx番目+1から真ん中区切りiまでの和
    Q = cumsum[i]-cumsum[Lx]
    
    # 真ん中区切りのi+1番目からRx番目までの和
    R = cumsum[Rx]-cumsum[i]
    
    # Rx+1番目から最後まで
    S = cumsum[N]-cumsum[Rx]
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
X = sum(A) / 4

i = 0
tmp = 0
B, C, D, E = [], [], [], []
while True:
    B.append(A[i])
    tmp += A[i]
    i += 1
    if tmp > X:
        #print(B, tmp)
        if abs(X - (tmp - A[i-1])) < (tmp - X) and len(B) > 1:
            del B[-1]
            i -= 1
        break

tmp = 0
while True:
    C.append(A[i])
    tmp += A[i]
    i += 1
    if tmp > X:
        #print(X, tmp, C)
        if abs(X - (tmp - A[i-1])) < (tmp - X) and len(C) > 1:
            del C[-1]
            i -= 1
        break

tmp = 0
while True:
    D.append(A[i])
    tmp += A[i]
    i += 1
    if tmp > X or i == N - 1:
        if abs(X - (tmp - A[i-1])) < (tmp - X) and len(D) > 1:
            del D[-1]
            i -= 1
        break

tmp = 0
while i < N:
    E.append(A[i])
    tmp += A[i]
    i += 1

#print(B, C, D, E)
P, Q, R, S = sum(B), sum(C), sum(D), sum(E)
print(max(P, Q, R, S) - min(P, Q, R, S))
Problem p03330 (python)

Fixed submission:
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
G = [list(map(int, input().split())) for i in range(N)]

change = [[0]*C for i in range(3)]
for c in range(C):
    for i in range(1, N+1):
        for j in range(1, N+1):
            change[(i+j) % 3][c] += (D[G[i-1][j-1]-1][c] if G[i-1][j-1] != c+1 else 0)

ans = float('inf')
for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            if len(set((c1, c2, c3))) != 3:
                continue
            ans = min(ans, change[0][c1] + change[1][c2] + change[2][c3])

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import permutations
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]  # 違和感
G = [list(map(int, input().split())) for i in range(N)]  # 初期盤面
X = [[0] * C for i in range(3)]  # modが0~2 × 各色への変更 の違和感の和

for c in range(C):  # 色
    tmp = [0] * 3  # 各modの違和感の和
    for i in range(N):
        for j in range(N):
            tmp[(i + j) % 3] += D[G[i][j] - 1][c]
    for t in range(3):
        X[c][t] = tmp[t]

ans = float('inf')
for c1, c2, c3 in permutations(range(C), 3):
    ans = min(ans, X[0][c1] + X[1][c2] + X[2][c3])

print(ans)
Problem p03374 (python)

Fixed submission:
N, C = map(int, input().split())
X, V = [], []
for i in range(N):
    xi, vi = map(int, input().split())
    X.append(xi)
    V.append(vi)

r_cal = [0]
l_cal = [0]
for i in range(N):
    r_cal.append(r_cal[-1] + V[i])
    l_cal.append(l_cal[-1] + V[N-i-1])

# 折り返さないパターン and 折り返してどこまでいくのか
r_straight = r_cal.copy()
l_straight = l_cal.copy()

for i in range(1, N+1):
    r_straight[i] -= X[i-1]
    l_straight[i] -= (C - X[N-i])

# 折り返すパターン
for i in range(1, N+1):
    r_cal[i] -= 2*X[i-1]
    l_cal[i] -= 2*(C - X[N-i])

# 折り返した後どこまで行くのが最適か
r_max = [0]
l_max = [0]
for i in range(1, N+1):
    r_max.append(max(r_max[-1], r_straight[i]))
    l_max.append(max(l_max[-1], l_straight[i]))

ans = max(r_max[-1], l_max[-1])
for i in range(N):
    ans = max(ans, r_cal[i] + l_max[N-i])
    ans = max(ans, l_cal[N-i] + r_max[i])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
X, V = [], []
for i in range(N):
    xi, vi = map(int, input().split())
    X.append(xi)
    V.append(vi)

r_cal = [0]
l_cal = [0]
for i in range(N):
    r_cal.append(r_cal[-1] + V[i])
    l_cal.append(l_cal[-1] + V[N-i-1])

# 折り返さないパターン and 折り返してどこまでいくのか
r_straight = r_cal.copy()
l_straight = l_cal.copy()

for i in range(1, N+1):
    r_straight[i] -= X[i-1]
    l_straight[i] -= (C - X[N-i])

# 折り返すパターン
for i in range(1, N+1):
    r_cal[i] -= 2*X[i-1]
    l_cal[i] -= 2*(C - X[N-i])

# 折り返した後どこまで行くのが最適か
r_max = [0]
l_max = [0]
for i in range(1, N+1):
    r_max.append(max(r_max[-1], r_straight[i]))
    l_max.append(max(l_max[-1], l_straight[i]))

ans = max(r_max[-1], l_max[-1])
for i in range(N):
    ans = max(ans, r_cal[i] + l_max[N-i])
    ans = max(ans, l_cal[N-i] + r_max[i])
print(ans)
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
ans = []
for a in range(A, min(A+K, B+1)):
    ans.append(a)
for b in range(max(A+K, B-K+1), B+1):
    ans.append(b)
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
Z = list(range(A, B+1))
Z = Z[:K] + Z[-K:]
A = set()
for z in Z:
    if z not in A:
        print(z)
        A.add(z)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
Z = list(range(A, B+1))
Z = Z[:K] + Z[-K:]
Z = set(Z)
Z = sorted(list(Z))
for z in Z:
    print(z)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
Z = list(range(A, B+1))
Z = Z[:K] + Z[-K:]
Z = set(Z)
Z = sorted(list(Z))
print(*Z, sep="\n")
Problem p03393 (python)

Fixed submission:
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            Z = sorted(list(filter(lambda x: x > S[i], S[i:])))
            print("".join(S[:i]) + Z[0])
            break
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
S = input()
A = [chr(ord("a")+i) for i in range(26)]

if len(set(S)) != 26:
    for a in A:
        if a not in S:
            print(S + a)
            break
else:
    used = []
    for i in range(1, 26):
        if S[-i] < S[-i-1]:
            used.append(S[-i])
        else:
            used.sort()
            print(S[:-i-1]+used[0])
            break
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
S = input()
A = [chr(ord("a")+i) for i in range(26)]

if len(set(S)) < 26:
    for a in A:
        if a not in S:
            print(S+a)
            break
else:
    X = []
    for i in range(25, 0, -1):
        if S[i] > S[i-1]:
            X.sort()
            print(S[:i-1]+X[0])
            break
        else:
            X.append(S[i])
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
S = input()
C = [chr(97+i) for i in range(26)]


if S == "".join(C.sort(reverse=True)):
    print(-1)

elif len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    K = []
    for i in range(25, -1, -1):
        K.append(S[i])
        K.sort()
        for j in range(25, -1, -1):
            if K[0] > S[j]:
                print(S[:j])
                exit()
Problem p03402 (python)

Fixed submission:
A, B = map(int, input().split())
white = [["#"] * 100 for i in range(50)]
black = [["."] * 100 for i in range(50)]
A, B = A-1, B-1

row = 0
line = 0
for i in range(A):
    white[line][row] = "."
    row += 2
    if row >= 100:
        row = 0
        line += 2

row = 0
line = 1
for i in range(B):
    black[line][row] = "#"
    row += 2
    if row >= 100:
        row = 0
        line += 2

ans = white + black
print(100, 100)
for a in ans:
    print("".join(a))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
G1 = [['#'] * 100 for i in range(50)]
G2 = [['.'] * 100 for i in range(50)]

A, B = A - 1, B - 1

h, w = 0, 0
for a in range(A):
    if w > 99:
        h += 1
    G1[h][w] = '.'
    w += 2

h, w = 1, 0
for b in range(B):
    if w > 99:
        h += 1
    G2[h][w] = '#'
    w += 2


print(100, 100)
for g in G1:
    print(''.join(g))
for g in G2:
    print(''.join(g))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
G1 = [['#'] * 100 for i in range(100)]
G2 = [['.'] * 100 for i in range(100)]

A, B = A - 1, B - 1

h, w = 0, 0
for a in range(A):
    if w > 99:
        h += 1
    G1[h][w] = '.'
    w += 2

h, w = 1, 0
for b in range(B):
    if w > 99:
        h += 1
    G2[h][w] = '#'
    w += 2


print(100, 100)
for g in G1:
    print(''.join(g))
for g in G2:
    print(''.join(g))
Problem p03438 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [B[i]-A[i] for i in range(N)]

P = sum(filter(lambda x: x<0, C))
M = list(filter(lambda x: x>1, C))
M = list(map(lambda x: x//2, M))

M = sum(M)
if abs(M) >= abs(P):
    print("Yes")
else:
    print("No")

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

C = [A[i]-B[i] for i in range(N)]
if 0 in C:
    print("Yes")
    exit()

Cplus = list(filter(lambda x:x>0, C))
Cminas = list(filter(lambda  x:x<0, C))

Cplus.sort(reverse=True)
pl = len(Cplus)
Cminas.sort()
ml = len(Cminas)

i = 0
j = 0
while True:
    if Cplus[i] > 0:
        if Cminas[j] <= -2:
            Cplus[i] -= 1
            Cminas[j] += 2
        else:
            j += 1
            if j >= ml:
                print("No")
                break
    else:
        i += 1
        if i >= pl:
            print("No")
            break

    if (Cplus[-1] <= 0) & (Cminas[-1] <= 0):
        print("Yes")
        break
Problem p03439 (python)

Fixed submission:
N = int(input())
seats = [""] * N

# 準備
print(0)
seats[0] = input()
if seats[0] == "Vacant":
    exit()
print(N - 1)
seats[N - 1] = input()
if seats[N - 1] == "Vacant":
    exit()

l = 0
r = N - 1
while True:
    m = (l + r) // 2
    print(m)

    s = input()
    if s == "Vacant":
        exit()
    seats[m] = s

    if (seats[l] == seats[m]) & ((m - l) % 2 == 1):
        r = m
    elif (seats[l] != seats[m]) & ((m-l) % 2 == 0):
        r = m
    else:
        l = m

Buggy submission (verdict: Runtime Error):
N = int(input())
seats = [""] * N

# 準備
print(0)
seats[0] = input()
print(N - 1)
seats[N - 1] = input()

l = 0
r = N - 1
while True:
    m = (l + r) // 2
    print("l,r =", l, r)
    print(m)
    s = input()
    if s == "Vacant":
        exit()

    if seats[l] == seats[m]:
        if (r-l) % 2 == 0:
            l = m + 1
        else:
            r = m -1
    else:
        if (r-l) % 2 == 1:
            r = m - 1
        else:
            l = m + 1