import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



def cmb(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] /= pivot

                denominator[k] /= pivot



    result = 1

    for k in range(r):

        if numerator[k] > 1:

            result *= int(numerator[k])



    return result



def main():

    

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

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

        print((0))

        return

    n = (x+y)//3

    a, b = (2*y-x)//3, (2*x-y)//3

    if a<0 or b<0:

        print((0))

        return

    o = cmb(n, a)

    o = o % (10**9+7)

    print(o)



if __name__ == "__main__":

    main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



def extgcd(a, b):

    if b == 0:

        return [1, 0, a]

    x, y, g = extgcd(b, a % b)

    return [y, x - a//b * y, g]





def mod_inverse(a, m):

    x, _, _ = extgcd(a, m)

    return (m + x % m) % m





def mod_comb(n, k, mod):

    mul, div = 1, 1

    for i in range(k):

        mul *= (n-i)

        div *= (i+1)

        mul %= mod

        div %= mod

    return mul * mod_inverse(div, mod) % mod





def main():

    

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

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

        print((0))

        return

    n = (x+y)//3

    a, b = (2*y-x)//3, (2*x-y)//3

    if a<0 or b<0:

        print((0))

        return

    print((mod_comb(n, min(a, b), (10**9+7))))



if __name__ == "__main__":

    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def cmb(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] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result


def main():
    x, y = list(map(int, readline().split()))
    if (x + y) % 3 != 0:
        print((0))
        return
    n = (x + y) // 3
    a, b = (2 * y - x) // 3, (2 * x - y) // 3
    if a < 0 or b < 0:
        print((0))
        return
    o = cmb(n, a)
    o = o % (10**9 + 7)
    print(o)


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a % b)
    return [y, x - a // b * y, g]


def mod_inverse(a, m):
    x, _, _ = extgcd(a, m)
    return (m + x % m) % m


def mod_comb(n, k, mod):
    mul, div = 1, 1
    for i in range(k):
        mul *= n - i
        div *= i + 1
        mul %= mod
        div %= mod
    return mul * mod_inverse(div, mod) % mod


def main():
    x, y = list(map(int, readline().split()))
    if (x + y) % 3 != 0:
        print((0))
        return
    n = (x + y) // 3
    a, b = (2 * y - x) // 3, (2 * x - y) // 3
    if a < 0 or b < 0:
        print((0))
        return
    print((mod_comb(n, min(a, b), (10**9 + 7))))


if __name__ == "__main__":
    main()

-def cmb(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] /= pivot -                denominator[k] /= pivot -    result = 1 -    for k in range(r): -        if numerator[k] > 1: -            result *= int(numerator[k]) -    return result +def extgcd(a, b): +    if b == 0: +        return [1, 0, a] +    x, y, g = extgcd(b, a % b) +    return [y, x - a // b * y, g] + + +def mod_inverse(a, m): +    x, _, _ = extgcd(a, m) +    return (m + x % m) % m + + +def mod_comb(n, k, mod): +    mul, div = 1, 1 +    for i in range(k): +        mul *= n - i +        div *= i + 1 +        mul %= mod +        div %= mod +    return mul * mod_inverse(div, mod) % mod -    o = cmb(n, a) -    o = o % (10**9 + 7) -    print(o) +    print((mod_comb(n, min(a, b), (10**9 + 7))))