import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

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



def modfact(n):

    fact=[1]*(n+1)

    invfact=[1]*(n+1)

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

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

    invfact[n]=pow(fact[n],MOD-2,MOD)

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

        invfact[i]=invfact[i+1]*(i+1)%MOD

    return fact,invfact



def resolve():

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

    if((x+y)%3):

        print((0))

        return



    z=(x+y)//3

    if(x-z<0 or y-z<0):

        print((0))

        return

    

    fact,invfact=modfact(z)

    print((fact[z]*invfact[x-z]%MOD*invfact[y-z]%MOD))

resolve()
import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

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



class modfact(object):

    def __init__(self,n):

        fact=[1]*(n+1)

        invfact=[1]*(n+1)

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

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

        invfact[n]=pow(fact[n],MOD-2,MOD)

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

            invfact[i]=invfact[i+1]*(i+1)%MOD

        self.__fact=fact

        self.__invfact=invfact



    def fact(self,n):

        return self.__fact[n]



    def invfact(self,n):

        return self.__invfact[n]



    def comb(self,n,k):

        if(k<0 or n-k<0): return 0

        return (self.fact(n)*self.invfact(k)*self.invfact(n-k))%MOD



def resolve():

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

    if((x+y)%3):

        print((0))

        return

    z=(x+y)//3

    mf=modfact(z)

    print((mf.comb(z,x-z)))

resolve()
import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


def modfact(n):
    fact = [1] * (n + 1)
    invfact = [1] * (n + 1)
    for i in range(1, n + 1):
        fact[i] = i * fact[i - 1] % MOD
    invfact[n] = pow(fact[n], MOD - 2, MOD)
    for i in range(n - 1, -1, -1):
        invfact[i] = invfact[i + 1] * (i + 1) % MOD
    return fact, invfact


def resolve():
    x, y = list(map(int, input().split()))
    if (x + y) % 3:
        print((0))
        return
    z = (x + y) // 3
    if x - z < 0 or y - z < 0:
        print((0))
        return
    fact, invfact = modfact(z)
    print((fact[z] * invfact[x - z] % MOD * invfact[y - z] % MOD))


resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()


class modfact(object):
    def __init__(self, n):
        fact = [1] * (n + 1)
        invfact = [1] * (n + 1)
        for i in range(1, n + 1):
            fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1):
            invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self.__fact = fact
        self.__invfact = invfact

    def fact(self, n):
        return self.__fact[n]

    def invfact(self, n):
        return self.__invfact[n]

    def comb(self, n, k):
        if k < 0 or n - k < 0:
            return 0
        return (self.fact(n) * self.invfact(k) * self.invfact(n - k)) % MOD


def resolve():
    x, y = list(map(int, input().split()))
    if (x + y) % 3:
        print((0))
        return
    z = (x + y) // 3
    mf = modfact(z)
    print((mf.comb(z, x - z)))


resolve()

-def modfact(n): -    fact = [1] * (n + 1) -    invfact = [1] * (n + 1) -    for i in range(1, n + 1): -        fact[i] = i * fact[i - 1] % MOD -    invfact[n] = pow(fact[n], MOD - 2, MOD) -    for i in range(n - 1, -1, -1): -        invfact[i] = invfact[i + 1] * (i + 1) % MOD -    return fact, invfact +class modfact(object): +    def __init__(self, n): +        fact = [1] * (n + 1) +        invfact = [1] * (n + 1) +        for i in range(1, n + 1): +            fact[i] = i * fact[i - 1] % MOD +        invfact[n] = pow(fact[n], MOD - 2, MOD) +        for i in range(n - 1, -1, -1): +            invfact[i] = invfact[i + 1] * (i + 1) % MOD +        self.__fact = fact +        self.__invfact = invfact + +    def fact(self, n): +        return self.__fact[n] + +    def invfact(self, n): +        return self.__invfact[n] + +    def comb(self, n, k): +        if k < 0 or n - k < 0: +            return 0 +        return (self.fact(n) * self.invfact(k) * self.invfact(n - k)) % MOD -    if x - z < 0 or y - z < 0: -        print((0)) -        return -    fact, invfact = modfact(z) -    print((fact[z] * invfact[x - z] % MOD * invfact[y - z] % MOD)) +    mf = modfact(z) +    print((mf.comb(z, x - z)))