import sys



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



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



MOD = 10**9 + 7



MAX = max(x,y)

MIN = min(x,y)



if (2*MAX - MIN) % 3 != 0 or MAX / MIN > 2:

	print((0))

	sys.exit()



c1 = (2*MAX - MIN) // 3

c2 = MAX - 2*c1



c1 %= MOD

c2 %= MOD



ans = cmb(c1 + c2 , c1)

print((ans%MOD))

import math

import sys



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])

			result %= MOD



	return result



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



min_xy = min(x,y)

max_xy = max(x,y)



MOD = 10**9+7



if max_xy / min_xy == 2.0:

	print((1))

	sys.exit()

if max_xy / min_xy > 2.0:

	print((0))

	sys.exit()

if max_xy == min_xy and max_xy % 3 != 0:

	print((0))

	sys.exit()

if max_xy == min_xy and max_xy % 3 == 0:

	print((cmb(2 * max_xy//3, max_xy//3)))

	sys.exit()



for i in range(min_xy//3+1):

	if (max_xy-3*i) / (min_xy-3*i) == 2.0:

		print((cmb(2*i + (min_xy-3*i),i)%MOD))

		sys.exit()



print((0))



import sys


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


x, y = list(map(int, input().split()))
MOD = 10**9 + 7
MAX = max(x, y)
MIN = min(x, y)
if (2 * MAX - MIN) % 3 != 0 or MAX / MIN > 2:
    print((0))
    sys.exit()
c1 = (2 * MAX - MIN) // 3
c2 = MAX - 2 * c1
c1 %= MOD
c2 %= MOD
ans = cmb(c1 + c2, c1)
print((ans % MOD))

import math
import sys


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])
            result %= MOD
    return result


x, y = list(map(int, input().split()))
min_xy = min(x, y)
max_xy = max(x, y)
MOD = 10**9 + 7
if max_xy / min_xy == 2.0:
    print((1))
    sys.exit()
if max_xy / min_xy > 2.0:
    print((0))
    sys.exit()
if max_xy == min_xy and max_xy % 3 != 0:
    print((0))
    sys.exit()
if max_xy == min_xy and max_xy % 3 == 0:
    print((cmb(2 * max_xy // 3, max_xy // 3)))
    sys.exit()
for i in range(min_xy // 3 + 1):
    if (max_xy - 3 * i) / (min_xy - 3 * i) == 2.0:
        print((cmb(2 * i + (min_xy - 3 * i), i) % MOD))
        sys.exit()
print((0))

+import math +            result %= MOD +min_xy = min(x, y) +max_xy = max(x, y) -MAX = max(x, y) -MIN = min(x, y) -if (2 * MAX - MIN) % 3 != 0 or MAX / MIN > 2: +if max_xy / min_xy == 2.0: +    print((1)) +    sys.exit() +if max_xy / min_xy > 2.0: -c1 = (2 * MAX - MIN) // 3 -c2 = MAX - 2 * c1 -c1 %= MOD -c2 %= MOD -ans = cmb(c1 + c2, c1) -print((ans % MOD)) +if max_xy == min_xy and max_xy % 3 != 0: +    print((0)) +    sys.exit() +if max_xy == min_xy and max_xy % 3 == 0: +    print((cmb(2 * max_xy // 3, max_xy // 3))) +    sys.exit() +for i in range(min_xy // 3 + 1): +    if (max_xy - 3 * i) / (min_xy - 3 * i) == 2.0: +        print((cmb(2 * i + (min_xy - 3 * i), i) % MOD)) +        sys.exit() +print((0))