Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = map(float, input().split())

dp = [1] + [0] * N
for p in enumerate(P):
    dp = [p * a + (1 - p) * b for a, b in zip([0] + dp, dp)]

print(sum(dp[-(-N // 2):]))

Fixed submission:
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [float(i) for i in input().split()]

dp = [0.0] * (N + 1)
dp[0] = 1.0

for i, p in enumerate(P, 1):
    dp = [p * dp[j - 1] + (1 - p) * dp[j] for j in range(N + 1)]

print(sum(dp[-(-N // 2):]))

Fixed submission:
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))

Fixed submission:
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
P = [float(i) for i in input().split()]

dp = [0, 1, 0, 0, 0, 0]
for i, p in enumerate(P):
    print(dp)
    dp = [p * dp[j - 1] + (1 - p) * dp[j] for j in range(1, N + 2)]

print(sum(dp[-(-N // 2):]))

Fixed submission:
N = int(input())
P = [float(i) for i in input().split()]

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1.0

for i, p in enumerate(P, 1):
    for j in range(N + 1):
        dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j]

print(sum(dp[N][-(-N // 2):]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

from sys import setrecursionlimit
setrecursionlimit(300 ** 3 + 10)


N, *A = map(int, open(0).read().split())

memo = {(0, 0, 0): 0.0}
def dp(i, j, k):
    if (i, j, k) in memo:
        return memo[(i, j, k)]

    res = N
    if i > 0:
        res += i * dp(i - 1, j, k)
    if j > 0:
        res += j * dp(i + 1, j - 1, k)
    if k > 0:
        res += k * dp(i, j + 1, k - 1)

    res /= (i + j + k)

    memo[(i, j, k)] = res

    return res

C = Counter(A)
print(dp(C[1], C[2], C[3]))

Fixed submission:
from collections import Counter

N, *A = map(int, open(0).read().split())

C = Counter(A)
dp = [[[.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
for i in range(C[3] + 1):
    for j in range(N - C[1] - i + 1):
        for k in range(N - i - j + 1):
            if i + j + k != 0:
                dp[i][j][k] = (
                    N +
                    i * dp[i - 1][j + 1][k] +
                    j * dp[i][j - 1][k + 1] +
                    k * dp[i][j][k - 1]
                ) / (i + j + k)

print(dp[C[3]][C[2]][C[1]])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

from sys import setrecursionlimit
setrecursionlimit(300 ** 3 + 10)


N, *A = map(int, open(0).read().split())

memo = {(0, 0, 0): 0.0}
def dp(i, j, k):
    if (i, j, k) in memo:
        return memo[(i, j, k)]

    res = N
    if i > 0:
        res += i * dp(i - 1, j, k)
    if j > 0:
        res += j * dp(i + 1, j - 1, k)
    if k > 0:
        res += k * dp(i, j + 1, k - 1)

    res /= (i + j + k)

    memo[(i, j, k)] = res

    return res

C = Counter(A)
print(dp(C[1], C[2], C[3]))

Fixed submission:
from collections import Counter

N, *A = map(int, open(0).read().split())

C = Counter(A)
dp = [[[.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
for i in range(C[3] + 1):
    for j in range(N - C[1] - i + 1):
        for k in range(N - i - j + 1):
            if i + j + k != 0:
                dp[i][j][k] = (
                    N +
                    i * dp[i - 1][j + 1][k] +
                    j * dp[i][j - 1][k + 1] +
                    k * dp[i][j][k - 1]
                ) / (i + j + k)

print(dp[C[3]][C[2]][C[1]])
Buggy python submission (verdict: Time Limit Exceeded):
N, K, *A = map(int, open(0).read().split())

dp = [False] * (K + 1)
for i in range(1, K + 1):
    if dp[i]:
        continue

    for a in A:
        if i - a >= 0:
            dp[i] |= not dp[i - a]

if dp[K]:
    print("First")
else:
    print("Second")

Fixed submission:
N, K, *A = map(int, open(0).read().split())

dp = [False] * (K + 1)
for i in range(1, K + 1):
    for a in A:
        if i - a >= 0:
            dp[i] |= not dp[i - a]

if dp[K]:
    print("First")
else:
    print("Second")

Buggy python submission (verdict: Time Limit Exceeded):
N, K, *A = map(int, open(0).read().split())

dp = [False] * (K + 1)
for i in range(1, K + 1):
    for a in A:
        if i - a >= 0:
            dp[i] |= not dp[i - a]

if dp[K]:
    print("First")
else:
    print("Second")

Fixed submission:
N, K, *A = map(int, open(0).read().split())

dp = [False] * (K + 1)
for i in range(1, K + 1):
    for a in A:
        if i - a >= 0:
            dp[i] |= not dp[i - a]

if dp[K]:
    print("First")
else:
    print("Second")
Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())

dp = [[0] * (N + 1) for _ in range(N + 1)]
for d in range(1, N + 1):
    for l in range(N - d + 1):
        r = l + d
        if (N - d) % 2 == 0:
            dp[l][r] = max(
                A[l] + dp[l + 1][r],
                A[r - 1] + dp[l][r - 1]
            )
        else:
            dp[l][r] = min(
                - A[l] + dp[l + 1][r],
                - A[r - 1] + dp[l][r - 1]
            )

print(dp[0][N])

Fixed submission:
N, *A = map(int, open(0).read().split())

dp = [[0] * (N + 1) for _ in range(N + 1)]
for d in range(1, N + 1):
    for l in range(N - d + 1):
        r = l + d
        if (N - d) % 2 == 0:
            dp[l][r] = max(
                A[l] + dp[l + 1][r],
                A[r - 1] + dp[l][r - 1]
            )
        else:
            dp[l][r] = min(
                - A[l] + dp[l + 1][r],
                - A[r - 1] + dp[l][r - 1]
            )

print(dp[0][N])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * K
for a in A:
    S = [0] + list(accumulate(dp))
    for i in range(K + 1):
        dp[i] = (S[i + 1] - S[max(0, i - a)]) % mod

print(dp[K])

Fixed submission:
mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * (K + 1)
for a in A:
    for i in range(1, K + 1):
        dp[i] += dp[i - 1]
    for i in reversed(range(1, K + 1)):
        dp[i] -= dp[max(0, i - a) - 1]
        dp[i] %= mod

print(dp[K])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = [[-1] * N for _ in range(N)]
def dp(L, R):
    if L == R:
        return 0
    if memo[L][R] >= 0:
        return memo[L][R]

    memo[L][R] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[L][R]

print(dp(0, N - 1))

Fixed submission:
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = [[-1] * N for _ in range(N)]
def dp(L, R):
    if L == R:
        return 0
    if memo[L][R] >= 0:
        return memo[L][R]

    memo[L][R] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[L][R]

print(dp(0, N - 1))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = {}
def dp(L, R):
    if L == R:
        return 0
    if (L, R) in memo:
        return memo[(L, R)]

    memo[(L, R)] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[(L, R)]

print(dp(0, N - 1))

Fixed submission:
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = [[-1] * N for _ in range(N)]
def dp(L, R):
    if L == R:
        return 0
    if memo[L][R] >= 0:
        return memo[L][R]

    memo[L][R] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[L][R]

print(dp(0, N - 1))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = {}
def dp(L, R):
    if L == R:
        return 0
    if (L, R) in memo:
        return memo[(L, R)]

    memo[(L, R)] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[(L, R)]

print(dp(0, N - 1))

Fixed submission:
from itertools import accumulate

N, *A = map(int, open(0).read().split())

S = [0] + list(accumulate(A))

memo = [[-1] * N for _ in range(N)]
def dp(L, R):
    if L == R:
        return 0
    if memo[L][R] >= 0:
        return memo[L][R]

    memo[L][R] = min(dp(L, c) + dp(c + 1, R) + S[R + 1] - S[L] for c in range(L, R))
    return memo[L][R]

print(dp(0, N - 1))
Buggy python submission (verdict: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

uint32_t ceil2(uint32_t a)
{
    uint32_t b = 1;
    while (a > b) {
        b <<= 1;
    }
    return b;
}

int main()
{
    int N;
    cin >> N;

    multiset<int> S;
    vector<int> A(N);
    for (auto &&a : A) {
        cin >> a;
        S.insert(a);
    }
    sort(rbegin(A), rend(A));

    int ans = 0;
    for (auto a : A) {
        if (S.find(a) != S.end()) {
            S.erase(a);
            int p = ceil2(a) - a;
            if (S.find(p) != S.end()) {
                S.erase(p);
                ans += 1;
            }
        }
    }

    cout << ans << '\n';
}

Fixed submission:
from collections import Counter

N, *A = map(int, open(0).read().split())

C = Counter(A)
A.sort(reverse=True)

ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1

    b = 2 ** a.bit_length() - a
    if C[b] > 0:
        C[b] -= 1
        ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open(0).read().split())

S = set(A)

A.sort(reverse=True)

ans = 0
for a in A:
    b = 2 ** a.bit_length() - a
    if a != b and b in S:
        S.remove(a)
        S.remove(b)
        ans += 1

print(ans)


Fixed submission:
from collections import Counter

N, *A = map(int, open(0).read().split())

C = Counter(A)
A.sort(reverse=True)

ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1

    b = 2 ** a.bit_length() - a
    if C[b] > 0:
        C[b] -= 1
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
Q = int(input())
K = [int(i) for i in input().split()]

for k in K:
    ans = 0

    d = m = dm = 0
    for i, si in enumerate(S):
        if 0 <= i - K:
            if S[i - K] == "D":
                d -= 1
                dm -= m
            elif S[i - K] == "M":
                m -= 1

        if si == "D":
            d += 1
        elif si == "M":
            m += 1
            dm += d
        elif si == "C":
            ans += dm

    print(ans)

Fixed submission:
N = int(input())
S = input()
Q = int(input())
K = [int(i) for i in input().split()]

for k in K:
    ans = 0

    d = m = dm = 0
    for i, si in enumerate(S):
        if 0 <= i - k:
            if S[i - k] == "D":
                d -= 1
                dm -= m
            elif S[i - k] == "M":
                m -= 1

        if si == "D":
            d += 1
        elif si == "M":
            m += 1
            dm += d
        elif si == "C":
            ans += dm

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def lcm(a, b):
    return a * b // gcd(a, b)


N, M = [int(_) for _ in input().split()]
S = input()
T = input()

L = lcm(N, M)


X = ['_' for i in range(L)]

j = 0
for i in range(0, L, L // N):
    X[i] = S[j]
    j += 1

j = 0
for i in range(0, L, L // M):
    if X[i] != '_' and X[i] != T[j]:
        print("-1")
        exit()
    X[i] = T[j]
    j += 1

print(L)


Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def lcm(a, b):
    return a * b // gcd(a, b)


N, M = [int(_) for _ in input().split()]
S = input()
T = input()

L = lcm(N, M)
D = lcm(L // M, L // N)

for i in range(0, L, D):
    if S[i // (L // N)] != T[i // (L // M)]:
        print("-1")
        exit()
else:
    print(L)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def lcm(a, b):
    return a * b // gcd(a, b)


N, M = [int(_) for _ in input().split()]
S = input()
T = input()

L = lcm(N, M)


X = ['_' for i in range(L)]

j = 0
for i in range(L):
    if i % (L // N) == 0:
        X[i] = S[j]
        j += 1

j = 0
for i in range(L):
    if i % (L // M) == 0:
        if X[i] != '_' and X[i] != T[j]:
            print("-1")
            exit()
        X[i] = T[j]
        j += 1

print(L)


Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def lcm(a, b):
    return a * b // gcd(a, b)


N, M = [int(_) for _ in input().split()]
S = input()
T = input()

L = lcm(N, M)
D = lcm(L // M, L // N)

for i in range(0, L, D):
    if S[i // (L // N)] != T[i // (L // M)]:
        print("-1")
        exit()
else:
    print(L)
Buggy python submission (verdict: Runtime Error):
def divisors(N):
    U = int(N ** 0.5)
    res = [i for i in range(1, U) if N % i == 0]
    if N % U == 0:
        res.append(U)
    res += [N // r for r in reversed(res)]
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Fixed submission:
N = int(input())
R = [_ for _ in range(N)]
for i in range(N):
    x, y, h = [int(_) for _ in input().split()]
    R[i] = (h, x, y)

R.sort(reverse=True)

def solve():
    for cx in range(101):
        for cy in range(101):
            h, x, y = R[0]
            H = h + abs(x - cx) + abs(y - cy)
            for i in range(1, N):
                h, x, y = R[i]
                if h == 0 and H < abs(x - cx) + abs(y - cy):
                    continue

                tempH = h + abs(x - cx) + abs(y - cy)
                if tempH != H:
                    break
            else:
                print(cx, cy, H)
                return

solve()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
print(max(d for d in range(1, M // N + 1) if M % d == 0))


Fixed submission:
N, M = map(int, input().split())
print(next(d for d in reversed(range(M // N + 1)) if M % d == 0))
Buggy python submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

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

print(len(ans))
for a in ans:
    print(*a)

Fixed submission:
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

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

print(len(ans))
for a in ans:
    print(*a)

Buggy python submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

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

print(len(ans))
for a in ans:
    print(*a)

Fixed submission:
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

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

print(len(ans))
for a in ans:
    print(*a)

Buggy python submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]
A.append([0] * W)

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

if A[H][W - 1] % 2 == 1:
    ans.pop()

print(len(ans))
for h, w, nh, nw in ans:
    print(h + 1, w + 1, nh + 1, nw + 1)


Fixed submission:
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

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

print(len(ans))
for a in ans:
    print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

acc = [0] + list(itertools.accumulate(A))

count = 0
for l in range(N + 1):
    for r in range(l + 1, N + 1):
        if (acc[r] - acc[l]) % M == 0:
            count += 1
print(count)

Fixed submission:
import itertools

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

acc = [0] + list(itertools.accumulate(A))

B = [ai % M for ai in acc]
B.sort()
B.append(-1)

result = 0
count = 1

for i in range(N + 1):
    if B[i + 1] == B[i]:
        count += 1
    else:
        result += count * (count - 1) // 2
        count = 1
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
for i in range(T):
    A, B, C, D = [int(i) for i in input().split()]

    memo = set()
    while True:
        if A in memo:
            print("Yes")
            break

        if A - B < 0:
            print("No")
            break

        if D - B == 0:
            if C - A + B < 0:
                print("No")
                break
            else:
                print("Yes")
                break

        if D - B < 0:
            print("No")
            break

        n = 1 + (C - A + B) // (D - B)
        r = (A - B) + n * (D - B)
        if r < B:
            print("No")
            break
        else:
            memo.add(A)
            A = B + r % B

    else:
        print("Yes")

    # print(A, B, C, D)


Fixed submission:
from fractions import gcd

def solve(a, b, c, d):
    if a < b or d < b:
        return False

    if c >= b - 1:
        return True

    g = gcd(b, d)
    return (b + a % g - g) <= c

T, *L = map(int, open(0).read().split())

for t in zip(*[iter(L)] * 4):
    if solve(*t):
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()

left, right = S[:N], S[N:][::-1]
a, b = Counter(), Counter()

for i in range(2 ** N):
    t = u = v = w = ""
    for j in range(N):
        if (i >> j) & 1:
            t += left[j]
            u += right[j]
        else:
            v += left[j]
            w += right[j]
    a[t, v] += 1
    b[u, w] += 1

print(sum(a[t] * b[t] for t in a.keys()))

Fixed submission:
from collections import Counter

N = int(input())
S = input()

left, right = S[:N], S[N:][::-1]
a, b = Counter(), Counter()

for i in range(2 ** N):
    t = "".join(left[j] if (i >> j) & 1 else "" for j in range(N))
    u = "".join(right[j] if (i >> j) & 1 else "" for j in range(N))
    v = "".join("" if (i >> j) & 1 else left[j] for j in range(N))
    w = "".join("" if (i >> j) & 1 else right[j] for j in range(N))
    a[t, v] += 1
    b[u, w] += 1

print((sum(a[t] * b[t] for t in a.keys())))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()

left, right = S[:N], S[N:][::-1]
a, b = Counter(), Counter()

for i in range(2 ** N):
    t = "".join(left[j] if (i >> j) & 1 else "" for j in range(N))
    u = "".join(right[j] if (i >> j) & 1 else "" for j in range(N))
    v = "".join("" if (i >> j) & 1 else left[j] for j in range(N))
    w = "".join("" if (i >> j) & 1 else right[j] for j in range(N))
    a[t, v] += 1
    b[u, w] += 1

print((sum(a[t] * b[t] for t in a.keys())))

Fixed submission:
from collections import Counter

N = int(input())
S = input()

left, right = S[:N], S[N:][::-1]
a, b = Counter(), Counter()

for i in range(2 ** N):
    t = "".join(left[j] if (i >> j) & 1 else "" for j in range(N))
    u = "".join(right[j] if (i >> j) & 1 else "" for j in range(N))
    v = "".join("" if (i >> j) & 1 else left[j] for j in range(N))
    w = "".join("" if (i >> j) & 1 else right[j] for j in range(N))
    a[t, v] += 1
    b[u, w] += 1

print((sum(a[t] * b[t] for t in a.keys())))
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

print(2 * N // math.gcd(N, 2))



Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
N = int(input())

print(2 * N // gcd(N, 2))
Buggy python submission (verdict: Runtime Error):
11 4

Fixed submission:
A, B = [int(i) for i in input().split()]

if A > 8 or B > 8:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
N, M, *XYZ = map(int, open(0).read().split())

P = tuple(product((1, -1), repeat=3))

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    A[0].append(sum((x, y, z)))
    A[1].append(sum((x, y, -z)))
    A[2].append(sum((x, -y, z)))
    A[3].append(sum((x, -y, -z)))
    A[4].append(sum((-x, y, z)))
    A[5].append(sum((-x, y, -z)))
    A[6].append(sum((-x, -y, z)))
    A[7].append(sum((-x, -y, -z)))

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))


Fixed submission:
# https://atcoder.jp/contests/abc100/tasks/abc100_d

from itertools import product

N, M, *XYZ = map(int, open(0).read().split())

P = tuple(product((1, -1), repeat=3))

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    for i, (a, b, c) in enumerate(P):
        A[i].append(a * x + b * y + c * z)

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))