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

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


def solve(N: int, M: int, A: "List[int]"):
    c = dict()
    c[0] = 1
    total = 0
    res = 0
    for a in A:
        total = (total + a) % M
        if total in c:
            c[total] += 1
        else:
            c[total] = 1
        res += c[total] - 1
    print(res)
    return


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

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    c = dict((0, 1))
    total = 0
    res = 0
    for a in A:
        total = (total + a) % M
        c[total] = c.get(total, 0) + 1
        res += c[total] - 1
    print(res)
    return


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

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    c = [0] * M
    c[0] = 1
    total = 0
    for a in A:
        total = (total + a) % M
        c[total] += 1
    res = 0
    for t in c:
        res += t * (t-1) // 2
    print(res)
    return


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

if __name__ == '__main__':
    main()
Problem p03006 (python)

Fixed submission:
N = int(input())
if N == 1:
    print(1)
    exit()
D = []
for i in range(N):
    x, y = map(int, input().split())
    D.append((x, y))
D = sorted(D)

d = set()
for i in range(N):
    for j in range(N):
        d.add((D[i][0] - D[j][0], D[i][1] - D[j][1]))


d = list(d)
num = float('inf')
for p, q in d:
    if p == 0 and q == 0:
        continue
    used = [0] * N
    prex, prey = D[0][0], D[0][1]
    used[0] = 1
    tmp = 1
    for k in range(N - 1):
        for i in range(N):
            if used[i]:
                continue
            if D[i][0] - prex == p and D[i][1] - prey == q:
                prex = D[i][0]
                prey = D[i][1]
                used[i] = 1
                break
        else:
            tmp += 1
            for i in range(N):
                if not used[i]:
                    prex = D[i][0]
                    prey = D[i][1]
                    used[i] = 1
                    break
    num = min(tmp, num)

print(num)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
D = []
for i in range(N):
    x, y = map(int, input().split())
    D.append((x, y))

d = defaultdict(int)
for i in range(N):
    for j in range(i + 1, N):
        d[(D[i][0] - D[j][0], D[i][1] - D[j][1])] += 1

print(N - max(d.values()))
Problem p03032 (python)

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

ma = 0
for i in range(K):
    P = K - i
    for p in range(P + 1):
        q1 = []
        q2 = []
        s = 0
        for j in range(min(N, p)):
            if V[j] >= 0:
                s += V[j]
            else:
                q1.append(V[j])
        if len(q1) == p:
            q1 = []
        for j in range(N - 1, max(p - 1, N - (P - p) - 1), -1):
            if V[j] >= 0:
                s += V[j]
            else:
                q2.append(V[j])
        if len(q2) == P - p:
            q2 = []

        q = sorted(q1 + q2)
        if len(q) < i:
            t = 0
        else:
            t = sum(q[i:])
        ma = max(s + t, ma)

print(ma)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = list(map(int, input().split()))
que = []
ma = 0
for i in range(K):
    P = K - i
    for p in range(P + 1):
        q1 = []
        q2 = []
        s = 0
        for j in range(p):
            if V[j] >= 0:
                s += V[j]
            else:
                q1.append(V[j])
        if len(q1) == p:
            q1 = []
        for j in range(N - 1, N - (P - p) - 1, -1):
            if V[j] >= 0:
                s += V[j]
            else:
                q2.append(V[j])
        if len(q2) == P - p:
            q2 = []

        q = sorted(q1 + q2)
        if len(q) < i:
            t = 0
        else:
            t = sum(q[i:])
        ma = max(s + t, ma)

print(ma)
Problem p03039 (python)

Fixed submission:
N, M, K = map(int, input().split())
MOD = 10 ** 9 + 7

P = 200005
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[k] * rfact[n - k] % MOD


num = 0
for d in range(1, N):
    num += d * (N - d) * (M ** 2)
    num %= MOD

for d in range(1, M):
    num += d * (M - d) * (N ** 2)
    num %= MOD

num *= comb(N * M - 2, K - 2)
print(num % MOD)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
MOD = 10 ** 9 + 7

P = 100005
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[k] * rfact[n - k] % MOD


num = 0
for d in range(1, N):
    num += d * (N - d) * (M ** 2)
    num %= MOD

for d in range(1, M):
    num += d * (M - d) * (N ** 2)
    num %= MOD

num *= comb(N * M - 2, K - 2)
print(num % MOD)
Problem p03083 (python)

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

MOD = 10 ** 9 + 7
M = 200005
fact = [0] * M
fact[0] = 1
for i in range(1, M):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * M
rfact[M - 1] = pow(fact[M - 1], MOD - 2, MOD)
for i in range(M - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD

pow2 = [0] * M
pow2[0] = 1
for i in range(1, M):
    pow2[i] = pow2[i - 1] * 2
    pow2[i] %= MOD


def comb(n, k):
    if k < 0 or k > n:
        return 0
    return fact[n] * rfact[n - k] * rfact[k] % MOD


num = [0] * 200005
f = [0] * 200005
for i in range(W):
    q = pow(pow2[i + B], MOD - 2, MOD) * comb(i + B - 1, B - 1) % MOD
    f[i + B] = q

g = [0] * 200005
for i in range(B):
    q = pow(pow2[i + W], MOD - 2, MOD) * comb(i + W - 1, W - 1) % MOD
    g[i + W] = q
    num[i + W + 1] = q


inv2 = pow(2, MOD - 2, MOD)
pB, pW = 0, 0
for i in range(1, B + W + 1):
    d = 1 - (pB + pW) + 2 * MOD
    d %= MOD
    pB += f[i]
    pB %= MOD
    pW += g[i]
    pW %= MOD

    num[i] += num[i - 1]
    num[i] %= MOD
    print((inv2 * d + num[i]) % MOD)

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

MOD = 10 ** 9 + 7
M = 100005
fact = [0] * M
fact[0] = 1
for i in range(1, M):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * M
rfact[M - 1] = pow(fact[M - 1], MOD - 2, MOD)
for i in range(M - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    if k < 0 or k > n:
        return 0
    return fact[n] * rfact[n - k] * rfact[k] % MOD


num = [0] * 200005
f = [0] * 200005
for i in range(W):
    q = pow(pow(2, i + B), MOD - 2, MOD) * comb(i + B - 1, B - 1) % MOD
    f[i + B] = q

g = [0] * 200005
for i in range(B):
    q = pow(pow(2, i + W), MOD - 2, MOD) * comb(i + W - 1, W - 1) % MOD
    g[i + W] = q
    num[i + W + 1] = q

pB, pW = 0, 0
for i in range(1, B + W + 1):
    d = 1 - (pB + pW) + 2 * MOD
    d %= MOD
    pB += f[i]
    pB %= MOD
    pW += g[i]
    pW %= MOD

    num[i] += num[i - 1]
    num[i] %= MOD
    print((pow(2, MOD - 2, MOD) * d + num[i]) % MOD)
Problem p03141 (python)

Fixed submission:
N = int(input())
rec = []
num = 0
for i in range(N):
    a, b = map(int, input().split())
    rec.append(a + b)
    num -= b

rec = sorted(rec, reverse=True)
for i in range(N):
    if i % 2 == 0:
        num += rec[i]
print(num)

Buggy submission (verdict: Runtime Error):
N = int(input())
rec = []
for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b, i))

rec1 = sorted(rec, key=lambda x: x[0] - x[1], reverse=True)
rec2 = sorted(rec, key=lambda x: x[1] - x[0], reverse=True)
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        while i < N and used[i] != -1:
            i += 1
        num += rec1[i][0]
        used[rec1[i][2]] = 1
        i += 1
    else:
        while j < N and used[j] != -1:
            j += 1
        num -= rec2[j][1]
        used[rec2[j][2]] = 1
        j += 1

    k += 1

print(num)

Buggy submission (verdict: Runtime Error):
N = int(input())
rec = []
for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b, i))

rec1 = sorted(rec, key=lambda x: x[0] - x[1], reverse=True)
rec2 = sorted(rec, key=lambda x: x[1] - x[0], reverse=True)
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        while i < N and used[i] != -1:
            i += 1
        num += rec1[i][0]
        used[rec1[i][2]] = 1
        i += 1
    else:
        while j < N and used[j] != -1:
            j += 1
        num -= rec2[i][1]
        used[rec2[i][2]] = 1
        j += 1

    k += 1

print(num)

Buggy submission (verdict: Runtime Error):
N = int(input())
rec = []
for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b, i))

rec1 = sorted(rec, key=lambda x: x[0] - x[1], reverse=True)
rec2 = sorted(rec, key=lambda x: x[1] - x[0], reverse=True)
used = [-1] * N
i = 0
j = 0
k = 0
num = 0
while k < N:
    if k % 2 == 0:
        while used[i] != -1:
            i += 1
        num += rec1[i][0]
        used[rec1[i][2]] = 1
        i += 1
    else:
        while used[j] != -1:
            j += 1
        num -= rec2[i][1]
        used[rec2[i][2]] = 1
        j += 1

    k += 1

print(num)
Problem p03263 (python)

Fixed submission:
h, w = map(int, input().split())
T = [[] for i in range(h)]
S = [[0] * w for i in range(h)]
for i in range(h):
    a = list(map(int, input().split()))
    T[i] = a

for i in range(h):
    for j in range(w):
        T[i][j] = T[i][j] % 2

move = []
i = 0
j = 0
k = 0
flag = False
while True:
    px, py = i, j
    if T[i][j] == 1:
        flag = True
    if i % 2 == 0:
        j += 1
        if j == w:
            j -= 1
            i += 1
        if i == h:
            break
        if flag:
            move.append((px, py, i, j))
        if flag and T[i][j] == 1:
            T[i][j] = 0
            flag = False
        k += 1
    else:
        j -= 1
        if j == -1:
            j += 1
            i += 1
        if i == h:
            break
        if flag:
            move.append((px, py, i, j))
        if flag and T[i][j] == 1:
            T[i][j] = 0
            flag = False

print(len(move))
for i in range(len(move)):
    x, y, w, z = move[i][0] + 1, move[i][1] + 1, move[i][2] + 1, move[i][3] + 1
    print(x, y, w, z)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
T = [[] for i in range(h)]
S = [[0] * w for i in range(h)]
for i in range(h):
    a = list(map(int, input().split()))
    T[i] = a

for i in range(h):
    for j in range(w):
        T[i][j] = T[i][j] % 2

rec = []
for i in range(h):
    for j in range(w):
        if T[i][j] == 1:
            rec.append((i, j))

rec = sorted(rec)
rec = sorted(rec, key=lambda s: s[1])
move = []
for i in range(0, len(rec), 2):
    if i + 1 == len(rec):
        break
    a, b = rec[i], rec[i + 1]
    sx = a[0]
    sy = a[1]
    tx = b[0]
    ty = b[1]
    while sx != tx and S[sx][sy] != 1:
        move.append((sx, sy, sx + 1, sy))
        S[sx][sy] = 1
        sx += 1
    if sy <= ty:
        while sy != ty and S[sx][sy] != 1:
            move.append((sx, sy, tx, sy + 1))
            S[sx][sy] = 1
            sy += 1
    else:
        while sy != ty and S[sx][sy] != 1:
            move.append((sx, sy, tx, sy - 1))
            S[sx][sy] = 1
            sy -= 1

print(len(move))
for i in range(len(move)):
    x, y, w, z = move[i][0] + 1, move[i][1] + 1, move[i][2] + 1, move[i][3] + 1
    print(x, y, w, z)
Problem p03276 (python)

Fixed submission:
n, k = map(int, input().split())
x = list(map(int, input().split()))
pl, mi = 0, 0
recp, recm = [], []
for i in range(n):
    if x[i] >= 0:
        pl += 1
        recp.append(x[i])
    else:
        mi += 1
        recm.append(x[i])

num = float("inf")
recm = recm[:: -1]
for i in range(pl + 1):
    if i == 0:
        if k <= mi:
            num = min(num, abs(recm[k - 1]))
        else:
            continue
    else:
        if k - i == 0:
            num = min(num, recp[k - 1])
        elif 0 < k - i <= mi:
            num = min(num, recp[i - 1] + 2 * abs(recm[k - i - 1]))
            num = min(num, 2 * recp[i - 1] + abs(recm[k - i - 1]))

print(num)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))
zero = 0
for i in range(N):
    if X[i] >= 0:
        break
    zero += 1
p = len(X[zero:])
m = len(X[:zero])
pl = X[zero:]
mi = X[:zero]
mi = mi[::-1]
num = float("inf")
if m == 0:
    num = min(num, pl[K - 1])
elif p == 0:
    num = min(num, mi[K - 1])
else:
    for i in range(K + 1):
        j = K - i
        if 0 < j <= m and 0 < i:
            rec1 = pl[i - 1] * 2 + abs(mi[j - 1])
            rec2 = pl[i - 1] + 2 * abs(mi[j - 1])
            num = min(num, rec1)
            num = min(num, rec2)
        elif j == 0 and K - 1 < p:
            num = min(num, pl[K - 1])
        elif i == 0 and K - 1 < m:
            num = min(num, mi[K - 1])


print(num)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
n = len(s)
index = float("inf")
num = 0
for i in range(n):
    if s[i] != "1":
        index = i + 1
        num = s[i]
        break

if k < index:
    print(1)
else:
    print(num)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
i = 0
while i < len(S) and S[i] == "1":
    i += 1

if i != len(S) - 1:
    ans = S[i]

if K - 1 <= i:
    print(1)
else:
    print(S[i])
Problem p03323 (python)

Fixed submission:
a, b = map(int, input().split())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")
Problem p03356 (python)

Fixed submission:
N, M = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
rank = [0] * N
parent = [i for i in range(N)]


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(M):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)

num = 0
for i in range(N):
    num += same(i, P[i])

print(num)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
rank = [0] * N
parent = [i for i in range(N)]


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = parent[x]
    y = parent[y]
    if x == y:
        return

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(M):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)

num = 0
for i in range(N):
    num += same(i, P[i])

print(num)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
rank = [0] * N
parent = [i for i in range(N)]


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = parent[x]
    y = parent[y]

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(M):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)

num = 0
for i in range(N):
    num += same(i, P[i])

print(num)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
rank = [0] * N
parent = [i for i in range(N)]


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = parent[x]
    y = parent[y]

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


for i in range(M):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)

rec = [[] for i in range(N)]
rec2 = [[] for i in range(N)]
for i in range(N):
    rec[parent[i]].append(P[i])
    rec2[parent[i]].append(i)

num = 0
for i in range(N):
    num += same(i, P[i])

print(num)
Problem p03488 (python)

Fixed submission:
S = input()
x, y = map(int, input().split())

T = S.split("T")
u, v = [len(T[0])], [0]
dp = [u, v]
for i in range(1, len(T)):
    s = set()
    k = len(T[i])
    if i % 2 != 0:
        Q = dp[1]
        for j in Q:
            s.add(j - k)
            s.add(j + k)
        dp = [dp[0], list(s)]
    else:
        Q = dp[0]
        for j in Q:
            s.add(j - k)
            s.add(j + k)
        dp = [list(s), dp[1]]
if x in dp[0] and y in dp[1]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
dic = {"U": (1, 0), "R": (0, 1), "D": (-1, 0), "L": (0, -1)}
rec = []


def dfs(x1, y1, pos, k):
    if k == len(s):
        if (x1, y1) not in rec:
            rec.append((x1, y1))
        return
    else:
        if s[k] == "F":
            nx, ny = x1 + dic[pos][0], y1 + dic[pos][1]
            dfs(nx, ny, pos, k + 1)
        else:
            if pos == "U" or pos == "D":
                dfs(x1, y1, "R", k + 1)
                dfs(x1, y1, "L", k + 1)
            else:
                dfs(x1, y1, "U", k + 1)
                dfs(x1, y1, "D", k + 1)


dfs(0, 0, "R", 0)
if (y, x) in rec:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
sx, sy = 0, 0
dic = {"U":(1,0), "R":(0, 1), "D":(-1,0), "L":(0, -1)}
rec = []


def dfs(x1, y1, pos, k):
    if k == len(s):
        rec.append((x1, y1))
        return
    else:
        if s[k] == "F":
            nx, ny = x1 + dic[pos][0], y1 + dic[pos][1]
            dfs(nx, ny, pos, k + 1)
        else:
            if pos == "U" or pos == "D":
                dfs(x1, y1, "R", k + 1)
                dfs(x1, y1, "L", k + 1)
            else:
                dfs(x1, y1, "U", k + 1)
                dfs(x1, y1, "D", k + 1)


dfs(0, 0, "R", 0)
if (y, x) in rec:
    print("Yes")
else:
    print("No")
Problem p03563 (python)

Fixed submission:
N = int(input())
G = int(input())
print(2*G-N)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
rec = []
for i in range(len(S)):
    flag = True
    Z = S
    for j in range(len(T)):
        if Z[i] == T[j]:
            for e in range(i - j):
                if Z[e] == "?":
                    Z = Z.replace("?", "a", 1)
            for k in range(len(T)):
                if Z[i + k - j] == T[k]:
                    continue
                elif Z[i + k - j] == "?":
                    Z = Z.replace("?", T[k], 1)
                    print(Z)
                else:
                    flag = False
            if flag:
                Z = Z.replace("?", "a")
                rec.append(Z)
if rec == []:
    print("UNRESTORABLE")
else:
    print(rec[-1])
Problem p03599 (python)

Fixed submission:
a, b, c, d, e, f = map(int, input().split())
rec = (0, 0)
ma = 0
for i in range(31):
    for j in range(31):
        for k in range(100):
            t = i * a * 100 + j * b * 100 + c * k
            if t > f:
                break
            for l in range(100):
                s = i * a * 100 + j * b * 100 + c * k + d * l
                if s > f:
                    break
                if c * k + d * l > (a * i + b * j) * e:
                    break
                if (i * a + j * b + c * k + d * l) == 0:
                    continue
                q = (c * k + d * l) / (100 * i * a + 100 * j * b + c * k + d * l) * 100
                if q >= ma:
                    ma = q
                    rec = (s, c * k + d * l)

print(rec[0], rec[1])

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
num = None
rec = 0
for a in range(101):
    for b in range(101):
        if a * A * 100 + b * B * 100 > F:
            break
        for c in range(100):
            if a * A * 100 + b * B * 100 + c * C > F:
                break
            for d in range(100):
                q = a * A * 100 + b * B * 100
                p = C * c + D * d
                if p > E * (a * A + b * B):
                    continue
                if p + q == 0:
                    continue
                if p + q <= F:
                    if rec < 100 * p / (p + q):
                        rec = 100 * p / (p + q)
                        num = (p + q, p)
                else:
                    break
print(num[0], num[1])
Problem p03612 (python)

Fixed submission:
n = int(input())
p = [0] + list(map(int, input().split()))
num = 0
for i in range(1, n + 1):
    if i == n:
        if i == p[i]:
            num += 1
            break
    if i == p[i]:
        num += 1
        p[i], p[i + 1] = p[i + 1], p[i]

print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [0] + list(map(int, input().split()))
num = 0
for i in range(1, n + 1):
    if i == p[i]:
        num += 1
        p[i], p[i + 1] = p[i + 1], p[i]

print(num)