from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools

sys.setrecursionlimit(10**8)

mod = 10**9+7

mod2 = 998244353

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))



# def conb(n,r): 

#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



x,y = inpl()

x,y = max(x,y),min(x,y)

if (x+y)%3 or y*2 < x:

    print((0))

    quit()

n = (x+y)//3 + 1

k = x-n+2





def cmd(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



a = cmd(n-1,k-1)%mod

print(a)

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

mod2 = 998244353

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))



class Combination:

    """

    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる

    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)

    使用例：

    comb = Combination(1000000)

    print(comb(5, 3))  # 10

    """

    def __init__(self, n_max, mod=10**9+7):

        self.mod = mod

        self.modinv = self.make_modinv_list(n_max)

        self.fac, self.facinv = self.make_factorial_list(n_max)



    def __call__(self, n, r):

        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod



    def make_factorial_list(self, n):

        # 階乗のリストと階乗のmod逆元のリストを返す O(n)

        # self.make_modinv_list()が先に実行されている必要がある

        fac = [1]

        facinv = [1]

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

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

            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)

        return fac, facinv



    def make_modinv_list(self, n):

        # 0からnまでのmod逆元のリストを返す O(n)

        modinv = [0] * (n+1)

        modinv[1] = 1

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

            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod

        return modinv

comb = Combination(10**6)

x,y = inpl()

if (x+y)%3 or max(x,y) > min(x,y)*2:

    print((0))

    quit()

n = (x+y)//3

c = comb(n,x-n)

print(c)
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
mod2 = 998244353
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))


# def conb(n,r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
x, y = inpl()
x, y = max(x, y), min(x, y)
if (x + y) % 3 or y * 2 < x:
    print((0))
    quit()
n = (x + y) // 3 + 1
k = x - n + 2


def cmd(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


a = cmd(n - 1, k - 1) % mod
print(a)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
mod2 = 998244353
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


comb = Combination(10**6)
x, y = inpl()
if (x + y) % 3 or max(x, y) > min(x, y) * 2:
    print((0))
    quit()
n = (x + y) // 3
c = comb(n, x - n)
print(c)

-import sys, bisect, math, itertools +import sys, bisect, math, itertools, fractions, pprint -# def conb(n,r): -#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) +class Combination: +    """ +    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる +    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) +    使用例： +    comb = Combination(1000000) +    print(comb(5, 3))  # 10 +    """ + +    def __init__(self, n_max, mod=10**9 + 7): +        self.mod = mod +        self.modinv = self.make_modinv_list(n_max) +        self.fac, self.facinv = self.make_factorial_list(n_max) + +    def __call__(self, n, r): +        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod + +    def make_factorial_list(self, n): +        # 階乗のリストと階乗のmod逆元のリストを返す O(n) +        # self.make_modinv_list()が先に実行されている必要がある +        fac = [1] +        facinv = [1] +        for i in range(1, n + 1): +            fac.append(fac[i - 1] * i % self.mod) +            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod) +        return fac, facinv + +    def make_modinv_list(self, n): +        # 0からnまでのmod逆元のリストを返す O(n) +        modinv = [0] * (n + 1) +        modinv[1] = 1 +        for i in range(2, n + 1): +            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod +        return modinv + + +comb = Combination(10**6) -x, y = max(x, y), min(x, y) -if (x + y) % 3 or y * 2 < x: +if (x + y) % 3 or max(x, y) > min(x, y) * 2: -n = (x + y) // 3 + 1 -k = x - n + 2 - - -def cmd(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 - - -a = cmd(n - 1, k - 1) % mod -print(a) +n = (x + y) // 3 +c = comb(n, x - n) +print(c)