Buggy python submission (verdict: Runtime Error):
x, y = [int(x) for x in input().split()]
 
def c(n, r):
    u = 1
    l = 1
    for i in range(min(r, n - r)):
        u = u * (n - i) / (i + 1)
    return int(u)
 
def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * x < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return c(n, r)

print(solve(x, y) % 1000000007)


Fixed submission:
MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX


def comb_init():
    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 comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


comb_init()
x, y = [int(x) for x in input().split()]


def solve(x, y):

    if (x + y) % 3 != 0:
        return 0

    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    if n < 0 or m < 0:
        return 0

    return comb(n + m, n)


print(solve(x, y))

Buggy python submission (verdict: Time Limit Exceeded):
x, y = [int(x) for x in input().split()]


def c(n, r):
    u = 1
    l = 1
    for i in range(min(r, n - r)):
        u *= n - i
        l *= i + 1
    return u // l


def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * 2 < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return c(n, r)


print(solve(x, y) % 1000000007)

Fixed submission:
MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX


def comb_init():
    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 comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


comb_init()
x, y = [int(x) for x in input().split()]


def solve(x, y):

    if (x + y) % 3 != 0:
        return 0

    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    if n < 0 or m < 0:
        return 0

    return comb(n + m, n)


print(solve(x, y))

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

x, y = [int(x) for x in input().split()]


def c(n, r):
    u = 1
    for i in range(min(r, n - r)):
        u = u * (n - i) / (i + 1)
    return u


def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * 2 < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return factorial(n) // factorial(r) // factorial(n - r)


print(solve(x, y) % 1000000007)

Fixed submission:
MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX


def comb_init():
    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 comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


comb_init()
x, y = [int(x) for x in input().split()]


def solve(x, y):

    if (x + y) % 3 != 0:
        return 0

    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    if n < 0 or m < 0:
        return 0

    return comb(n + m, n)


print(solve(x, y))

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

x, y = [int(x) for x in input().split()]


def c(n, r):
    u = 1
    l = 1
    for i in range(min(r, n - r)):
        u *= n - i
        l *= i + 1
    return u // l


def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    if x * 2 < y or y * 2 < x:
        return 0
    
    n = (x + y) // 3
    r = ((x - y) + n) // 2
    return factorial(n) // factorial(r) // factorial(n - r)


print(solve(x, y) % 1000000007)

Fixed submission:
MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX


def comb_init():
    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 comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


comb_init()
x, y = [int(x) for x in input().split()]


def solve(x, y):

    if (x + y) % 3 != 0:
        return 0

    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    if n < 0 or m < 0:
        return 0

    return comb(n + m, n)


print(solve(x, y))