import sys

import math

x, y = list(map(int, input().split()))



if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:

    print((0))

    sys.exit()



# 手数

n = (x + y) // 3

x -= n

y -= n





def cmb(n, r, p):

    if (r < 0) or (n < r):

        return 0

    r = min(r, n - r)

    return fact[n] * factinv[r] * factinv[n-r] % p





MOD = 10**9 + 7

N = 10**6

fact = [1, 1]

factinv = [1, 1]

inv = [0, 1]



for i in range(2, N + 1):

    fact.append((fact[-1] * i) % MOD)

    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)

    factinv.append((factinv[-1] * inv[-1]) % MOD)



print((cmb(x + y, x, MOD)))
import numpy as np

import sys

x, y = list(map(int, input().split()))



if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:

    print((0))

    sys.exit()



# 手数

n = (x + y) // 3

x -= n

y -= n





MOD = 10**9 + 7





def prepare(n, MOD):

    f = 1

    for m in range(1, n + 1):

        f *= m

        f %= MOD

    fn = f



    inv = pow(f, MOD - 2, MOD)

    invs = [1] * (n + 1)

    invs[n] = inv

    for m in range(n, 1, -1):

        inv *= m

        inv %= MOD

        invs[m - 1] = inv



    return fn, invs





fact, invs = prepare(n, MOD)



print((fact * invs[x] * invs[y] % MOD))
import sys
import math

x, y = list(map(int, input().split()))
if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print((0))
    sys.exit()
# 手数
n = (x + y) // 3
x -= n
y -= n


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)
print((cmb(x + y, x, MOD)))

import numpy as np
import sys

x, y = list(map(int, input().split()))
if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print((0))
    sys.exit()
# 手数
n = (x + y) // 3
x -= n
y -= n
MOD = 10**9 + 7


def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return fn, invs


fact, invs = prepare(n, MOD)
print((fact * invs[x] * invs[y] % MOD))

+import numpy as np -import math +MOD = 10**9 + 7 -def cmb(n, r, p): -    if (r < 0) or (n < r): -        return 0 -    r = min(r, n - r) -    return fact[n] * factinv[r] * factinv[n - r] % p +def prepare(n, MOD): +    f = 1 +    for m in range(1, n + 1): +        f *= m +        f %= MOD +    fn = f +    inv = pow(f, MOD - 2, MOD) +    invs = [1] * (n + 1) +    invs[n] = inv +    for m in range(n, 1, -1): +        inv *= m +        inv %= MOD +        invs[m - 1] = inv +    return fn, invs -MOD = 10**9 + 7 -N = 10**6 -fact = [1, 1] -factinv = [1, 1] -inv = [0, 1] -for i in range(2, N + 1): -    fact.append((fact[-1] * i) % MOD) -    inv.append((-inv[MOD % i] * (MOD // i)) % MOD) -    factinv.append((factinv[-1] * inv[-1]) % MOD) -print((cmb(x + y, x, MOD))) +fact, invs = prepare(n, MOD) +print((fact * invs[x] * invs[y] % MOD))