class Combination:

    def __init__(self, n, mod):

        self.mod = mod



        # self.fac[i] ≡ i! (factorial:階乗)

        l = [1]

        num = 1

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

            num *= i

            num %= mod

            l.append(num)

        self.fac = l.copy()



        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)

        num = pow(num, mod-2, mod)

        l = [1 for i in range(n+1)]

        l[n] = num

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

            num *= i + 1

            num %= mod

            l[i] = num

        self.rec = l.copy()



    # comb(n, r) ≡ nCr

    def comb(self, n, r):

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



mod = 10**9 + 7

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



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

    print((0))

    exit()

if y < x/2 or 2*x < y:

    print((0))

    exit()



n = (x + y) // 3

r = x - n

c = Combination(n, mod)

print((c.comb(n, r)))
class Factorials:

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

        self.mod = mod



        # self.fac[i] ≡ i! (factorial:階乗)

        self.fac = [1] * (n+1)

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

            self.fac[i] = self.fac[i-1] * i % mod



        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)

        self.rec = [1] * (n+1)

        self.rec[n] = pow(self.fac[n], mod-2, mod)

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

            self.rec[i] = self.rec[i+1] * (i+1) % mod



    # comb(n, r) ≡ nCr

    def comb(self, n, r):

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



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



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

    print((0))

    exit()

if y < x/2 or 2*x < y:

    print((0))

    exit()



n = (x + y) // 3

r = x - n

c = Factorials(n)

print((c.comb(n, r)))

class Combination:
    def __init__(self, n, mod):
        self.mod = mod
        # self.fac[i] ≡ i! (factorial:階乗)
        l = [1]
        num = 1
        for i in range(1, n + 1):
            num *= i
            num %= mod
            l.append(num)
        self.fac = l.copy()
        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        num = pow(num, mod - 2, mod)
        l = [1 for i in range(n + 1)]
        l[n] = num
        for i in range(n - 1, 0, -1):
            num *= i + 1
            num %= mod
            l[i] = num
        self.rec = l.copy()

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod


mod = 10**9 + 7
x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
    print((0))
    exit()
if y < x / 2 or 2 * x < y:
    print((0))
    exit()
n = (x + y) // 3
r = x - n
c = Combination(n, mod)
print((c.comb(n, r)))

class Factorials:
    def __init__(self, n=10**6, mod=10**9 + 7):
        self.mod = mod
        # self.fac[i] ≡ i! (factorial:階乗)
        self.fac = [1] * (n + 1)
        for i in range(2, n + 1):
            self.fac[i] = self.fac[i - 1] * i % mod
        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        self.rec = [1] * (n + 1)
        self.rec[n] = pow(self.fac[n], mod - 2, mod)
        for i in range(n - 1, 1, -1):
            self.rec[i] = self.rec[i + 1] * (i + 1) % mod

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod


x, y = list(map(int, input().split()))
if (x + y) % 3 != 0:
    print((0))
    exit()
if y < x / 2 or 2 * x < y:
    print((0))
    exit()
n = (x + y) // 3
r = x - n
c = Factorials(n)
print((c.comb(n, r)))

-class Combination: -    def __init__(self, n, mod): +class Factorials: +    def __init__(self, n=10**6, mod=10**9 + 7): -        l = [1] -        num = 1 -        for i in range(1, n + 1): -            num *= i -            num %= mod -            l.append(num) -        self.fac = l.copy() +        self.fac = [1] * (n + 1) +        for i in range(2, n + 1): +            self.fac[i] = self.fac[i - 1] * i % mod -        num = pow(num, mod - 2, mod) -        l = [1 for i in range(n + 1)] -        l[n] = num -        for i in range(n - 1, 0, -1): -            num *= i + 1 -            num %= mod -            l[i] = num -        self.rec = l.copy() +        self.rec = [1] * (n + 1) +        self.rec[n] = pow(self.fac[n], mod - 2, mod) +        for i in range(n - 1, 1, -1): +            self.rec[i] = self.rec[i + 1] * (i + 1) % mod -mod = 10**9 + 7 -c = Combination(n, mod) +c = Factorials(n)