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

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

    print((0))

else:

    k = (x + y)//3

    if k <= x <= 2*k:

        MOD = 10**9 + 7

        fac = [0]*(k + 1)

        finv = [0]*(k + 1)

        inv = [0]*(k + 1)

        fac[0] = 1; fac[1] = 1; finv[0] =1; finv[1] = 1; inv[1] = 1

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

            fac[i] = fac[i - 1] * i % MOD

            inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD

            finv[i] = finv[i - 1] * inv[i] % MOD

        

        i = x - k

        print((fac[k] * (finv[i] * finv[k - i] % MOD) % MOD))

    else:

        print((0))
# 拡張ユークリッド互除法を用いて逆元を求める

def modinv(a, m):

    b = m; x0 = 1; x1 = 0

    while b:

        q = a//b

        a, b = b, a%b

        x0, x1 = x1, x0 - q*x1

    return x0%m 





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

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

    print((0))

else:

    k = (x + y)//3

    if k <= x <= 2*k:

        i = min(x - k, 2*k - x)

        # 結局 コンビネーションkCiに帰着

        MOD = 10**9 + 7

        # まず階乗のmodを求める

        fac = [1]*(k + 1)

        for j in range(2, k + 1):

            fac[j] = fac[j - 1]*j%MOD

        # 次に階乗の逆元を求める

        finv = [0]*(k + 1)

        #finv[k] = pow(fac[k], MOD - 2, MOD) # fac[k]の逆元, フェルマーの小定理

        finv[k] = modinv(fac[k], MOD)

        for j in range(k, i, - 1):

            finv[j - 1] = finv[j]*j%MOD



        print((fac[k] * (finv[i] * finv[k - i] % MOD) % MOD))

    else:

        print((0))
x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
    print((0))
else:
    k = (x + y) // 3
    if k <= x <= 2 * k:
        MOD = 10**9 + 7
        fac = [0] * (k + 1)
        finv = [0] * (k + 1)
        inv = [0] * (k + 1)
        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, k + 1):
            fac[i] = fac[i - 1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD
        i = x - k
        print((fac[k] * (finv[i] * finv[k - i] % MOD) % MOD))
    else:
        print((0))

# 拡張ユークリッド互除法を用いて逆元を求める
def modinv(a, m):
    b = m
    x0 = 1
    x1 = 0
    while b:
        q = a // b
        a, b = b, a % b
        x0, x1 = x1, x0 - q * x1
    return x0 % m


x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
    print((0))
else:
    k = (x + y) // 3
    if k <= x <= 2 * k:
        i = min(x - k, 2 * k - x)
        # 結局 コンビネーションkCiに帰着
        MOD = 10**9 + 7
        # まず階乗のmodを求める
        fac = [1] * (k + 1)
        for j in range(2, k + 1):
            fac[j] = fac[j - 1] * j % MOD
        # 次に階乗の逆元を求める
        finv = [0] * (k + 1)
        # finv[k] = pow(fac[k], MOD - 2, MOD) # fac[k]の逆元, フェルマーの小定理
        finv[k] = modinv(fac[k], MOD)
        for j in range(k, i, -1):
            finv[j - 1] = finv[j] * j % MOD
        print((fac[k] * (finv[i] * finv[k - i] % MOD) % MOD))
    else:
        print((0))

+# 拡張ユークリッド互除法を用いて逆元を求める +def modinv(a, m): +    b = m +    x0 = 1 +    x1 = 0 +    while b: +        q = a // b +        a, b = b, a % b +        x0, x1 = x1, x0 - q * x1 +    return x0 % m + + +        i = min(x - k, 2 * k - x) +        # 結局 コンビネーションkCiに帰着 -        fac = [0] * (k + 1) +        # まず階乗のmodを求める +        fac = [1] * (k + 1) +        for j in range(2, k + 1): +            fac[j] = fac[j - 1] * j % MOD +        # 次に階乗の逆元を求める -        inv = [0] * (k + 1) -        fac[0] = 1 -        fac[1] = 1 -        finv[0] = 1 -        finv[1] = 1 -        inv[1] = 1 -        for i in range(2, k + 1): -            fac[i] = fac[i - 1] * i % MOD -            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD -            finv[i] = finv[i - 1] * inv[i] % MOD -        i = x - k +        # finv[k] = pow(fac[k], MOD - 2, MOD) # fac[k]の逆元, フェルマーの小定理 +        finv[k] = modinv(fac[k], MOD) +        for j in range(k, i, -1): +            finv[j - 1] = finv[j] * j % MOD