Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
anstable = [0] * (10 ** 6 + 1)
d = defaultdict(int)
for i in a:
    d[i] += 1

u = []
for i, v in d.items():
    if v == 1:
        u.append(i)

for i in a:
    for j in range(i * 2, 10 ** 6 + 1, i):
        anstable[j] += 1

cnt = 0
for i in u:
    if anstable[i] == 0:
        cnt += 1

print(cnt)

Fixed submission:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
anstable = [0] * (10 ** 6 + 1)
d = defaultdict(int)
for i in a:
    d[i] += 1

u = []
for i, v in d.items():
    if v == 1:
        u.append(i)
a = set(a)
for i in a:
    for j in range(i * 2, 10 ** 6 + 1, i):
        anstable[j] += 1

cnt = 0
for i in u:
    if anstable[i] == 0:
        cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
anstable = [0] * (10 ** 6 + 1)

for i in range(N):
    for j in range(1, 10 ** 6 + 1):
        index = a[i] * j
        if index <= 10 ** 6:
            anstable[index] += 1

cnt = 0
for i in a:
    if anstable[i] == 1:
        cnt += 1

print(cnt)

Fixed submission:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
anstable = [0] * (10 ** 6 + 1)
d = defaultdict(int)
for i in a:
    d[i] += 1

u = []
for i, v in d.items():
    if v == 1:
        u.append(i)
a = set(a)
for i in a:
    for j in range(i * 2, 10 ** 6 + 1, i):
        anstable[j] += 1

cnt = 0
for i in u:
    if anstable[i] == 0:
        cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())
total = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += math.gcd(k, math.gcd(i, j))

print(total)

Fixed submission:
import math

K = int(input())
total = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += math.gcd(k, math.gcd(i, j))

print(total)
Buggy python submission (verdict: Runtime Error):

from decimal import Decimal
a, b, c = map(int, input().split())
if Decimal(a).sqrt() + Decimal(b).sqrt(b) < Decimal(c).sqrt():
    print('Yes')
else:
    print('No')

Fixed submission:

from decimal import Decimal
a, b, c = map(int, input().split())
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from decimal import *
import numpy as np
getcontext().prec = 50
a, b, c = map(int, input().split())
tmp1 = Decimal(np.sqrt(a)) + Decimal(np.sqrt(b))
tmp2 = Decimal(np.sqrt(c))

if tmp1 < tmp2:
    print('Yes')
else:
    print('No')

Fixed submission:
import string
def dfs(w, d):
    if len(w) == N:
        print(w)
        return
    for i in range(d + 1):
        if i == d:
            dfs(w + wordlst[i], d + 1)
        else:
            dfs(w + wordlst[i], d)

N = int(input())
anslst = []
nlst = [0] * N
wordlst = string.ascii_lowercase
dfs('a', 1)
Buggy python submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = 10 ** 18 + 1
for i in range(A):
    tmp = a[i] + b[i]
    ans = min(tmp, ans)

for i in range(M):
    tmp = a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2]
    ans = min(ans, tmp)

print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)

for i in range(M):
    tmp = a[xyc[i][0] - 1] + b[xyc[i][1] - 1] - xyc[i][2]
    ans = min(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B = map(int, input().split())
tmpa = math.floor(A / 0.08)
tmpb = math.floor(B / 0.1)
alst = []
blst = []

indexa = 0
while True:
    tmp = math.floor((tmpa + indexa) * 0.08)
    if tmp == A:
        alst.append(tmpa + indexa)
        indexa += 1
    elif tmp > A:
        break
    else:
        indexa += 1

indexb = 1
while True:
    tmp = math.floor((tmpb + indexb) * 0.1)
    if tmp == B:
        blst.append(tmpb + indexb)
        indexb += 1
    elif tmp == B:
        break
    else:
        indexb += 1
ans = -1
alst.sort()
blst.sort()
for i in alst:
    if blst.count(i) >= 1:
        ans = i
        break

print(ans)

Fixed submission:
import math
A, B = map(int, input().split())
tmpa = math.floor(A / 0.08)
tmpb = math.floor(B / 0.1)
alst = []
blst = []

indexa = 0
while True:
    tmp = math.floor((tmpa + indexa) * 0.08)
    if tmp == A:
        alst.append(tmpa + indexa)
        indexa += 1
    elif tmp > A:
        break
    else:
        indexa += 1

indexb = 0
while True:
    tmp = math.floor((tmpb + indexb) * 0.1)
    if tmp == B:
        blst.append(tmpb + indexb)
        indexb += 1
    elif tmp > B:
        break
    else:
        indexb += 1
ans = -1
alst.sort()
blst.sort()
for i in alst:
    if blst.count(i) >= 1:
        ans = i
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
qlst = []
for i in range(Q):
    qlst.append(input().split())
ans = S
rtmp = 0
for i in range(Q):
    if qlst[i][0] == '1':
        rtmp += 1
    else:
        if rtmp % 2 == 0:
            if qlst[i][1] == '1':
                ans = qlst[i][2] + ans
            else:
                ans = ans + qlst[i][2]
        else:
            if qlst[i][1] == '2':
                ans = qlst[i][2] + ans
            else:
                ans = ans + qlst[i][2]

if rtmp % 2 != 0:
    print(ans[::-1])
else:
    print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
ans = deque(S)
revcnt = 0
for i in range(Q):
    data = list(input().split())
    if data[0] == '1':
        revcnt += 1
        continue

    if data[1] == '1':
        if revcnt % 2 == 0:
            ans.appendleft(data[2])
        else:
            ans.append(data[2])
    else:
        if revcnt % 2 == 0:
            ans.append(data[2])
        else:
            ans.appendleft(data[2])

if revcnt % 2 != 0:
    print(''.join(reversed(list(ans))))
else:
    print(''.join(list(ans)))
Buggy python submission (verdict: Runtime Error):
N, P = map(int, input().split())
S = input()
ans = 0
rui = [0] * (N + 1)
if 10 % P == 0:
    for i in range(len(S)):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()

t = 1
for i in reversed(range(N)):
    tmp = int(S[i]) * t % P
    rui[i] = (rui[i + 1] + tmp) % P
    t *= 10
    t %= P

cnt = [0] * (N + 1)
for i in reversed(range(N + 1)):
    ans += cnt[rui[i]]
    cnt[rui[i]] += 1
print(ans)

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
rui = [0] * (N + 1)
if 10 % P == 0:
    for i in range(len(S)):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()

t = 1
for i in reversed(range(N)):
    tmp = int(S[i]) * t % P
    rui[i] = (rui[i + 1] + tmp) % P
    t *= 10
    t %= P

cnt = [0] * P
for i in reversed(range(N + 1)):
    ans += cnt[rui[i]]
    cnt[rui[i]] += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N, P = map(int, input().split())
S = input()
ans = 0
rui = [0] * (N + 1)
if 10 % P == 0:
    for i in range(len(S)):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()

t = 1
for i in reversed(range(N)):
    tmp = int(S[i]) * t % P
    rui[i] = (rui[i + 1] + tmp) % P
    t *= 10
    t %= P

cnt = [0] * N
for i in reversed(range(N + 1)):
    ans += cnt[rui[i]]
    cnt[rui[i]] += 1
print(ans)

Fixed submission:
N, P = map(int, input().split())
S = input()
ans = 0
rui = [0] * (N + 1)
if 10 % P == 0:
    for i in range(len(S)):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()

t = 1
for i in reversed(range(N)):
    tmp = int(S[i]) * t % P
    rui[i] = (rui[i + 1] + tmp) % P
    t *= 10
    t %= P

cnt = [0] * P
for i in reversed(range(N + 1)):
    ans += cnt[rui[i]]
    cnt[rui[i]] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''

ans = -1
for i in range(1, 1000):
    cnt = 0
    for j in range(M):
        if len(str(i)) < M:
            break
        if str(i)[sc[j][0] - 1] == str(sc[j][1]):
            cnt += 1

    if cnt >= 3:
        ans = i
        break

print(ans)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''
ans = -1
sc2 = []

if M == 0:
    if N == 1:
        print(0)
        exit()
    else:
        tmp = ''
        for i in range(N):
            if i == 0:
                tmp += '1'
            else:
                tmp += '0'
        print(int(tmp))
        exit()
for i in range(M):
    if cnt[sc[i][0] - 1] == 0:
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
        sc2.append([sc[i][0], sc[i][1]])
    else:
        if chk[sc[i][0] - 1] != sc[i][1]:
            print(-1)
            exit()

for i in range(1000):
    cnt = 0
    for j in range(len(sc2)):
        if len(str(i)) < N:
            break
        if str(i)[sc2[j][0] - 1] == str(sc2[j][1]):
            cnt += 1

    if cnt >= len(sc2):
        ans = i
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''

ans = -1
for i in range(1, 1000):
    cnt = 0
    for j in range(M):
        if len(str(i)) < M:
            break
        if str(i)[sc[j][0] - 1] == str(sc[j][1]):
            cnt += 1

    if cnt == M:
        ans = i
        break

print(ans)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
chk = [0, 0, 0]
cnt = [0, 0, 0]
ans = ''
ans = -1
sc2 = []

if M == 0:
    if N == 1:
        print(0)
        exit()
    else:
        tmp = ''
        for i in range(N):
            if i == 0:
                tmp += '1'
            else:
                tmp += '0'
        print(int(tmp))
        exit()
for i in range(M):
    if cnt[sc[i][0] - 1] == 0:
        chk[sc[i][0] - 1] = sc[i][1]
        cnt[sc[i][0] - 1] += 1
        sc2.append([sc[i][0], sc[i][1]])
    else:
        if chk[sc[i][0] - 1] != sc[i][1]:
            print(-1)
            exit()

for i in range(1000):
    cnt = 0
    for j in range(len(sc2)):
        if len(str(i)) < N:
            break
        if str(i)[sc2[j][0] - 1] == str(sc2[j][1]):
            cnt += 1

    if cnt >= len(sc2):
        ans = i
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
INF = 10 ** 9
N = N[::-1] + '0'
dp = [[INF for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0] = 0

for i in range(len(N)):
    for j in range(2):
        x = int(N[i])
        x += j
        for k in range(10):
            nexti = i + 1
            nextj = 0
            b = k - x
            if b < 0:
                nextj = 1
                b += 10
            dp[nexti][nextj] = min(dp[nexti][nextj], dp[i][j] + k + b)
print(dp[len(N)][0])

Fixed submission:
N = input()
INF = 10 ** 9
N = N[::-1] + '0'
dp = [[INF for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0] = 0

for i in range(len(N)):
    for j in range(2):
        x = int(N[i])
        x += j
        for k in range(10):
            nexti = i + 1
            nextj = 0
            b = k - x
            if b < 0:
                nextj = 1
                b += 10
            dp[nexti][nextj] = min(dp[nexti][nextj], dp[i][j] + k + b)
print(dp[len(N)][0])
Buggy python submission (verdict: Time Limit Exceeded):
import queue
import copy

def bfs(s1,s2):
    global ans
    cs = copy.deepcopy(s)
    queueX = queue.Queue()
    queueY = queue.Queue()
    queueX.put(s1)
    queueY.put(s2)
    cs[s1][s2] = 0
    while queueX.empty() == False:
        x = queueX.get()
        y = queueY.get()

        for i in range(4):
            nextX = x + moveR[i]
            nextY = y + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and cs[nextX][nextY] != '#'\
                and cs[nextX][nextY] == '.':
                cs[nextX][nextY] = cs[x][y] + 1
                ans = max(ans, cs[nextX][nextY])
                queueX.put(nextX)
                queueY.put(nextY)

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            bfs(i, j)

print(ans)

Fixed submission:
import queue
import copy

def bfs(s1,s2):
    global ans
    cs = copy.deepcopy(s)
    queueX = queue.Queue()
    queueY = queue.Queue()
    queueX.put(s1)
    queueY.put(s2)
    cs[s1][s2] = 0
    while queueX.empty() == False:
        x = queueX.get()
        y = queueY.get()

        for i in range(4):
            nextX = x + moveR[i]
            nextY = y + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and cs[nextX][nextY] != '#'\
                and cs[nextX][nextY] == '.':
                cs[nextX][nextY] = cs[x][y] + 1
                ans = max(ans, cs[nextX][nextY])
                queueX.put(nextX)
                queueY.put(nextY)

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            bfs(i, j)

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

def kaijo(n):
    return math.factorial(n)

INF = 10 ** 9 + 7
N = int(input())
x = list(map(int, input().split()))
k = kaijo(N - 1)
tmp = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        tmp += ((x[j] - x[i]) / (N - 1 - j + 1)) % INF
    tmp += ((x[-1] - x[i]) / 2) % INF
tmp += ((x[-1] - x[-2])) % INF
ans = int(tmp * k)
ans %= INF
print(ans)

Fixed submission:
import math
N = int(input())
x = list(map(int, input().split()))
kyori = [x[i + 1] - x[i] for i in range(N - 1)]
MOD = 10 ** 9 + 7
kai = [0] * (N + 1)
kai[0] = 1
for i in range(1, N + 1):
    kai[i] = (kai[i - 1] * i) % MOD
c = [0] * N
c[0] = 0
for i in range(1, N):
    c[i] = ((kai[N - 1] * pow(i, MOD - 2, MOD) % MOD) + c[i - 1]) % MOD
ans = 0
for i in range(N - 1):
    ans = (ans + kyori[i] * c[i + 1] % MOD) % MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        tmp = i >> j
        if tmp != 0:
            cnt[j] += tmp % 2
        else:
            break
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        cnt[j] += (i >> j) % 2
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        cnt[j] += (i >> j) % 2
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        cnt[j] += (i >> j) % 2
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)
Buggy python submission (verdict: Runtime Error):

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    for j in range(N):
        if i[0] == S[j]:
            for k in range(j + 1, N):
                if i[1] == S[k]:
                    for n in range(k + 1, N):
                        if i[2] == S[n]:
                            ans += 1
                            break
                    break
        if tmp != ans:
            tmp = ans
            break
print(ans)

Fixed submission:
import sys

X = int(input())
tmp1 = X // 100
tmp2 = X % 100
ans = 1

if X < 100:
    print(0)
    sys.exit()
if tmp1 == 0:
    print(ans)
    sys.exit()

for i in range(5, 0, -1):
    t1 = tmp2 // i
    t2 = tmp2 % i
    tmp2 = t2
    tmp1 -= t1
    if tmp1 < 0:
        ans = 0
        break

if t2 != 0:
    ans = 0

print(ans)
Buggy python submission (verdict: Runtime Error):

INF = 1000000007
N = int(input())
A = list(map(int, input().split()))
blst =[0, 0, 0]
blst[0] += 1
ans = 3
for i in range(1, N):
    cnt = blst.count(A[i])
    ans *= cnt
    ans %= INF
    index = blst.index(A[i])
    blst[index] += 1
    if ans == 0:
        ans = 0
        break

print(ans)

Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]

for a in A:
    ans = ans * cnt[a] % MOD

    cnt[a] -= 1
    cnt[a+1] += 1

print(ans)

Buggy python submission (verdict: Runtime Error):

INF = 1000000007
N = int(input())
A = list(map(int, input().split()))
blst =[0, 0, 0]
blst[0] += 1
ans = 3
for i in range(1, N):
    cnt = blst.count(A[i])
    ans *= cnt
    ans %= INF
    index = blst.index(A[i])
    blst[index] += 1

print(ans)

Fixed submission:
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]

for a in A:
    ans = ans * cnt[a] % MOD

    cnt[a] -= 1
    cnt[a+1] += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import math
N = int(input())
x = [list(map(int, input().split())) for _ in range(N)]
nlst = '01234567'
xlst = []
a = [-1] * N
def dfs(cnt):
    if cnt == N:
        tmpF = True
        for i in range(N):
            if a.count(int(nlst[i])) != 1:
                tmpF = False
                break
        if tmpF:
            tmp = 0
            for i in range(1, N):
                tmp += math.sqrt(((x[a[i - 1]][0] - x[a[i]][0]) ** 2) + (x[a[i - 1]][1] - x[a[i]][1]) ** 2)
            xlst.append(tmp)
        return

    for i in range(N):
        a[cnt] = i
        dfs(cnt + 1)

dfs(0)

kain = 1
for i in range(1, N + 1):
    kain *= i

print(sum(xlst) / kain)

Fixed submission:
import itertools
import math
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
p = []
cnt = 0

for v in itertools.permutations(xy, N):
    p.append(v)

ans = 0
for i in range(len(p)):
    for j in range(N - 1):
        ans += math.sqrt((p[i][j][0] - p[i][j + 1][0]) ** 2 + (p[i][j][1] - p[i][j + 1][1]) ** 2)

print(ans / len(p))

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
x = [list(map(int, input().split())) for _ in range(N)]
nlst = '01234567'
xlst = []
a = [-1] * N
def dfs(cnt):
    if cnt == N:
        tmpF = True
        for i in range(N):
            if a.count(int(nlst[i])) != 1:
                tmpF = False
                break
        if tmpF:
            tmp = 0
            for i in range(1, N):
                tmp += math.sqrt(((x[a[i - 1]][0] - x[a[i]][0]) ** 2) + (x[a[i - 1]][1] - x[a[i]][1]) ** 2)
            xlst.append(tmp)
        return

    for i in range(N):
        a[cnt] = i
        dfs(cnt + 1)

dfs(0)

kain = 1
for i in range(1, N + 1):
    kain *= i

print(sum(xlst) / kain)

Fixed submission:
import itertools
import math
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
p = []
cnt = 0

for v in itertools.permutations(xy, N):
    p.append(v)

ans = 0
for i in range(len(p)):
    for j in range(N - 1):
        ans += math.sqrt((p[i][j][0] - p[i][j + 1][0]) ** 2 + (p[i][j][1] - p[i][j + 1][1]) ** 2)

print(ans / len(p))
Buggy python submission (verdict: Runtime Error):
from sympy import Symbol, solve
x = Symbol('x')
y = Symbol('y')

tmp1 = 2*x + 3*y - 6
tmp2 = 3*x + 2*y - 12

ans = solve((tmp1, tmp2))
print(ans[x])
print(x)

Fixed submission:
MOD = 10 ** 9 + 7
MAX = 10 ** 6 + 1
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX

def CoMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def COM(n, k):
   if n < k:
       return 0
   if n < 0 or k < 0:
       return 0

   return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

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

if (X + Y) % 3:
    print(0)
    exit()
n = (X + Y) // 3
X -= n
Y -= n
if X < 0 or Y < 0:
    print(0)
    exit()
CoMinit()
ans = COM(X + Y, X)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

cnt = 0
tmp = 1
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
       tmp += 1
    elif tmp >= 2:
        cnt += tmp // 2
        tmp = 1
    else:
        tmp = 1

if tmp >= 2:
    cnt += 1

tmp1 = cnt
if S[0] == S[-1]:
    if S[-2] != S[-1]:
        cnt += 1

print((cnt * (K - 1) + tmp1))

Fixed submission:
import math

S = input()
K = int(input())
cnt = 0
tmp = 1
if K == 1:
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            tmp += 1
        elif tmp >= 2:
            cnt += tmp // 2
            tmp = 1
        else:
            tmp = 1
    if tmp >= 2:
        cnt += tmp // 2
else:
    g1 = 0
    g2 = 0
    jlst = S + S
    for i in range(1, len(S) * 2):
        if jlst[i - 1] == jlst[i]:
            tmp += 1
        elif tmp >= 2:
            cnt += tmp // 2
            tmp = 1
        else:
            tmp = 1

    if tmp >= 2:
        cnt += tmp // 2

    if cnt % 2 == 0:
        cnt = K * (cnt // 2)
    else:
        g1 = cnt // 2
        g2 = cnt - g1
        v = math.ceil(K / 2)
        if tmp >= 3 and tmp % 2 != 0 and S[0] == S[-1]:
            cnt = g1 + (g2 * (K - 1))
        else:
            cnt = (g1 * v) + (g2 * (K - v))

print(cnt)