import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



def cmb(n, k, mod, fac, ifac):

    # nCkを計算する

    k = min(k, n-k)

    return fac[n] * ifac[k] * ifac[n-k] % mod



def make_tables(mod, n):

    # 階乗テーブル、逆元の階乗テーブルを作成する

    fac = [1, 1] # 階乗テーブル

    ifac = [1, 1] # 逆元の階乗テーブル

    inverse = [0, 1] # 逆元テーブル 0の階乗は1 0の逆元は0



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

        fac.append((fac[-1] * i) % mod)

        inverse.append((-inverse[mod % i] * (mod//i)) % mod)

        ifac.append((ifac[-1] * inverse[-1]) % mod)

    return fac, ifac



X, Y = lr()

MOD = 10 ** 9 + 7

if (X+Y)%3 != 0 or X > 2 * Y or Y > 2 * X:

    print((0))

    exit()

if X < Y:

    X, Y = Y, X

# Xが大きい

total_time = (X+Y)//3

x_time = (X - Y + total_time) // 2

# total_time C i_time

fac, ifac = make_tables(MOD, total_time)

answer = fac[total_time] * ifac[x_time] * ifac[total_time - x_time] % MOD

print(answer)

# 44
import sys

import numpy as np



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



MOD = 10 ** 9 + 7



def cmb(n, k):

    if k < 0 or k > n: return 0 

    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD



def cumprod(arr, MOD):

    L = len(arr); Lsq = int(L**.5+1)

    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)

    for n in range(1, Lsq):

        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD

    for n in range(1, Lsq):

        arr[n] *= arr[n-1, -1]; arr[n] %= MOD

    return arr.ravel()[:L]



def make_fact(U, MOD):

    x = np.arange(U, dtype=np.int64); x[0] = 1

    fact = cumprod(x, MOD)

    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)

    fact_inv = cumprod(x, MOD)[::-1]

    return fact, fact_inv



U = 10 ** 6 # 階乗テーブルの上限

fact, fact_inv = make_fact(U, MOD)

X, Y = lr()

if (X+Y)%3 != 0 or X > Y + Y or Y > X + X:

    print((0)); exit()



time = (X+Y) // 3

diff = abs(X-Y)

a = (time-diff)//2

# timeCaが答え

answer = cmb(time, a)

print((answer%MOD))

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


def cmb(n, k, mod, fac, ifac):
    # nCkを計算する
    k = min(k, n - k)
    return fac[n] * ifac[k] * ifac[n - k] % mod


def make_tables(mod, n):
    # 階乗テーブル、逆元の階乗テーブルを作成する
    fac = [1, 1]  # 階乗テーブル
    ifac = [1, 1]  # 逆元の階乗テーブル
    inverse = [0, 1]  # 逆元テーブル 0の階乗は1 0の逆元は0
    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


X, Y = lr()
MOD = 10**9 + 7
if (X + Y) % 3 != 0 or X > 2 * Y or Y > 2 * X:
    print((0))
    exit()
if X < Y:
    X, Y = Y, X
# Xが大きい
total_time = (X + Y) // 3
x_time = (X - Y + total_time) // 2
# total_time C i_time
fac, ifac = make_tables(MOD, total_time)
answer = fac[total_time] * ifac[x_time] * ifac[total_time - x_time] % MOD
print(answer)
# 44

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 10**9 + 7


def cmb(n, k):
    if k < 0 or k > n:
        return 0
    return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**0.5 + 1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n - 1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n - 1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD - 2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**6  # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
X, Y = lr()
if (X + Y) % 3 != 0 or X > Y + Y or Y > X + X:
    print((0))
    exit()
time = (X + Y) // 3
diff = abs(X - Y)
a = (time - diff) // 2
# timeCaが答え
answer = cmb(time, a)
print((answer % MOD))

+import numpy as np +MOD = 10**9 + 7 -def cmb(n, k, mod, fac, ifac): -    # nCkを計算する -    k = min(k, n - k) -    return fac[n] * ifac[k] * ifac[n - k] % mod +def cmb(n, k): +    if k < 0 or k > n: +        return 0 +    return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD -def make_tables(mod, n): -    # 階乗テーブル、逆元の階乗テーブルを作成する -    fac = [1, 1]  # 階乗テーブル -    ifac = [1, 1]  # 逆元の階乗テーブル -    inverse = [0, 1]  # 逆元テーブル 0の階乗は1 0の逆元は0 -    for i in range(2, n + 1): -        fac.append((fac[-1] * i) % mod) -        inverse.append((-inverse[mod % i] * (mod // i)) % mod) -        ifac.append((ifac[-1] * inverse[-1]) % mod) -    return fac, ifac +def cumprod(arr, MOD): +    L = len(arr) +    Lsq = int(L**0.5 + 1) +    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) +    for n in range(1, Lsq): +        arr[:, n] *= arr[:, n - 1] +        arr[:, n] %= MOD +    for n in range(1, Lsq): +        arr[n] *= arr[n - 1, -1] +        arr[n] %= MOD +    return arr.ravel()[:L] +def make_fact(U, MOD): +    x = np.arange(U, dtype=np.int64) +    x[0] = 1 +    fact = cumprod(x, MOD) +    x = np.arange(U, 0, -1, dtype=np.int64) +    x[0] = pow(int(fact[-1]), MOD - 2, MOD) +    fact_inv = cumprod(x, MOD)[::-1] +    return fact, fact_inv + + +U = 10**6  # 階乗テーブルの上限 +fact, fact_inv = make_fact(U, MOD) -MOD = 10**9 + 7 -if (X + Y) % 3 != 0 or X > 2 * Y or Y > 2 * X: +if (X + Y) % 3 != 0 or X > Y + Y or Y > X + X: -if X < Y: -    X, Y = Y, X -# Xが大きい -total_time = (X + Y) // 3 -x_time = (X - Y + total_time) // 2 -# total_time C i_time -fac, ifac = make_tables(MOD, total_time) -answer = fac[total_time] * ifac[x_time] * ifac[total_time - x_time] % MOD -print(answer) -# 44 +time = (X + Y) // 3 +diff = abs(X - Y) +a = (time - diff) // 2 +# timeCaが答え +answer = cmb(time, a) +print((answer % MOD))