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

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

N, M = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    adjL[A-1].append(B-1)
    adjL[B-1].append(A-1)

if M % 2:
    print(-1)
    sys.exit()

def makeSpanningTree(vNow, vPar):
    useds[vNow] = True
    for v2 in adjL[vNow]:
        if v2 == vPar:
            pass
        elif useds[v2]:
            if vNow < v2:
                anss.append((vNow, v2))
                outdegs[vNow] += 1
        else:
            adjL2[vNow].append(v2)
            adjL2[v2].append(vNow)
            makeSpanningTree(v2, vNow)

anss = []
adjL2 = [[] for _ in range(N)]
outdegs = [0] * N
useds = [False] * (N)
makeSpanningTree(0, -1)

def dfs(vNow, vPar):
    for v2 in adjL2[vNow]:
        if v2 != vPar:
            dfs(v2, vNow)
    if outdegs[vNow] % 2:  # 出す
        anss.append((vNow, vPar))
        outdegs[vNow] += 1
    else:  # 入れる
        anss.append((vPar, vNow))
        outdegs[vPar] += 1

dfs(0, -1)
anss.pop()

print('\n'.join(map(lambda x: str(x[0]+1)+' '+str(x[1]+1), anss)))

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

N, M = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    adjL[A-1].append(B-1)
    adjL[B-1].append(A-1)

if M % 2:
    print(-1)
    sys.exit()

anss = []
degs = [0] * N
useds = [False] * N

vNotLeafs = []
for v in range(N):
    if len(adjL[v]) == 1:
        v0 = adjL[v][0]
        anss.append(v0, v)
        degs[v0] += 1
        useds[v] = True
    else:
        vNotLeafs.append(v)
#print(vNotLeafs)

def dfs(vNow):
    if degs[vNow] % 2 == 0:
        useds[vNow] = True
    for v2 in adjL[vNow]:
        if useds[v2]: continue
        if not useds[vNow]:
            anss.append((vNow, v2))
            degs[vNow] += 1
            useds[vNow] = True
        else:
            anss.append((v2, vNow))
            degs[v2] += 1
        dfs(v2)

dfs(vNotLeafs[0])

print('\n'.join(map(lambda x: str(x[0]+1)+' '+str(x[1]+1), anss)))
Problem p03006 (python)

Fixed submission:
N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]

balls.sort()

ans = N
for i in range(N):
    for j in range(i+1, N):
        p, q = balls[j][0]-balls[i][0], balls[j][1]-balls[i][1]
        useds = [False] * N
        num = 0
        for a in range(N):
            if useds[a]: continue
            useds[a] = True
            num += 1
            x, y = balls[a]
            for b in range(a+1, N):
                if useds[b]: continue
                if balls[b] == (x+p, y+q):
                    useds[b] = True
                    x, y = balls[b]
        ans = min(ans, num)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]

diffs = Counter()
for i in range(N):
    x1, y1 = balls[i]
    for j in range(i+1, N):
        x2, y2 = balls[j]
        diffs.update([(x2-x1, y2-y1)])

ans = N - diffs.most_common(1)[0][1]
print(ans)
Problem p03019 (python)

Fixed submission:
from itertools import accumulate
import sys
input = sys.stdin.readline

def solve():
    N, X = map(int, input().split())
    tests = []
    D0 = 0
    for _ in range(N):
        B, L, U = map(int, input().split())
        v = L*B + U*(X-B)
        tests.append((v, B, L, U))
        D0 -= L*B
    tests.sort(reverse=True)

    accV = 0
    accVs = [0]
    for v, B, L, U in tests:
        accV += v
        accVs.append(accV)

    def isOK(k):
        q = k // X
        r = k % X
        accV = accVs[q+1]
        for v, B, L, U in tests[:q]:
            d = D0 + accV - v
            if r <= B:
                d += L*r
            else:
                d += L*B + U*(r-B)
            if d >= 0:
                return True
        accV = accVs[q]
        for v, B, L, U in tests[q:]:
            d = D0 + accV
            if r <= B:
                d += L*r
            else:
                d += L*B + U*(r-B)
            if d >= 0:
                return True
        return False

    ng, ok = -1, N*X
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    return ok


print(solve())

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import sys
input = sys.stdin.readline

def solve():
    N, X = map(int, input().split())
    tests = []
    D0 = 0
    for _ in range(N):
        B, L, U = map(int, input().split())
        v = L*B + U*(X-B)
        tests.append((v, B, L, U))
        D0 -= L*B
    tests.sort(reverse=True)
    accVs = list(accumulate([0] + tests, lambda accX, X: accX + X[0]))

    def isOK(k):
        q = k // X
        r = k % X
        accV = accVs[q+1]
        for v, B, L, U in tests[:q]:
            d = D0 + accV - v
            if r <= B:
                d += L*r
            else:
                d += L*B + U*(r-B)
            if d >= 0:
                return True
        accV = accVs[q]
        for v, B, L, U in tests[q:]:
            d = D0 + accV
            if r <= B:
                d += L*r
            else:
                d += L*B + U*(r-B)
            if d >= 0:
                return True
        return False

    ng, ok = -1, N*X
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    return ok


print(solve())
Problem p03050 (python)

Fixed submission:
N = int(input())

anss = set()
for X in range(1, int(N**0.5)+2):
    if (N-X) % X == 0:
        m = (N-X) // X
        if m <= 0: continue
        if N//m == N%m:
            anss.add(m)

for m in range(1, int(N**0.5)+2):
    if N//m == N%m:
        anss.add(m)

print(sum(anss))

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

anss = set()
for X in range(1, int(N**0.5)+2):
    if (N-X) % X == 0:
        m = (N-X) // X
        if N//m == N%m:
            anss.add(m)

for m in range(1, int(N**0.5)+2):
    if N//m == N%m:
        anss.add(m)

print(sum(anss))
Problem p03074 (python)

Fixed submission:
from itertools import accumulate

N, K = map(int, input().split())
Ss = list(map(int, input()))

consecutive01s = [[], [0]]
turn = 0
num = 0
for S in Ss+[9]:
    if S == turn:
        num += 1
    else:
        consecutive01s[turn].append(num)
        turn = 1-turn
        num = 1
if turn == 0:
    consecutive01s[0].append(0)
consecutive01s[1].append(0)

N0, N1 = len(consecutive01s[0]), len(consecutive01s[1])
K = min(K, N0)

acc0s = list(accumulate([0]+consecutive01s[0]))
acc1s = list(accumulate([0]+consecutive01s[1]))

len0s = [acc0s[i+K]-acc0s[i] for i in range(N0-K+1)]
len1s = [acc1s[i+K+1]-acc1s[i] for i in range(N1-K)]

ans = max([len0+len1 for len0, len1 in zip(len0s, len1s)])
print(ans)

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

N, K = map(int, input().split())
Ss = list(map(int, input()))

consecutive01s = [[], [0]]
turn = 0
num = 0
for S in Ss+[9]:
    if S == turn:
        num += 1
    else:
        consecutive01s[turn].append(num)
        turn = 1-turn
        num = 1
if turn == 0:
    consecutive01s[0].append(0)
consecutive01s[1].append(0)

N0, N1 = len(consecutive01s[0]), len(consecutive01s[1])

acc0s = list(accumulate([0]+consecutive01s[0]))
acc1s = list(accumulate([0]+consecutive01s[1]))

len0s = [acc0s[i+K]-acc0s[i] for i in range(N0-K+1)]
len1s = [acc1s[i+K+1]-acc1s[i] for i in range(N1-K)]

ans = max([len0+len1 for len0, len1 in zip(len0s, len1s)])
print(ans)
Problem p03142 (python)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].append(v-1)
    indegs[v-1] += 1

parents = [-1] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        parents[v2] = vNow
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)

for v in range(N):
    print(parents[v] + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
adjL = [set() for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].add(v-1)
    indegs[v-1] += 1

parents = [-1] * N
v0s = [set() for v in range(N)] # 前回まで
vRoot = [v for v in range(N) if indegs[v] == 0][0]

vNows = set([vRoot])
while vNows:
    vNexts = set()
    v0News = [set() for v in range(N)] # 今回新しく
    for vNow in vNows:
        for v2 in adjL[vNow]:
            parents[v2] = vNow
            vNexts.add(v2)
            v0News[v2].add(vNow)
    vNows = vNexts

    for v in range(N):
        if not v0News[v]: continue
        for v0 in v0s[v]:
            adjL[v0].remove(v)
    for v in range(N):
        v0s[v] = v0News[v]

for v in range(N):
    print(parents[v] + 1)
Problem p03158 (python)

Fixed submission:
from itertools import accumulate
import sys

# 整数Xのときの[高橋くんが上から取る連続枚数]が、k枚以下（k+1以上にはならない）かどうか判定する
def check(X, k):
    # 青木くんがLより先にRを取れれば、条件を満たす
    L, R = As[N-2*k-1], As[N-k-1]
    return abs(L-X) > abs(X-R)

N, Q = map(int, input().split())
As = list(map(int, input().split()))
Xs = [(int(input()), iX) for iX in range(Q)]

if N == 2:
    print('\n'.join(map(str, [As[-1]]*Q)))
    sys.exit()

numT = (N+1) // 2  # 高橋くんが取るカードの枚数
Ascs = As[::2] if N % 2 else As[1::2]
Descs = As[::-1]
accAscs = [0] + list(accumulate(Ascs))
accDescs = [0] + list(accumulate(Descs))

# 高橋くんが上から連続k枚を取る場合のスコア
scores = [0] * (numT+1)
for k in range(1, numT+1):
    scores[k] = accDescs[k] + accAscs[numT - k]

# Xの降順で処理する
anss = [0] * Q
k = 1
for X, iX in sorted(Xs, reverse=True):
    # [k枚以下]になる最小のkを求める
    while not check(X, k):
        k += 1
    anss[iX] = scores[k]

print('\n'.join(map(str, anss)))

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

# 整数Xのときの[高橋くんが上から取る連続枚数]が、k枚以下（k+1以上にはならない）かどうか判定する
def check(X, k):
    # 青木くんがLより先にRを取れれば、条件を満たす
    L, R = As[N-2*k-1], As[N-k-1]
    return abs(L-X) > abs(X-R)

N, Q = map(int, input().split())
As = list(map(int, input().split()))
Xs = [(int(input()), iX) for iX in range(Q)]

numT = (N+1) // 2  # 高橋くんが取るカードの枚数
Ascs = As[::2] if N % 2 else As[1::2]
Descs = As[::-1]
accAscs = [0] + list(accumulate(Ascs))
accDescs = [0] + list(accumulate(Descs))

# 高橋くんが上から連続k枚を取る場合のスコア
scores = [0] * (numT+1)
for k in range(1, numT+1):
    scores[k] = accDescs[k] + accAscs[numT - k]

# Xの降順で処理する
anss = [0] * Q
k = 1
for X, iX in sorted(Xs, reverse=True):
    # [k枚以下]になる最小のkを求める
    while not check(X, k):
        k += 1
    anss[iX] = scores[k]

print('\n'.join(map(str, anss)))
Problem p03175 (python)

Fixed submission:
from collections import deque

MOD = 10**9 + 7

N = int(input())
adjL = [[] for v in range(N)]
degs = [0] * N
for _ in range(N-1):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    adjL[y-1].append(x-1)
    degs[x-1] += 1
    degs[y-1] += 1

dpWhite = [1] * N
dpBlack = [1] * N
vNow = 0
Q = deque([v for v in range(N) if degs[v] == 1])
while Q:
    vNow = Q.popleft()
    if degs[vNow] == 0: break
    dpW, dpB = dpWhite[vNow], dpBlack[vNow]
    for v2 in adjL[vNow]:
        if degs[v2] == 0: continue
        dpWhite[v2] *= dpW + dpB
        dpWhite[v2] %= MOD
        dpBlack[v2] *= dpW
        dpBlack[v2] %= MOD
        degs[v2] -= 1
        if degs[v2] == 1:
            Q.append(v2)
    degs[vNow] = 0

print((dpWhite[vNow] + dpBlack[vNow]) % MOD)

Buggy submission (verdict: Runtime Error):
from collections import deque

MOD = 10**9 + 7

def rec(vNow, vPar):
    W, B = 1, 1
    for v2 in adjL[vNow]:
        if v2 == vPar: continue
        W2, B2 = rec(v2, vNow)
        W = (W * (W2+B2)) % MOD
        B = (B * W2) % MOD
    return (W, B)

N = int(input())
adjL = [[] for v in range(N)]
for _ in range(N-1):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    adjL[y-1].append(x-1)

print(sum(rec(0, -1)) % MOD)
Problem p03203 (python)

Fixed submission:
H, W, N = map(int, input().split())
posObss = [{H} for y in range(W)]
for _ in range(N):
    X, Y = map(int, input().split())
    posObss[Y - 1].add(X - 1)

ans = H
xNow = 0
for y in range(W):
    xLim = min([x for x in posObss[y] if x > xNow])
    ans = min(ans, xLim)

    if y == W - 1: break
    xNow += 1
    while xNow in posObss[y + 1]:
        xNow += 1
    if xNow >= xLim: break

print(ans)

Buggy submission (verdict: Runtime Error):
H, W, N = map(int, input().split())
posObss = [{H} for y in range(W)]
for _ in range(N):
    X, Y = map(int, input().split())
    posObss[Y - 1].add(X - 1)

ans = H
xNow = 0
for y in range(W):
    xLim = min([x for x in posObss[y] if x > xNow])
    ans = min(ans, xLim)

    xNow += 1
    while xNow in posObss[y + 1]:
        xNow += 1
    if xNow >= xLim: break

print(ans)
Problem p03223 (python)

Fixed submission:
N = int(input())
As = [int(input()) for _ in range(N)]

As.sort(reverse=True)

if N % 2:
    ans = 2 * sum(As[:N//2 - 1]) - 2 * sum(As[N//2 + 2:])
    A1, A2, A3 = As[N//2 - 1:N//2 + 2]
    ans += max(A1 + A2 - 2*A3, 2*A1 - A2 - A3)
else:
    ans = 2 * sum(As[:N//2 - 1]) + As[N//2 - 1] - As[N//2] - 2 * sum(As[N//2 + 1:])

print(ans)

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

As.sort()
#print(As)

def f(As):
    Bs = [0] * N
    iB = N // 2
    d = -2
    for A in As[:N//2]:
    #    print(A, iB, d)
        Bs[iB] = A
        iB += d
        if d > 0:
            d = -d - 2
        else:
            d = -d + 2
#    print(Bs)

    if N % 2:
        iB = N // 2 + 1
        d = -2
    else:
        iB = N // 2 - 1
        d = +2
    for A in reversed(As[N//2:]):
        Bs[iB] = A
        iB += d
        if d > 0:
            d = -d - 2
        else:
            d = -d + 2
#    print(Bs)

    ans = 0
    for i in range(N - 1):
        ans += abs(Bs[i + 1] - Bs[i])
#    print(ans)
    return ans

print(max(f(As), f(As[::-1])))
Problem p03247 (python)

Fixed submission:
import sys

LEN_D = 31
CONST = 2**LEN_D - 1

N = int(input())
XYs = [tuple(map(int, input().split())) for _ in range(N)]

parities = [(X+Y) % 2 for X, Y in XYs]
if len(set(parities)) != 1:
    print(-1)
    sys.exit()

if parities[0]:
    m = LEN_D
    ds = [2**i for i in range(LEN_D)]
else:
    m = LEN_D + 1
    ds = [1] + [2**i for i in range(LEN_D)]
print(m)
print(*ds)

for X, Y in XYs:
    ws = []
    if (X+Y) % 2 == 0:
        X -= 1
        ws.append('R')
    u = ((X+Y) + CONST) // 2
    v = ((X-Y) + CONST) // 2
    for i in range(LEN_D):
        ws.append('LDUR'[((u>>i) & 1) * 2 + ((v>>i) & 1)])
    print(''.join(ws))

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
XYs = [tuple(map(int, input().split())) for _ in range(N)]

parities = [(X+Y) % 2 for X, Y in XYs]
if len(set(parities)) != 1:
    print(-1)
    sys.exit()

m = 19 if parities[0] else 20
ds = [1] * m
print(m)
print(*ds)

for X, Y in XYs:
    if X >= 0:
        ws = ['R'] * X
    else:
        ws = ['L'] * -X
    if Y >= 0:
        ws += ['U'] * Y
    else:
        ws += ['D'] * -Y
    ws += ['RL'] * ((m-abs(X)-abs(Y)) // 2)
    print(''.join(ws))
Problem p03276 (python)

Fixed submission:
from bisect import bisect_left

N, K = map(int, input().split())
xs = list(map(int, input().split()))

num1 = bisect_left(xs, 0)
num2 = N - num1

d1s = [0] + [-x for x in xs[:num1]][::-1]
d2s = [0] + xs[num1:]

ans = float('inf')
for i in range(max(0, K - num2), min(num1, K) + 1):
    d1, d2 = d1s[i], d2s[K - i]
    ans = min(ans, d1 + d2 + min(d1, d2))

print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

N, K = map(int, input().split())
xs = list(map(int, input().split()))

num1 = bisect_left(xs, 0)
num2 = N - num1

d1s = [0] + [-x for x in xs[:num1]][::-1]
d2s = [0] + xs[num1:]

ans = float('inf')
for i in range(max(0, K - num2), num1 + 1):
    d1, d2 = d1s[i], d2s[K - i]
    ans = min(ans, d1 + d2 + min(d1, d2))

print(ans)
Problem p03357 (python)

Fixed submission:
N = int(input())
balls = []
for i in range(2 * N):
    c, a = input().split()
    balls += [(c, int(a))]

# numB[i][b]: 初期状態において、i番目の玉より右にある、1～bが書かれた黒玉の数
numB = [[0] * (N + 1) for i in range(2 * N)]
numW = [[0] * (N + 1) for i in range(2 * N)]
for i in reversed(range(1, 2 * N)):
    c, a = balls[i]
    numB[i - 1] = list(numB[i])
    numW[i - 1] = list(numW[i])
    if c == 'B':
        for b in range(a, N + 1):
            numB[i - 1][b] += 1
    else:
        for w in range(a, N + 1):
            numW[i - 1][w] += 1

# costB[b][w]: 黒玉1～b、白玉1～wのうち、初期状態において、黒玉[b+1]より右にある玉の数
costB = [[0] * (N + 1) for i in range(N + 1)]
costW = [[0] * (N + 1) for i in range(N + 1)]
for i in reversed(range(2 * N)):
    c, a = balls[i]
    if c == 'B':
        cost = numB[i][a - 1]
        for w in range(N + 1):
            costB[a - 1][w] = cost + numW[i][w]
    else:
        cost = numW[i][a - 1]
        for b in range(N + 1):
            costW[b][a - 1] = cost + numB[i][b]

dp = [[float('inf')] * (N + 1) for i in range(N + 1)]
dp[0][0] = 0
for b in range(N + 1):
    for w in range(N + 1):
        if b > 0:
            dp[b][w] = min(dp[b][w], dp[b - 1][w] + costB[b - 1][w])
        if w > 0:
            dp[b][w] = min(dp[b][w], dp[b][w - 1] + costW[b][w - 1])

print(dp[N][N])

Buggy submission (verdict: Runtime Error):
N = int(input())
balls = []
for i in range(2 * N):
    c, a = input().split()
    balls += [(c, int(a))]

# numB[i][b]: 初期状態において、i番目の玉より右にある、1～bが書かれた黒玉の数
numB = [[0] * (N + 1) for i in range(2 * N)]
numW = [[0] * (N + 1) for i in range(2 * N)]
for i in reversed(range(1, 2 * N)):
    c, a = balls[i]
    numB[i - 1] = numB[i].copy()
    numW[i - 1] = numW[i].copy()
    if c == 'B':
        for b in range(a, N + 1):
            numB[i - 1][b] += 1
    else:
        for w in range(a, N + 1):
            numW[i - 1][w] += 1

# costB[b][w]: 黒玉1～b、白玉1～wのうち、初期状態において、黒玉[b+1]より右にある玉の数
costB = [[0] * (N + 1) for i in range(N + 1)]
costW = [[0] * (N + 1) for i in range(N + 1)]
for i in reversed(range(2 * N)):
    c, a = balls[i]
    if c == 'B':
        cost = numB[i][a - 1]
        for w in range(N + 1):
            costB[a - 1][w] = cost + numW[i][w]
    else:
        cost = numW[i][a - 1]
        for b in range(N + 1):
            costW[b][a - 1] = cost + numB[i][b]

dp = [[float('inf')] * (N + 1) for i in range(N + 1)]
dp[0][0] = 0
for b in range(N + 1):
    for w in range(N + 1):
        if b > 0:
            dp[b][w] = min(dp[b][w], dp[b - 1][w] + costB[b - 1][w])
        if w > 0:
            dp[b][w] = min(dp[b][w], dp[b][w - 1] + costW[b][w - 1])

print(dp[N][N])
Problem p03390 (python)

Fixed submission:
Q = int(input())
querys = [tuple(map(int, input().split())) for _ in range(Q)]

anss = []
for A, B in querys:
    if A > B:
        A, B = B, A

    if A == B:
        ans = 2*(A-1)
    elif A+1 == B:
        ans = 2*(A-1)
    else:
        C = -(-((A*B)**0.5) // 1) - 1
        if C*(C+1) >= A*B:
            ans = 2*(C-1)
        else:
            ans = 2*C-1

    anss.append(int(ans))

print('\n'.join(map(str, anss)))

Buggy submission (verdict: Runtime Error):
import math

Q = int(input())
ABs = [list(map(int, input().split())) for i in range(Q)]

for A, B in ABs:
    n = math.floor(math.sqrt(A * B - 1))
    ans = 2 * n

    if (A * B - 1) // n == n:
        ans -= 1
    if A <= n:
        ans -= 1
    if B <= n - 1:
        ans -= 1

    print(ans)
Problem p03421 (python)

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

if A + B - 1 > N or A * B < N:
    print('-1')
else:
    ans = list(range(1, B + 1)[::-1])
    if A > 1:
        x = (N - B) // (A - 1)
        y = (N - B) % (A - 1)
        st = B + 1
        for i in range(y):
            ans += list(range(st, st + x + 1)[::-1])
            st += x + 1
        for i in range(A - 1 - y):
            ans += list(range(st, st + x)[::-1])
            st += x

    print(' '.join(map(str, ans)))

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

if A + B > N + 1:
    print('-1')
else:
    ans = list(range(N - B + 1, N + 1)[::-1])
    Ns = list(range(1, N - B + 1))
    for i in range((N - B) // (A - 1) + 1):
        st = i * (A - 1)
        ans = Ns[st:st + A - 1] + ans
    print(ans)
Problem p03463 (python)

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

if (B - A) % 2 == 0:
    print('Alice')
else:
    print('Borys')

Buggy submission (verdict: Runtime Error):
from math import ceil, floor

K = int(input())
As = list(map(int, input().split()))

L = 2
R = 2
for A in reversed(As):
    if R // A * A < L:
        print('-1')
        exit()
    L = ceil(L / A) * A
    R = floor(R / A) * A + A - 1

print(L, R)
Problem p03553 (python)

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

def func(Bs):
    for x in range(N):
        if Bs[x] >= 0: continue
        if max(Bs[x::x + 1]) <= 0:
            Bs[x] = 0

func(As)

zs = [27, 29, 31, 33] + list(range(34, 51))
for x in zs:
    if sum(As[x - 1::x]) < 0:
        for i in range(x - 1, N, x):
            As[i] = 0

ns = [1, 2, 4, 8, 16, 32] + [3, 6, 9, 12, 18, 24, 27, 36, 48] \
    + [5, 10, 15, 20, 25, 30, 40, 45, 50] + [7, 14, 21, 28, 35, 42, 49] \
    + [11, 22, 33, 44] + [13, 26, 39] + [17, 34] + [19, 38] + [23, 46] \
    + [29, 31, 37, 41, 43, 47]

memo = {}
memo[tuple(As)] = sum(As)

cs = [n - 1 for n in ns if n <= N and n not in zs and As[n - 1] < 0]
for c in cs:
    for tupleA in list(memo.keys()):
        if tupleA[c] == 0:
            continue

        listA = list(tupleA)
        for x in range(c, N, c + 1):
            listA[x] = 0

        func(listA)
        memo[tuple(listA)] = sum(listA)

print(max(memo.values()))

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

def func(Bs):
    for x in range(N):
        if Bs[x] >= 0: continue
        if max(Bs[x::x + 1]) <= 0:
            Bs[x] = 0

func(As)

for x in range(34, 51):
    if As[x - 1] + As[x * 2 - 1] < 0:
        As[x - 1] = 0
        As[x * 2 - 1] = 0

for x in [27, 29, 31, 33]:
    if As[x - 1] + As[x * 2 - 1] + As[x * 3 - 1] < 0:
        As[x - 1] = 0
        As[x * 2 - 1] = 0
        As[x * 3 - 1] = 0
zs = [27, 29, 31, 33] + list(range(34, 51))

ns = [1, 2, 4, 8, 16, 32] + [3, 6, 9, 12, 18, 24, 27, 36, 48] \
    + [5, 10, 15, 20, 25, 30, 40, 45, 50] + [7, 14, 21, 28, 35, 42, 49] \
    + [11, 22, 33, 44] + [13, 26, 39] + [17, 34] + [19, 38] + [23, 46] \
    + [29, 31, 37, 41, 43, 47]

memo = {}
memo[tuple(As)] = sum(As)

cs = [n - 1 for n in ns if n <= N and n not in zs and As[n - 1] < 0]
for c in cs:
    for tupleA in list(memo.keys()):
        if tupleA[c] == 0:
            continue

        listA = list(tupleA)
        for x in range(c, N, c + 1):
            listA[x] = 0

        func(listA)
        memo[tuple(listA)] = sum(listA)

print(max(memo.values()))