Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import floor, ceil
h, w = map(int, input().split(' '))
result = []
if h%3 == 0 or w%3 == 0:
    print(0)
else:
    for i in range(1, h-1):
        x = i*w
        y = (h-i)*floor(w/2)
        z = (h-i)*ceil(w/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((h-i)/2)*w
        z = ceil((h-i)/2)*w
        result.append(max(x,y,z)-min(x,y,z))
    for i in range(1, w-1):
        x = i*h
        y = (w-i)*floor(h/2)
        z = (w-i)*ceil(h/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((w-i)/2)*h
        z = ceil((w-i)/2)*h
        result.append(max(x,y,z)-min(x,y,z))
    print(min(result))

Fixed submission:
from math import floor, ceil
h, w = map(int, input().split(' '))
result = []
if h%3 == 0 or w%3 == 0:
    print(0)
elif h<3 or w<3:
    if h<3 and w>=3:
        for i in range(1, w-1):
            x = i*h
            y = (w-i)*floor(h/2)
            z = (w-i)*ceil(h/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((w-i)/2)*h
            z = ceil((w-i)/2)*h
            result.append(max(x,y,z)-min(x,y,z))
        print(min(result))
    elif h>=3 and w<3:
        for i in range(1, h-1):
            x = i*w
            y = (h-i)*floor(w/2)
            z = (h-i)*ceil(w/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((h-i)/2)*w
            z = ceil((h-i)/2)*w
            result.append(max(x,y,z)-min(x,y,z))
        print(min(result))
    else:
        print(1)
else:
    for i in range(1, h-1):
        x = i*w
        y = (h-i)*floor(w/2)
        z = (h-i)*ceil(w/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((h-i)/2)*w
        z = ceil((h-i)/2)*w
        result.append(max(x,y,z)-min(x,y,z))
    for i in range(1, w-1):
        x = i*h
        y = (w-i)*floor(h/2)
        z = (w-i)*ceil(h/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((w-i)/2)*h
        z = ceil((w-i)/2)*h
        result.append(max(x,y,z)-min(x,y,z))
    print(min(result))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c = map(int, input().split())

counter = 0
while a%2==b%2==c%2==0:
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    counter += 1
    if counter > 100000000:
        counter = -1
        break
print(counter)

Fixed submission:
a, b, c = map(int, input().split())

counter = 0
while a%2==b%2==c%2==0:
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    counter += 1
    if counter > 1000:
        counter = -1
        break
print(counter)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split(' ')))
result = 0
h = 0
if a[0] == 0:
    counter += 1
    result += 1
else:
    counter += a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result +=1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result += 1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out = []
out.append(result)
result = 0
counter = 0
if a[0] == 0:
    counter -= 1
    result +=1
elif a[0]< 0:
    counter += 1
    result += 1-a[0]
else:
    counter -= 1
    result += 1+a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result += 1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result +=1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out.append(result)
print(min(out))

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
result = 0
counter = 0
if a[0] == 0:
    counter += 1
    result += 1
else:
    counter += a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result +=1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result += 1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out = []
out.append(result)
result = 0
counter = 0
if a[0] == 0:
    counter -= 1
    result +=1
elif a[0]< 0:
    counter += 1
    result += 1-a[0]
else:
    counter -= 1
    result += 1+a[0]

for i in range(1, n):
    if counter < 0:
        counter += a[i]
        if counter == 0:
            counter += 1
            result += 1
        elif counter > 0:
            continue
        else:
            result += 1-counter
            counter = 1
    else:
        counter += a[i]
        if counter == 0:
            counter -= 1
            result +=1
        elif counter < 0:
            continue
        else:
            result += counter+1
            counter = -1
out.append(result)
print(min(out))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = str(input())
s += s[0]
candidate = [[1,-1],[1,1],[-1,-1],[-1,1]]
result = []
checker = 0
while checker < 4:
    result = candidate[checker]
    for i in range(1, n):
        if s[i] == 'o' and result[i] == 1:
            result.append(result[-2])
        elif s[i] == 'x' and result[i] == 1:
            result.append(-result[-2])
        elif s[i] == 'o' and result[i] == -1:
            result.append(-result[-2])
        else:
            result.append(result[-2])
    if result[0] == result[-1]:
        checker += 10
    else:
        checker += 1
if checker == 4:
    print(-1)
else:
    result = ['S' if x == 1 else 'W' for x in result[:n]]
    print(''.join(result)

Fixed submission:
n = int(input())
s = str(input())
s += s
candidate = [[1,-1],[1,1],[-1,-1],[-1,1]]
result = []
checker = 0
while checker < 4:
    result = candidate[checker]
    for i in range(1, len(s)-1):
        if s[i] == 'o' and result[i] == 1:
            result.append(result[-2])
        elif s[i] == 'x' and result[i] == 1:
            result.append(-result[-2])
        elif s[i] == 'o' and result[i] == -1:
            result.append(-result[-2])
        else:
            result.append(result[-2])
    if result[:n] == result[n:]:
        checker += 10
    else:
        checker += 1
if checker == 4:
    print(-1)
else:
    result = ['S' if x == 1 else 'W' for x in result[:n]]
    print(''.join(result))
Buggy python submission (verdict: Runtime Error):
n = int(input())

def gcd(num):
    result = []
    for i in range(2, int(num**(1/2))+2):
        r = 0
        while num%i == 0:
            num = num//i
            r += 1
        if r != 0:
            result.append(r)
    return result

c = 1
for i in range(1, n+1):
    c *= i
o = 1
res = gcd(c)
if len(res) != 0:
    for i in range(len(res)):
        o *= res[i]+1
    print(o%(10**9 + 7))
else:
    print(2)

Fixed submission:
n = int(input())

result = [0 for i in range(n+1)]

for i in range(1, n+1):
    for j in range(2, i+1):
        while i%j == 0:
            result[j] += 1
            i //= j
        if i == 1:
            break
r = 1
for i in range(n+1):
    r *= result[i]+1
    r %= 10**9 + 7
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
tree = [[] for _i in range(m+1)]
k = []
for i in range(n):
    x = list(map(int, input().split()))
    for j in x[1:]:
        tree[j].append(i)
    k.append(x[1:])

visit = [0 for _ in range(n)]
from collections import deque
q = deque([0])
while q:
    p = q.pop()
    if visit[p]==1:
        continue
    visit[p] = 1
    for i in k[p]:
        for j in tree[i]:
            if visit[j]==0:
                q.appendleft(j)
if sum(visit)==n:
    print("YES")
else:
    print("NO")

Fixed submission:
n, m = map(int, input().split())
tree = [[] for _i in range(m+n+1)]
for i in range(n):
    x = list(map(int, input().split()))
    tree[i].extend([i+n for i in x[1:]])
    for j in x[1:]:
        tree[j+n].append(i)

from collections import deque
q = deque([1])
visit = [0 for _i in range(m+n+2)]
visit[1] = 1
while q:
    p = q.pop()
    for j in tree[p]:
        if visit[j]==0:
            visit[j] = 1
            q.appendleft(j)
if sum(visit[:n]) == n:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
tree = [[] for _i in range(m+1)]
k = []
for i in range(n):
    x = list(map(int, input().split()))
    for j in x[1:]:
        tree[j].append(i)
    k.append(x[1:])

visit = [0 for _ in range(n)]
from collections import deque
q = deque([0])
while q:
    p = q.pop()
    if visit[p]==1:
        continue
    visit[p] = 1
    for i in k[p]:
        for j in tree[i]:
            if visit[j]==0:
                q.appendleft(j)
if sum(visit)==n:
    print("YES")
else:
    print("NO")

Fixed submission:
n, m = map(int, input().split())
tree = [[] for _i in range(m+n+1)]
for i in range(n):
    x = list(map(int, input().split()))
    tree[i].extend([i+n for i in x[1:]])
    for j in x[1:]:
        tree[j+n].append(i)

from collections import deque
q = deque([1])
visit = [0 for _i in range(m+n+2)]
visit[1] = 1
while q:
    p = q.pop()
    for j in tree[p]:
        if visit[j]==0:
            visit[j] = 1
            q.appendleft(j)
if sum(visit[:n]) == n:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
result = 1
for i in range(n):
    h_max, h_min = min(t[i], a[i])+1, 1

    if i != 0:
        if t[i-1] < t[i]:
            h_min = t[i]
    else:
        h_min = t[0]

    if i != n-1:
        if a[i] > a[i+1]:
            h_min = a[i]
    else:
        h_min = max(a[n-1], h_min)


    result = result * max(h_max - h_min, 0)
print(result % (10**9+7))

Fixed submission:
n = int(input())
t = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
result = 1
for i in range(n):
    h_max, h_min = min(t[i], a[i])+1, 1

    if i != n-1:
        if a[i] > a[i+1]:
            h_min = a[i]
    else:
        h_min = a[n-1] 

    if i != 0:
        if t[i-1] < t[i]:
            h_min = t[i]
    else:
        h_min = t[0]


    result = result * max(h_max - h_min, 0) % (10**9+7)
print(result)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
w = list(Counter(list(input())).items())
if all(w[i][1]%2== for i in range(len(w))):
    print("Yes")
else:
    print("No")

Fixed submission:
from collections import Counter
w = list(Counter(list(input())).items())
if all(w[i][1]%2==0 for i in range(len(w))):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = input()
kita, minami = sorted([s.count('N'),s.count('S')])
nisi, higasi = sorted([s.count('W'),s.count('E')])
result = ['No','Yes']
r = 1
if kita==minami:
    continue
elif kita*minami > 0:
    continue
else:
    r *= 0
if nisi==higasi:
    continue
elif nisi*higasi > 0:
    continue
else:
    r = 0
print(result[r])

Fixed submission:
s = input()
kita, minami = sorted([s.count('N'),s.count('S')])
nisi, higasi = sorted([s.count('W'),s.count('E')])
result = ['No','Yes']
r = 1
if kita==minami or kita*minami > 0:
    r *= 1
else:
    r = 0

if nisi==higasi or nisi*higasi > 0:
    r *= 1
else:
    r = 0
print(result[r])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
counter = 0
for i in range(0, n, 2):
    if a.index(b[i])%2 == 1:
        counter += 1
print(counter)

Fixed submission:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = sorted(a)
    c = b[::2]
    d = a[::2]
    set_c = set(c)
    set_d = set(d)
    print(len(set_c - set_d))
main()
Buggy python submission (verdict: Runtime Error):
X, K, D = map(int, input().split())


def f(C):
    NX = float("inf")
    if C > K:
        return NX

    if K % 2 == 0:
        if C % 2 == 0:
            NX = abs(abs(X) - C * D)
        else:
            NX = abs(abs(X) - (C + 1) * D)
            if C > 0:
                NX = min(NX, abs(abs(X) - (C - 1) * D))
    else:
        if C % 2 == 0:
            NX = abs(NX, abs(X) - (C + 1) * D)
            if C > 0:
                NX = min(NX, abs(abs(X) - (C - 1) * D))
        else:
            NX = abs(abs(X) - C * D)

    return NX


C = min(abs(X) // D, K)

print(min(f(C), f(C + 1)))


Fixed submission:
X, K, D = map(int, input().split())


def f(C):
    NX = float("inf")
    if C > K:
        return NX

    if K % 2 == 0:
        if C % 2 == 0:
            NX = abs(abs(X) - C * D)
        else:
            NX = abs(abs(X) - (C + 1) * D)
            if C > 0:
                NX = min(NX, abs(abs(X) - (C - 1) * D))
    else:
        if C % 2 == 0:
            NX = abs(abs(X) - (C + 1) * D)
            if C > 0:
                NX = min(NX, abs(abs(X) - (C - 1) * D))
        else:
            NX = abs(abs(X) - C * D)

    return NX


C = min(abs(X) // D, K)

print(min(f(C), f(C + 1)))
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())

MOD = 10 ** 9 + 7


def comb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] *= pow(pivot, MOD - 2, MOD)
                numerator[k - offset] %= MOD
                denominator[k] *= pow(pivot, MOD - 2, MOD)
                denominator[k] %= MOD

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            result %= MOD

    return result


# maxn = 2 * pow(10, 5)
# f = [1 for _ in range(2 * pow(10, 5) + 1)]
# invf = [1 for _ in range(2 * pow(10, 5) + 1)]

# for i in range(1, maxn + 1):
#     f[i] = (f[i - 1] * i) % MOD
# invf[maxn] = pow(f[maxn], MOD - 2, MOD)
# for i in range(maxn, -1, -1):
#     invf[i - 1] = (invf[i] * i) % MOD


# def comb(n, r):
#     return f[n] * invf[r] * invf[n - r] % MOD


res = pow(2, N, MOD)

res -= comb(N, A) + comb(N, B)
print((res - 1) % MOD)


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

MOD = 10 ** 9 + 7


def comb(n, r):
    if n - r < r:
        r = n - r

    res = 1
    for i in range(n - r + 1, n + 1):
        res = res * i % MOD
    for i in range(1, r + 1):
        res = res * pow(i, MOD - 2, MOD) % MOD
    return res


res = pow(2, N, MOD)

res -= comb(N, A) + comb(N, B)
res %= MOD
print(res - 1)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [float("inf") for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for i in range(N):
        dp[h] = min(dp[h], dp[max(0, h - A[i])] + B[i])

print(dp[H])


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

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [float("inf") for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for i in range(N):
        dp[h] = min(dp[h], dp[max(0, h - A[i])] + B[i])

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

H, N = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [[float("inf") for _ in range(H + 1)] for _ in range(N + 1)]

for i in range(N + 1):
    dp[i][0] = 0

for i in range(N):
    for h in range(H):
        dp[i + 1][min(H, h + A[i])] = min(
            dp[i + 1][min(H, h + A[i])], dp[i][min(H, h + A[i])]
        )
        dp[i + 1][min(H, h + A[i])] = min(
            dp[i + 1][min(H, h + A[i])], dp[i + 1][h] + B[i]
        )

print(dp[N][H])


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

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [float("inf") for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for i in range(N):
        dp[h] = min(dp[h], dp[max(0, h - A[i])] + B[i])

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

H, N = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [[float("inf") for _ in range(H + 1)] for _ in range(N + 1)]

for i in range(N + 1):
    dp[i][0] = 0

for i in range(N):
    for h in range(H):
        dp[i + 1][min(H, h + A[i])] = min(
            dp[i + 1][min(H, h + A[i])], dp[i][min(H, h + A[i])]
        )
        dp[i + 1][min(H, h + A[i])] = min(
            dp[i + 1][min(H, h + A[i])], dp[i + 1][h] + B[i]
        )

print(dp[N][H])


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

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [float("inf") for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for i in range(N):
        dp[h] = min(dp[h], dp[max(0, h - A[i])] + B[i])

print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

res = 0

for k in range(60):
    cnt = [0, 0]
    for i in range(N):
        cnt[(A[i] >> k) & 1] += 1
    res = (res + cnt[0] * cnt[1] * pow(2, k)) % MOD

print(res)


Fixed submission:
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))

res = 0

for k in range(60):
    cnt = [0, 0]
    for i in range(N):
        cnt[(A[i] >> k) & 1] += 1
    res = (res + cnt[0] * cnt[1] * pow(2, k)) % MOD

print(res)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin >> N >> S;
  vector<int> left(10, 0), right(10, 0);
  left[S[0] - '0']++;
  for (int i = 2; i < N; i++) {
    right[S[i] - '0']++;
  }
  vector<int> cnts(1000, 0);
  for (int i = 1; i < N - 1; i++) {
    int b = S[i] - '0';
    for (int a = 0; a < 10; a++) {
      for (int c = 0; c < 10; c++) {
        if (left[a] == 0 || right[c] == 0) continue;
        cnts[100 * a + 10 * b + c]++;
      }
    }
    left[S[i] - '0']++;
    right[S[i + 1] - '0']--;
  }
  int res = 0;
  for (int i = 0; i < 1000; i++) {
    if (cnts[i] != 0) res++;
  }
  cout << res << '\n';
  return 0;
}


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

right = [[0 for _ in range(10)] for _ in range(N + 1)]
left = [[0 for _ in range(10)] for _ in range(N + 1)]
C = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]

for i in range(N - 1):
    for j in range(10):
        right[i + 1][j] += right[i][j]
    right[i + 1][int(S[i])] += 1

for i in range(N - 1, 0, -1):
    for j in range(10):
        left[i][j] += left[i + 1][j]
    left[i][int(S[i])] += 1

for i in range(1, N - 1):
    for a in range(10):
        for b in range(10):
            if right[i][a] != 0 and left[i + 1][b] != 0:
                C[a][int(S[i])][b] += 1

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if C[i][j][k] != 0:
                res += 1

print(res)

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

right = [[0 for _ in range(10)] for _ in range(N + 1)]
left = [[0 for _ in range(10)] for _ in range(N + 1)]
C = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]

for i in range(N - 1):
    for j in range(10):
        right[i + 1][j] += right[i][j]
    right[i + 1][int(S[i])] += 1

for i in range(N - 1, 0, -1):
    for j in range(10):
        left[i][j] += left[i + 1][j]
    left[i][int(S[i])] += 1

for i in range(1, N - 1):
    for a in range(10):
        for b in range(10):
            if right[i][a] != 0 and left[i + 1][b] != 0:
                C[a][int(S[i])][b] += 1

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if C[i][j][k] != 0:
                res += 1

print(res)


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

right = [[0 for _ in range(10)] for _ in range(N + 1)]
left = [[0 for _ in range(10)] for _ in range(N + 1)]
C = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]

for i in range(N - 1):
    for j in range(10):
        right[i + 1][j] += right[i][j]
    right[i + 1][int(S[i])] += 1

for i in range(N - 1, 0, -1):
    for j in range(10):
        left[i][j] += left[i + 1][j]
    left[i][int(S[i])] += 1

for i in range(1, N - 1):
    for a in range(10):
        for b in range(10):
            if right[i][a] != 0 and left[i + 1][b] != 0:
                C[a][int(S[i])][b] += 1

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if C[i][j][k] != 0:
                res += 1

print(res)
Buggy python submission (verdict: Runtime Error):
    MOD = 10 ** 9 + 7
     
    X, Y = map(int, input().split())
     
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
     
    if not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0 and a >= 0 and b >= 0):
        print(0)
        exit()
     
    maxf = a + b + 1
    f = [1 for _ in range(maxf)]
    invf = [1 for _ in range(maxf)]
     
    for i in range(1, maxf):
        f[i] = (i * f[i - 1]) % MOD
    invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
     
    for i in range(maxf - 1, 0, -1):
        invf[i - 1] = (i * invf[i]) % MOD
     
     
    def comb(a, b):
        return (f[a + b] * invf[a] * invf[b]) % MOD
     
     
    print(comb(a, b))

Fixed submission:
MOD = 10 ** 9 + 7

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

a, b = (2 * X - Y) // 3, (2 * Y - X) // 3
maxf = a + b + 10

if (not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0)) or (a < 0 or b < 0):
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = (f[i - 1] * i) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (invf[i] * i) % MOD

comb = lambda a, b: f[a + b] * invf[a] * invf[b] % MOD

print(comb(a, b) % MOD)

Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

MOD = 10 ** 9 + 7

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

a, b = (2 * X - Y) // 3, (2 * Y - X) // 3
# maxf = 2 * 10 ** 6 + 100
maxf = a + b + 10

if 2 * a + b != X or a + 2 * b != Y:
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = (f[i - 1] * i) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (invf[i] * i) % MOD

comb = lambda a, b: f[a + b] * invf[a] * invf[b] % MOD

print(comb(a, b) % MOD)


Fixed submission:
MOD = 10 ** 9 + 7

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

a, b = (2 * X - Y) // 3, (2 * Y - X) // 3
maxf = a + b + 10

if (not ((2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0)) or (a < 0 or b < 0):
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = (f[i - 1] * i) % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = (invf[i] * i) % MOD

comb = lambda a, b: f[a + b] * invf[a] * invf[b] % MOD

print(comb(a, b) % MOD)