Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = [0] * (N + 1)
for x in range(1, N + 1):
    for y in range(1, N + 1):
        for z in range(1, N + 1):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            if v <= N:
                ans[v] += 1

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

Fixed submission:
N = int(input())

ans = [0] * (N + 1)
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            if v <= N:
                ans[v] += 1

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

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = [0] * (N + 1)
for x in range(1, N + 1):
    for y in range(1, N + 1):
        for z in range(1, N + 1):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            if v <= N:
                ans[v] += 1

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

Fixed submission:
N = int(input())

ans = [0] * (N + 1)
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            if v <= N:
                ans[v] += 1

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

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

N = int(input())

def solve():
    memo = Counter()
    for x in range(1, N):
        for y in range(x, N):
            res = x * x + y * y + x * y
            if res >= N:
                return
            for z in range(y, N):
                if x == y == z:
                    cnt = 1
                elif x < y < z:
                    cnt = 6
                else:
                    cnt = 3
                memo[res + z * z + y * z + x * z] += cnt

C = solve()
for i in range(1, N + 1):
    print(C[i])

Fixed submission:
N = int(input())

ans = [0] * (N + 1)
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x * x + y * y + z * z + x * y + y * z + z * x
            if v <= N:
                ans[v] += 1

for i in range(1, N + 1):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
from functools import reduce

INF = float("inf")

N, a, b, *A = map(int, open(0).read().split())
c = reduce(lambda a, b: a ^ b, A, 0)

def solve(a, b, c):
    if (a % 2) ^ (b % 2) != (c % 2):
        return INF
    if c == 0:
        return INF if a < b else (a - b) // 2

    return min(
        2 * solve(a // 2, b // 2, c // 2),
        1 + 2 * solve((a - 1) // 2, (b + 1) // 2, c // 2)
    )

print(-1 if (res := solve(a, b, c)) >= a else res)

Fixed submission:
from functools import reduce, lru_cache

INF = float("inf")

N, a, b, *A = map(int, open(0).read().split())
c = reduce(lambda a, b: a ^ b, A, 0)

@lru_cache(None)
def solve(a, b, c):
    if (a % 2) ^ (b % 2) != (c % 2):
        return INF
    if c == 0:
        return INF if a < b else (a - b) // 2

    return min(
        2 * solve(a // 2, b // 2, c // 2),
        1 + 2 * solve((a - 1) // 2, (b + 1) // 2, c // 2)
    )

print(-1 if (res := solve(a, b, c)) >= a else res)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

INF = float("inf")

N, a, b, *A = map(int, open(0).read().split())
c = reduce(lambda a, b: a ^ b, A, 0)

def solve(a, b, c):
    if (a % 2) ^ (b % 2) != (c % 2):
        return INF
    if c == 0:
        return INF if a < b else (a - b) // 2

    return min(
        2 * solve(a // 2, b // 2, c // 2),
        1 + 2 * solve((a - 1) // 2, (b + 1) // 2, c // 2)
    )

print(-1 if (res := solve(a, b, c)) >= a else res)

Fixed submission:
from functools import reduce, lru_cache

INF = float("inf")

N, a, b, *A = map(int, open(0).read().split())
c = reduce(lambda a, b: a ^ b, A, 0)

@lru_cache(None)
def solve(a, b, c):
    if (a % 2) ^ (b % 2) != (c % 2):
        return INF
    if c == 0:
        return INF if a < b else (a - b) // 2

    return min(
        2 * solve(a // 2, b // 2, c // 2),
        1 + 2 * solve((a - 1) // 2, (b + 1) // 2, c // 2)
    )

print(-1 if (res := solve(a, b, c)) >= a else res)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    mod = 998244353

    A, B, C, D = map(int, input().split())

    dp = [0] * B + [pow(A, i, mod) for i in range(D + 1 - B)]
    for a in range(A + 1, C + 1):
        T = [0] * (D + 1)
        for b in range(B, D + 1):
            T[b] = (a * T[b - 1] + b * dp[b] - (a - 1) * (b - 1) * dp[b - 1]) % mod
        dp = T

    print(dp[D])

main()

Fixed submission:
mod = 998244353

A, B, C, D = map(int, input().split())

dp = [0] * (D + 1)
dp[B:D + 1] = [pow(A, i, mod) for i in range(D + 1 - B)]

for a in range(A + 1, C + 1):
    T = [0] * (D + 1)
    for b in range(B, D + 1):
        T[b] = (a * T[b - 1] + b * dp[b] - (a - 1) * (b - 1) * dp[b - 1]) % mod
    dp = T

print(dp[D])

Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353

A, B, C, D = map(int, input().split())

dp = [0] * B + [pow(A, i, mod) for i in range(D + 1 - B)]
for a in range(A + 1, C + 1):
    T = [0] * (D + 1)
    for b in range(B, D + 1):
        T[b] = (a * T[b - 1] + b * dp[b] - (a - 1) * (b - 1) * dp[b - 1]) % mod
    dp = T

print(dp[D])

Fixed submission:
mod = 998244353

A, B, C, D = map(int, input().split())

dp = [0] * (D + 1)
dp[B:D + 1] = [pow(A, i, mod) for i in range(D + 1 - B)]

for a in range(A + 1, C + 1):
    T = [0] * (D + 1)
    for b in range(B, D + 1):
        T[b] = (a * T[b - 1] + b * dp[b] - (a - 1) * (b - 1) * dp[b - 1]) % mod
    dp = T

print(dp[D])
Buggy python submission (verdict: Time Limit Exceeded):
from numba import njit

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

@njit(cache=True)
def solve(A):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    for i in range(N):
        B[i + 1] += B[i]
    return B

for _ in range(min(K, 41)):
    A = solve(A)

print(*A[:-1])

Fixed submission:
from itertools import accumulate

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

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = list(accumulate(B))

print(*A[:-1])

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import zeros

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

for _ in range(min(K, 41)):
    B = zeros(N, dtype=int)
    for x, d in enumerate(A):
        B[x - d if x > d else 0] += 1
        if (x := x + d + 1) < N:
            B[x] -= 1
    A = B.cumsum()

print(*A)

Fixed submission:
from itertools import accumulate

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

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = list(accumulate(B))

print(*A[:-1])

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

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

for _ in range(min(K, 41)):
    B = [0] * N
    for x, d in enumerate(A):
        B[x - d if x > d else 0] += 1
        if (x := x + d + 1) < N:
            B[x] -= 1
    A = list(accumulate(B))

print(*A)

Fixed submission:
from itertools import accumulate

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

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = list(accumulate(B))

print(*A[:-1])

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

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

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = list(accumulate(B))

print(*A[:-1])

Fixed submission:
from itertools import accumulate

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

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = list(accumulate(B))

print(*A[:-1])
Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353

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

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

for i, a in enumerate(A):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod

        if j + a <= S:
            dp[i + 1][j + a] += dp[i][j]
            dp[i + 1][j + a] %= mod

print(dp[N][S])

Fixed submission:
mod = 998244353

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

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

for i, a in enumerate(A):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod

        if j + a <= S:
            dp[i + 1][j + a] += dp[i][j]
            dp[i + 1][j + a] %= mod

print(dp[N][S])

Buggy python submission (verdict: Runtime Error):
mod = 998244353

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

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

for i, a in enumerate(A, 1):
    for j in range(S + 1):
        dp[i][j] = 2 * dp[i - 1][j] + dp[i - 1][j - a] * (j >= a)

print(dp[N][S])

Fixed submission:
mod = 998244353

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

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

for i, a in enumerate(A):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod

        if j + a <= S:
            dp[i + 1][j + a] += dp[i][j]
            dp[i + 1][j + a] %= mod

print(dp[N][S])

Buggy python submission (verdict: Runtime Error):
mod = 998244353

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

dp = [1] + [0] * S
for i, a in enumerate(A):
    for j in reversed(range(S + 1)):
        dp[j] = (2 * dp[j] + dp[j - a] * (j >= a)) % mod

print(dp[S])

Fixed submission:
mod = 998244353

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

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

for i, a in enumerate(A):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod

        if j + a <= S:
            dp[i + 1][j + a] += dp[i][j]
            dp[i + 1][j + a] %= mod

print(dp[N][S])

Buggy python submission (verdict: Runtime Error):
mod = 998244353

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

dp = [1] + [0] * S
for i, a in enumerate(A):
    for j in reversed(range(S + 1)):
        dp[j] = 2 * dp[j] + dp[j - a] * (j >= a)

print(dp[S])

Fixed submission:
mod = 998244353

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

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

for i, a in enumerate(A):
    for j in range(S + 1):
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod

        if j + a <= S:
            dp[i + 1][j + a] += dp[i][j]
            dp[i + 1][j + a] %= mod

print(dp[N][S])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, *P = map(int, open(0).read().split())

    dp = [0] + [min(i, j, N - 1 - i, N - 1 - j) for i in range(N) for j in range(N)]
    memo = [1] * (N * N + 1)

    def move(fr, to):
        if dp[to] > dp[fr] + memo[fr]:
            dp[to] = dp[fr] + memo[fr]
            S.append(to)

    ans = 0
    for p in P:
        ans += dp[p]
        memo[p] = 0

        S = [p]
        while S:
            v = S.pop()

            q, r = divmod(v - 1, N)
            if r != 0:
                move(v, v - 1)
            if r != N - 1:
                move(v, v + 1)
            if q < N - 1:
                move(v, v + N)
            if q >= 1:
                move(v, v - N)

    print(ans)

main()

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

dp = [0] + [min(i, j, N - 1 - i, N - 1 - j) for i in range(N) for j in range(N)]
memo = [1] * (N * N + 1)

def move(fr, to):
    if dp[to] > dp[fr] + memo[fr]:
        dp[to] = dp[fr] + memo[fr]
        S.append(to)

ans = 0
for p in P:
    ans += dp[p]
    memo[p] = 0

    S = [p]
    while S:
        v = S.pop()

        q, r = divmod(v - 1, N)
        if r != 0:
            move(v, v - 1)
        if r != N - 1:
            move(v, v + 1)
        if q < N - 1:
            move(v, v + N)
        if q >= 1:
            move(v, v - N)

print(ans)

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

dp = [0] + [min(i, j, N - 1 - i, N - 1 - j) for i in range(N) for j in range(N)]
memo = [1] * (N * N + 1)

def move(fr, to):
    if dp[to] > dp[fr] + memo[fr]:
        dp[to] = dp[fr] + memo[fr]
        S.append(to)

ans = 0
for p in P:
    ans += dp[p]
    memo[p] = 0

    S = [p]
    while S:
        v = S.pop()

        q, r = divmod(v - 1, N)
        if r != 0:
            move(v, v - 1)
        if r != N - 1:
            move(v, v + 1)
        if q < N - 1:
            move(v, v + N)
        if q >= 1:
            move(v, v - N)

print(ans)

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

dp = [0] + [min(i, j, N - 1 - i, N - 1 - j) for i in range(N) for j in range(N)]
memo = [1] * (N * N + 1)

def move(fr, to):
    if dp[to] > dp[fr] + memo[fr]:
        dp[to] = dp[fr] + memo[fr]
        S.append(to)

ans = 0
for p in P:
    ans += dp[p]
    memo[p] = 0

    S = [p]
    while S:
        v = S.pop()

        q, r = divmod(v - 1, N)
        if r != 0:
            move(v, v - 1)
        if r != N - 1:
            move(v, v + 1)
        if q < N - 1:
            move(v, v + N)
        if q >= 1:
            move(v, v - N)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

INF = float("inf")

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

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

dist = [INF] * (N + 1)
ans = [-1] * (N + 1)

Q = deque([1])
dist[1] = 0
while Q:
    v = Q.popleft()
    d = dist[v] + 1
    for u in E[v]:
        if dist[u] > d:
            dist[u] = d
            ans[u] = v
            Q.appendleft(u)

print("Yes")
for a in ans[2:]:
    print(a)

Fixed submission:
from collections import deque

INF = float("inf")

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

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

dist = [INF] * (N + 1)
ans = [-1] * (N + 1)

Q = deque([1])
dist[1] = 0
while Q:
    v = Q.popleft()
    d = dist[v] + 1
    for u in E[v]:
        if dist[u] > d:
            dist[u] = d
            ans[u] = v
            Q.append(u)

print("Yes")
for a in ans[2:]:
    print(a)
Buggy python submission (verdict: Runtime Error):
stdin = open(0)

N, A, B, C = map(int, stdin.readline().split())
S = stdin.read().split()

ans = [""] * N
def dfs(i, a, b, c):
    if a < 0 or b < 0 or c < 0:
        return

    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    if S[i] == "AB":
        ans[i] = "A"
        dfs(i + 1, a + 1, b - 1, c)

        ans[i] = "B"
        dfs(i + 1, a - 1, b + 1, c)

    elif S[i] == "BC":
        ans[i] = "B"
        dfs(i + 1, a, b + 1, c - 1)

        ans[i] = "C"
        dfs(i + 1, a, b - 1, c + 1)
    else:
        ans[i] = "A"
        dfs(i + 1, a + 1, b, c - 1)

        ans[i] = "C"
        dfs(i + 1, a - 1, b, c + 1)

dfs(0, A, B, C)
print("No")

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

stdin = open(0)

N, A, B, C = map(int, stdin.readline().split())
S = stdin.read().split()

ans = [""] * N
def dfs(i, a, b, c):
    if a < 0 or b < 0 or c < 0:
        return

    if i == N:
        print("Yes")
        print("\n".join(ans))
        quit()

    if S[i] == "AB":
        ans[i] = "A"
        dfs(i + 1, a + 1, b - 1, c)

        ans[i] = "B"
        dfs(i + 1, a - 1, b + 1, c)

    elif S[i] == "BC":
        ans[i] = "B"
        dfs(i + 1, a, b + 1, c - 1)

        ans[i] = "C"
        dfs(i + 1, a, b - 1, c + 1)
    else:
        ans[i] = "A"
        dfs(i + 1, a + 1, b, c - 1)

        ans[i] = "C"
        dfs(i + 1, a - 1, b, c + 1)

dfs(0, A, B, C)
print("No")
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

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

L = list(zip(*[iter(ABCD)] * 4))

def solve(A):
    if len(A) == M:
        return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)

    return max((solve(A + [i]) for i in range(A[-1], M + 1)), default=0)

print(solve([1]))

Fixed submission:
from itertools import combinations_with_replacement

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

L = list(zip(*[iter(ABCD)] * 4))

print(max(sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c) for A in combinations_with_replacement(range(1, M + 1), N)))

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

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

L = list(zip(*[iter(ABCD)] * 4))

def solve(A):
    if len(A) == M:
        return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)

    return max((solve(A + [i]) for i in range(A[-1], M + 1)))

print(solve([1]))

Fixed submission:
from itertools import combinations_with_replacement

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

L = list(zip(*[iter(ABCD)] * 4))

print(max(sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c) for A in combinations_with_replacement(range(1, M + 1), N)))

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

L = list(zip(*[iter(ABCD)] * 4))

def solve(A):
    if len(A) == M:
        return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)

    return max((solve(A + [i]) for i in range(A[-1], M + 1)), default=0)

print(solve([1]))

Fixed submission:
from itertools import combinations_with_replacement

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

L = list(zip(*[iter(ABCD)] * 4))

print(max(sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c) for A in combinations_with_replacement(range(1, M + 1), N)))

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

L = list(zip(*[iter(ABCD)] * 4))

def solve(A):
    if len(A) == M:
        return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)

    return max(solve(A + [i]) for i in range(A[-1], M + 1))

print(solve([1]))

Fixed submission:
from itertools import combinations_with_replacement

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

L = list(zip(*[iter(ABCD)] * 4))

print(max(sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c) for A in combinations_with_replacement(range(1, M + 1), N)))
Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())

A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

dp = [[0] * (N + 1) for _ in range(N + 1)]
for i, (p, a) in enumerate(A):
    for j in range(i + 1):
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a * (p - j))
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * (N - (i - j) - 1 - p))

print(max(dp[N]))

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

A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

dp = [[0] * (N + 1) for _ in range(N + 1)]
for i, (p, a) in enumerate(A):
    for j in range(i + 1):
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a * (p - j))
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * (N - (i - j) - 1 - p))

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

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

R = [0] + list(accumulate(int(s == "R") for s in S))
G = [0] + list(accumulate(int(s == "G") for s in S))
B = [0] + list(accumulate(int(s == "B") for s in S))

memo = {"R": R, "G": G, "B": B}

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == S[j]:
            continue

        color = "RGB".replace(S[i], "").replace(S[j], "")
        C = memo[color]

        d = j - i
        x = N - j
        if d < x and S[j + d] == color:
            ans += C[N] - C[j] - 1
        else:
            ans += C[N] - C[j]

print(ans)

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

cand = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
    for d in range(1, (N - i + 1) // 2):
        if S[i:i + 2 * d + 1:d] in cand:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

cand = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
    for d in range(1, N):
        if S[i:i + 2 * d + 1:d] in cand:
            ans -= 1

print(ans)

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

cand = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]

ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
    for d in range(1, (N - i + 1) // 2):
        if S[i:i + 2 * d + 1:d] in cand:
            ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque, Counter

INF = float("inf")

N, X, Y = map(int, input().split())

E = [[] for _ in range(N + 1)]
for i in range(1, N):
    E[i].append(i + 1)
    E[i + 1].append(i)
E[X].append(Y)
E[Y].append(X)

C = Counter()
for s in range(1, N + 1):
    dist = [INF] * (N + 1)
    dist[s] = 0
    Q = deque([s])
    while Q:
        p = Q.popleft()
        for c in E[p]:
            if dist[c] > dist[p] + 1:
                dist[c] = dist[p] + 1
                Q.append(c)
    C.update(dist)

for k in range(1, N):
    print(C[k] // 2)

Fixed submission:
from collections import deque, Counter

INF = float("inf")

N, X, Y = map(int, input().split())

E = [[] for _ in range(N + 1)]
for i in range(1, N):
    E[i].append(i + 1)
    E[i + 1].append(i)
E[X].append(Y)
E[Y].append(X)

C = Counter()
for s in range(1, N + 1):
    dist = [INF] * (N + 1)
    dist[s] = 0
    Q = deque([s])
    while Q:
        p = Q.popleft()
        for c in E[p]:
            if dist[c] > dist[p] + 1:
                dist[c] = dist[p] + 1
                Q.append(c)
    C.update(dist)

for k in range(1, N):
    print(C[k] // 2)
Buggy python submission (verdict: Runtime Error):
Point = complex


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

P = [Point(x, y) for x, y in zip(*[iter(XY)] * 2)]

def max_distance(center):
    return max(abs(center - p) for p in P)

def ternary_search(f, left, right, MAX_ITER=100):
    for _ in range(MAX_ITER):
        m1 = (left * 2 + right) / 3
        m2 = (left + right * 2) / 3
        if f(m1) < f(m2):
            right = m2
        else:
            left = m1
    return f(left)

def g(x):
    return ternary_search(lambda y: max_distance(Point(x, y)), -1000, 1000)

print(ternary_search(g, -1000, 1000))

Fixed submission:
mod = 10 ** 9 + 7

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod


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

mc = ModComb(2 * N)

ans = mc.nCk(2 * N - 1, N - 1)
if K + 1 < N:
    ans += sum((mod - mc.nCk(N, i)) * mc.nCk(N - 1, i) % mod for i in range(K + 1, N)) % mod

print(ans % mod)