AtCoder Beginner Contest 145 - Knight

There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.

-----Constraints-----
 - 1 \leq X \leq 10^6
 - 1 \leq Y \leq 10^6
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
X Y

-----Output-----
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.

-----Sample Input-----
3 3

-----Sample Output-----
2

There are two ways: (0,0) \to (1,2) \to (3,3) and (0,0) \to (2,1) \to (3,3).

Difficulty: MEDIUM

Starter code:

Solutions:
(X, Y) = map(int, input().split())
c1 = 2 * Y - X
rest = c1 % 3
c1 = c1 // 3
if rest != 0 or X - c1 < 0 or Y - 2 * c1 < 0 or (c1 < 0):
	print(0)
else:
	c2 = Y - 2 * c1
	c3 = c1 + c2 + 1
	mod = 10 ** 9 + 7
	c4 = min(c1, c2)
	x = 1
	y = 1
	for i in range(1, c4 + 1):
		x = x * (c3 - i) % mod
		y = y * i % mod
	result = x * pow(y, mod - 2, mod) % mod
	print(result)


(X, Y) = map(int, input().split())
MOD = 10 ** 9 + 7
FAC = [1]
INV = [1]
for i in range(1, X + Y + 1):
	FAC.append(FAC[i - 1] * i % MOD)
	INV.append(pow(FAC[-1], MOD - 2, MOD))

def nCr(n, r):
	return FAC[n] * INV[n - r] * INV[r]
a = (2 * X - Y) / 3
b = (2 * Y - X) / 3
if a >= 0 and b >= 0 and a.is_integer() and b.is_integer():
	print(nCr(int(a) + int(b), min(int(a), int(b))) % MOD)
else:
	print(0)


def calccombi(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
(x, y) = map(int, input().split())
if (x + y) % 3 != 0 or 2 * y < x or 2 * x < y:
	print(0)
else:
	MOD = 1000000007
	n = (2 * y - x) // 3
	m = (2 * x - y) // 3
	fac = [0] * (n + m + 1)
	finv = [0] * (n + m + 1)
	inv = [0] * (n + m + 1)
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, n + m + 1):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	print(calccombi(n + m, n))


mod = 10 ** 9 + 7
(x, y) = [int(i) for i in input().split()]
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
	print(0)
	exit()
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a < 0 or b < 0:
	print(0)
	exit()

def mygcd(a_b, b, mod):
	b = min(a_b, b)
	cnt = 1
	for i in range(b):
		cnt = cnt * (a_b - i) * pow(i + 1, mod - 2, mod) % mod
	return cnt
print(mygcd(a + b, b, mod))


p = 1000000007
(X, Y) = list(map(int, input().split()))
if (X + Y) % 3 != 0:
	print(0)
	return
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
if a < 0 or b < 0:
	print(0)
	return
n = a + b
fac = [0] * (n + 1)
fac[0] = 1
for i in range(n):
	fac[i + 1] = fac[i] * (i + 1) % p

def mcomb(n, k):
	if n == 0 and k == 0:
		return 1
	if n < k or k < 0:
		return 0
	return fac[n] * pow(fac[n - k], p - 2, p) * pow(fac[k], p - 2, p) % p
print(mcomb(n, a))


def nCk(n, k):
	if n < k or (n < 0 or k < 0):
		return 0
	(num, denum) = (1, 1)
	for i in range(k):
		num = num * (n - i) % mod
		denum = denum * (i + 1) % mod
	return num * pow(denum, mod - 2, mod) % mod
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
n = (y - 0.5 * x) / 1.5
if int(n) != n:
	print(0)
else:
	m = (y + x) // 3
	l = int(n)
	print(nCk(m, l))


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
import math
a = (2 * y - x) // 3
b = (2 * x - y) // 3
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0 or a < 0 or (b < 0):
	print(0)
else:
	L = [1] * (a + b + 1)
	for i in range(1, a + b + 1):
		L[i] = L[i - 1] * i
		L[i] = L[i] % mod
	p = pow(L[a], mod - 2, mod)
	q = pow(L[b], mod - 2, mod)
	ans = L[a + b] * p * q % mod
	print(ans)


M = 10 ** 9 + 7
(x, y) = map(int, input().split())
(d, m) = divmod(x + y, 3)
if m or y > 2 * x or x > 2 * y:
	print(0)
	exit()
x -= d
y -= d
s = t = 1
for i in range(min(x, y)):
	s = s * (x + y - i) % M
	t = t * (i + 1) % M
print(s * pow(t, M - 2, M) % M)


m = 10 ** 9 + 7

def cmb(x, y):
	r = 1
	for i in range(1, y + 1):
		r = r * (x - i + 1) * pow(i, m - 2, m) % m
	return r
(x, y) = map(int, input().split())
a = (2 * x - y) / 3
b = (2 * y - x) / 3
if (x + y) % 3 == 0 and a >= 0 and (b >= 0):
	print(cmb(int((x + y) / 3), int(a)))
else:
	print(0)


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

def nCr(n, r, mod=10 ** 9 + 7):
	r = min(r, n - r)
	a = b = 1
	for i in range(1, r + 1):
		a = a * n % mod
		b = b * i % mod
		n -= 1
	return a * pow(b, mod - 2, mod) % mod
z = x + y
if z % 3 != 0 or x - z // 3 < 0 or y - z // 3 < 0:
	print(0)
else:
	z //= 3
	print(nCr(z, min(x, y) - z))


(X, Y) = map(int, input().split())

def comb(n, k, mod=10 ** 9 + 7):
	ret = 1
	for i in range(1, k + 1):
		ret = ret * (n - i + 1) % mod
		ret = ret * pow(i, mod - 2, mod) % mod
	return ret
a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a != int(a) or b != int(b) or a < 0 or (b < 0):
	print(0)
else:
	print(comb(int(a + b), int(a)))


(x, y) = map(int, input().split())
if (2 * x - y) % 3 != 0 or (x - 2 * y) % 3 != 0:
	print(0)
	exit()
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a < 0 or b < 0:
	print(0)
	exit()
mod = 10 ** 9 + 7

def comb(x, y):
	s = 1
	t = 1
	for i in range(1, y + 1):
		s = s * (x - i + 1) % mod
		t = t * i % mod
	return s * pow(t, mod - 2, mod) % mod
print(comb(a + b, min(a, b)))


import sys
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	return
cnt = (X + Y) // 3
diff = abs(X - Y)

def comb(n, m, mod=10 ** 9 + 7):
	if m < 0:
		return 0
	numerator = 1
	denominator = 1
	for i in range(1, m + 1):
		numerator = numerator * (n - i + 1) % mod
		denominator = denominator * i % mod
	d_inv = pow(denominator, mod - 2, mod)
	return numerator * d_inv % mod
print(comb(cnt, (2 * Y - X) // 3) % (10 ** 9 + 7))


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) = map(int, input().split())
MOD = 10 ** 9 + 7
n = (x + y) // 3
a = x - n
b = y - n
if (x + y) % 3 != 0 or a < 0 or b < 0:
	print(0)
else:
	a = x - n
	b = y - n
	print(cmb(a + b, b) % MOD)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
n_max = 10 ** 6 + 1
F = [0] * (n_max + 1)
F[0] = 1
for i in range(n_max):
	F[i + 1] = F[i] * (i + 1) % mod

def comb(x, y):
	return F[x] * pow(F[x - y], mod - 2, mod) * pow(F[y], mod - 2, mod) % mod
(a, b) = (2 * y - x, 2 * x - y)
if a < 0 or b < 0:
	print(0)
elif a % 3 != 0 or b % 3 != 0:
	print(0)
else:
	a //= 3
	b //= 3
	print(comb(a + b, a))


def comb(n, k, mod):
	x = y = 1
	for i in range(min(k, n - k)):
		x = x * (n - i) % mod
		y = y * (i + 1) % mod
	return x * pow(y, mod - 2, mod) % mod
(x, y) = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
if (x + y) % 3 == 0:
	a = (-x + 2 * y) // 3
	b = (2 * x - y) // 3
	if a >= 0 and b >= 0:
		ans = comb(a + b, a, mod)
print(ans)


from math import factorial as fac
(x, y) = map(int, input().split())
a = 2 * y - x
b = 2 * x - y
mod = 10 ** 9 + 7
if a >= 0 and b >= 0 and (a % 3 == 0) and (b % 3 == 0):
	a = a // 3
	b = b // 3
	a1 = 1
	a2 = 1
	n3 = 10 ** 9 + 7
	for i in range(a):
		a1 *= a + b - i
		a2 *= i + 1
		a1 %= n3
		a2 %= n3
	a2 = pow(a2, n3 - 2, n3)
	print(a1 * a2 % n3)
else:
	print(0)


def com(n, k):
	if k == 0:
		return 1
	s = n
	p = 10 ** 9 + 7
	inv = [0, 1]
	for c in range(2, k + 1):
		inv.append(-(p // c) * inv[p % c] % p)
		s = s * (n + 1 - c) % p * inv[c] % p
	return s
(x, y) = map(int, input().split())
if (x + y) % 3 != 0 or 2 * y < x or 2 * x < y:
	print(0)
else:
	r = min(2 * y - x, 2 * x - y) // 3
	print(com((x + y) // 3, r))


def mod_inv(a, m):
	return pow(a, m - 2, m)
(X, Y) = map(int, input().split())
MOD = 10 ** 9 + 7
if (X + Y) % 3:
	print(0)
	exit()
n = (X + Y) // 3
(nx, ny) = (X - n, Y - n)
if nx < 0 or ny < 0:
	print(0)
	exit()
ans = 1
for i in range(nx + 1, nx + ny + 1):
	ans = ans * i % MOD
for i in range(1, ny + 1):
	ans = ans * mod_inv(i, MOD) % MOD
print(ans)


import math

def inv(a, mod=10 ** 9 + 7):
	return pow(a, mod - 2, mod)
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
reuslt = 0
if (x + y) % 3 == 0:
	n = (2 * x - y) // 3
	m = (2 * y - x) // 3
	r = min(n, m)
	result = 1
	if n < 0 or m < 0:
		print(0)
		exit()
	for i in range(r):
		result = result * (n + m - i) * inv(i + 1, mod) % mod
else:
	result = 0
print(result)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0 and (2 * x - y >= 0) and (2 * y - x >= 0):
	u = (2 * x - y) // 3
	v = (2 * y - x) // 3
	n = u + v
	x = 1
	y = 1
	for i in range(u):
		x = x * (n - i) % mod
		y = y * (i + 1) % mod
	print(x * pow(y, mod - 2, mod) % mod)
else:
	print(0)


MOD = 10 ** 9 + 7
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	exit()
N = (X + Y) // 3
X -= N
Y -= N
if X < 0 or Y < 0:
	print(0)
	exit()
si = 1
bo = 1
for i in range(N):
	si = si * (i + 1) % MOD
for i in range(min(X, Y)):
	bo = bo * (i + 1) % MOD
for i in range(N - min(X, Y)):
	bo = bo * (i + 1) % MOD
print(si * pow(bo, MOD - 2, MOD) % MOD)


(X, Y) = map(int, input().split())
total = (X + Y) / 3
k = (2 * X - Y) // 3
if total == int(total) and k >= 0:
	total = (X + Y) // 3
	mod = 10 ** 9 + 7
	modinv_table = [-1] * (k + 1)
	for i in range(1, k + 1):
		modinv_table[i] = pow(i, -1, mod)

	def binomial_coefficients(n, k):
		ans = 1
		for i in range(k):
			ans *= n - i
			ans *= modinv_table[i + 1]
			ans %= mod
		return ans
	print(binomial_coefficients(total, k))
else:
	print(0)


(x, y) = list(map(int, input().split()))
if (x + y) % 3 != 0:
	print(0)
	return
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a < 0 or b < 0:
	print(0)
	return
MOD = 10 ** 9 + 7

def fact(x):
	f = 1
	for i in range(2, x + 1):
		f *= i
		f %= MOD
	return f

def fact_inv(x):
	return pow(fact(x), MOD - 2, MOD)
ans = fact(a + b) * fact_inv(a) * fact_inv(b) % MOD
print(ans)


p = 10 ** 9 + 7
(X, Y) = map(int, input().split())
if (X + Y) % 3 > 0:
	print(0)
	exit()
a = (2 * X - Y) // 3
b = (2 * Y - X) // 3
if a * b < 0:
	print(0)
	exit()
ab = a + b
ue = [1] * (ab + 1)
for i in range(1, ab + 1):
	ue[i] = ue[i - 1] * i % p
out = ue[-1] * pow(ue[a], p - 2, p) % p
out = out * pow(ue[b], p - 2, p) % p
print(out)


def com(n, r, m):
	f = [1, 1]
	for i in range(2, n + 1):
		f.append(f[i - 1] * i % m)
	return f[n] * pow(f[r] * f[n - r] % m, m - 2, m) % m
mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
z = (x + y) // 3
if (x + y) % 3 or abs(x - y) > z:
	ans = 0
else:
	ans = com(z, x - z, mod)
print(ans)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
N = 10 ** 6
fact = [1 for i in range(N + 1)]
for i in range(1, N):
	fact[i + 1] = fact[i] * (i + 1) % mod

def nCk(n, k):
	return fact[n] * pow(fact[n - k] * fact[k], mod - 2, mod)
ans = 0
if (2 * Y - X) % 3 == 0 and (2 * X - Y) % 3 == 0 and (2 * Y - X >= 0) and (2 * X - Y >= 0):
	cntx = (2 * Y - X) // 3
	cnty = (2 * X - Y) // 3
	ans = nCk(cntx + cnty, cntx) % mod
print(ans)


(x, y) = map(int, input().split())
n = 0
mod = 10 ** 9 + 7
ans = 0
if not (x + y) % 3:
	n = (x + y) // 3
	x -= n
	y -= n
	if not x < 0 or y < 0:
		ans = 1
		for i in range(x):
			ans = ans * (n - i) * pow(i + 1, mod - 2, mod) % mod
print(ans)


mod = 10 ** 9 + 7
(N, K) = list(map(int, input().split()))
if (N + K) % 3 == 0 and N * 2 >= K and (K * 2 >= N):
	A = max(N, K) - min(N, K)
	low = (min(N, K) - A) // 3
	all_pt = low * 2 + A
else:
	print(0)
	return
(up, down) = (1, 1)
for i in range(low):
	up = up * (all_pt - i) % mod
	down = down * (i + 1) % mod
base = pow(down, mod - 2, mod)
print(up * base % mod)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
m = int((2 * y - x) / 3)
n = int((2 * x - y) / 3)
f = [1]
for i in range(1, 10 ** 6):
	f.append(f[-1] * i % mod)
if (x + y) % 3 != 0 or min(m, n) < 0:
	print(0)
else:
	print(f[m + n] * pow(f[m], mod - 2, mod) * pow(f[n], mod - 2, mod) % mod)


class common_function:

	def __init__(self):
		self.sletter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
		self.bletter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

	def combi(self, n: int, k: int, MOD=pow(10, 9) + 7):
		k = min(k, n - k)
		numer = 1
		for i in range(n, n - k, -1):
			numer *= i
			numer %= MOD
		denom = 1
		for j in range(k, 0, -1):
			denom *= j
			denom %= MOD
		return numer * pow(denom, MOD - 2, MOD) % MOD

def main():
	common = common_function()
	(X, Y) = list(map(int, input().split()))
	if X <= 0 or Y <= 0 or (X + Y) % 3 != 0:
		print(0)
		return
	if Y > 2 * X or X > 2 * Y:
		print(0)
		return
	for i in range(X):
		two = i
		one = X - 2 * i
		if two + one * 2 == Y:
			break
	ans = common.combi(two + one, one)
	print(ans)

def __starting_point():
	main()
__starting_point()


(x, y) = map(int, input().split())
diff = abs(x - y)
ref = (min(x, y) - diff) // 3
total = ref * 2 + diff
mod = 10 ** 9 + 7
ans = 1
if (x + y) % 3 != 0 or ref < 0:
	print(0)
	return
for i in range(min(ref, total - ref)):
	ans = ans * (total - i) % mod
	ie = pow(i + 1, mod - 2, mod)
	ans = ans * ie % mod
print(ans)


(x, y) = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
if (x + y) % 3 == 0:
	m = (2 * y - x) // 3
	n = (2 * x - y) // 3
	if m >= 0 and n >= 0:
		fac = [1] * (m + n + 1)
		for i in range(2, m + n + 1):
			fac[i] = fac[i - 1] * i % mod
		ans = fac[m + n] * (pow(fac[m], mod - 2, mod) * pow(fac[n], mod - 2, mod) % mod) % mod
print(ans)


(X, Y) = sorted(list(map(int, input().split())))
if (X - abs(Y - X)) % 3 != 0 or X * 2 < Y:
	print(0)
	exit(0)
n = (X - abs(Y - X)) // 3
X = n + abs(Y - X)
Y = n
mod = 10 ** 9 + 7
a = 1
for i in range(1, X + Y + 1):
	a *= i
	a %= mod
b = 1
for i in range(1, X + 1):
	b *= i
	b %= mod
c = 1
for i in range(1, Y + 1):
	c *= i
	c %= mod
print(a * pow(b, -1, mod) * pow(c, -1, mod) % mod)


(x, y) = map(int, input().split())
a = (x + y) // 3
n = (2 * x - y) // 3
m = a - n
mod = 10 ** 9 + 7

def nCr(n, r, mod):
	r = min(r, n - r)
	numer = denom = 1
	for i in range(1, r + 1):
		numer = numer * (n + 1 - i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod - 2, mod) % mod
if n < 0 or m < 0 or (x + y) % 3 != 0:
	print(0)
	exit()
print(nCr(a, n, mod))


import sys
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	return
turn = (X + Y) // 3
X -= turn
Y -= turn
if X < 0 or Y < 0:
	print(0)
	return

def nCr(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
size = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, size + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
print(nCr(X + Y, X, mod))


(x, y) = map(int, input().split())
a = (2 * y - x) / 3
b = (2 * x - y) / 3
c = (x + y) / 3
mod = 10 ** 9 + 7
MOD = 10 ** 9 + 7

def comb(n, k):
	ret = 1
	for i in range(1, k + 1):
		ret = ret * (n - i + 1) % MOD
		ret = ret * pow(i, MOD - 2, MOD) % MOD
	return ret
if (x + y) % 3 != 0:
	print(0)
elif a < 0 or b < 0:
	print(0)
else:
	print(int(comb(int(c), int(a))))


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
f = [1]
for i in range(10 ** 6):
	f.append(f[-1] * (i + 1) % mod)

def nCr(n, r):
	return f[n] * pow(f[r], mod - 2, mod) * pow(f[n - r], mod - 2, mod) % mod
if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
	print(0)
	exit()
n = (x + y) // 3
r = n // 2 - abs(x - y) // 2
print(nCr(n, r))


(X, Y) = map(int, input().split())
MOD = 10 ** 9 + 7

def modpow(x, n):
	ret = 1
	while n > 0:
		if n & 1:
			ret = ret * x % MOD
		x = x * x % MOD
		n >>= 1
	return ret

def modinv(x):
	return modpow(x, MOD - 2)

def modf(x):
	ret = 1
	for i in range(2, x + 1):
		ret *= i
		ret %= MOD
	return ret
ans = 0
if (X + Y) % 3 == 0:
	m = (2 * X - Y) // 3
	n = (2 * Y - X) // 3
	if m >= 0 and n >= 0:
		ans = modf(m + n) * modinv(modf(n) * modf(m))
		ans %= MOD
print(ans)


mod = 10 ** 9 + 7
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	exit()
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
if a < 0 or b < 0:
	print(0)
	exit()
m = min(a, b)
ifact = 1
for i in range(2, m + 1):
	ifact = ifact * i % mod
ifact = pow(ifact, mod - 2, mod)
fact = 1
for i in range(a + b, a + b - m, -1):
	fact = fact * i % mod
print(fact * ifact % mod)


(x, y) = map(int, input().split())
n = x + y
if x / y > 2 or y / x > 2 or n % 3 != 0:
	print(0)
	exit()
n //= 3
r = min(x - n, y - n)
m = 10 ** 9 + 7
a = b = 1
for i in range(r):
	a = a * (n - i) % m
	b = b * (i + 1) % m
print(a * pow(b, m - 2, m) % m)


mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
	exit()
if x * 2 < y or y * 2 < x:
	print(0)
	exit()
z = (x + y) // 3
x -= z
y -= z
n = x + y
r = x
if x == 0 or y == 0:
	print(1)
	exit()
lst = [0] + [1]
for i in range(2, n + 10):
	lst.append(lst[-1] * i % mod)
xxx = lst[n]
xxx *= pow(lst[n - r], 10 ** 9 + 5, mod)
xxx %= mod
xxx *= pow(lst[r], 10 ** 9 + 5, mod)
xxx %= mod
print(xxx)


import math
(X, Y) = list(map(int, input().split()))

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
if (X + Y) % 3 != 0:
	print(0)
	return
s = (-X + 2 * Y) // 3
t = (-Y + 2 * X) // 3
ans = cmb(s + t, s, 10 ** 9 + 7)
print(ans)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
move = x + y
if move % 3 != 0:
	print(0)
	exit()
move //= 3
(x, y) = (x - move, y - move)
if x < 0 or y < 0:
	print(0)
	exit()
ans = 1
for i in range(min(x, y)):
	ans *= x + y - i
	ans *= pow(i + 1, mod - 2, mod)
	ans %= mod
print(ans)


def nCr(n, r):
	(num, den) = (1, 1)
	for i in range(n, n - r, -1):
		num = num * i % M
	for i in range(1, r + 1):
		den = den * i % M
	den_inv = pow(den, -1, M)
	return num * den_inv % M

def is_comb():
	a = 1 / 3 * (2 * X - Y)
	b = 1 / 3 * (-X + 2 * Y)
	if a >= 0 and b >= 0 and a.is_integer() and b.is_integer():
		return (int(a), int(b))
	return (0, 0)
M = 10 ** 9 + 7
(X, Y) = map(int, input().split())
(a, b) = is_comb()
if a == b == 0:
	print(0)
else:
	(n, r) = (a + b, a)
	print(nCr(n, r))


import math
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

def init(n):
	for i in range(2, n + 1):
		fac.append(fac[-1] * i % mod)
		inv.append(-inv[mod % i] * (mod // i) % mod)
		finv.append(finv[-1] * inv[-1] % mod)

def com(n, k, mod):
	if n < 0 or k < 0 or n < k:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod

def main():
	if (x + y) % 3:
		print(0)
		return
	else:
		n = (2 * y - x) // 3
		m = (2 * x - y) // 3
		if n < 0 or m < 0:
			print(0)
			return
		else:
			init(n + m)
			print(com(n + m, n, mod))
main()


def combination(N: int, R: int, MOD: int):
	if N - R < R:
		R = N - R
	if R == 0:
		return 1
	if R == 1:
		return N
	numerator = [N - R + r for r in range(1, R + 1)]
	denominator = [r for r in range(1, R + 1)]
	for p in range(2, R + 1):
		pivot = denominator[p - 1]
		if pivot <= 1:
			continue
		offset = (N - R) % p
		for r in range(p - 1, R, p):
			numerator[r - offset] /= pivot
			denominator[r] /= pivot
	result = 1
	for n in numerator:
		if n <= 1:
			continue
		result *= int(n)
		result %= MOD
	return result

def main():
	(X, Y) = list(map(int, input().split()))
	MOD = 10 ** 9 + 7
	n = (2 * Y - X) // 3
	m = (2 * X - Y) // 3
	if n < 0 or m < 0 or (X + Y) % 3:
		print(0)
	else:
		print(combination(n + m, n, MOD))

def __starting_point():
	main()
__starting_point()


from functools import reduce
(x, y) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def cmb(n, r, m):

	def mul(a, b):
		return a * b % m
	r = min(n - r, r)
	if r == 0:
		return 1
	over = reduce(mul, list(range(n, n - r, -1)))
	under = reduce(mul, list(range(1, r + 1)))
	return over * pow(under, m - 2, m) % m
r = abs(x - y)
l = (min(x, y) - r) // 3
r += l
if l * 2 + r * 1 in (x, y) and l >= 0:
	print(cmb(r + l, l, mod))
else:
	print(0)


(X, Y) = map(int, input().split())
if 2 * Y < X or 2 * X < Y:
	print(0)
	return
if not (X % 3 == 0 and Y % 3 == 0 or (X % 3 == 1 and Y % 3 == 2) or (X % 3 == 2 and Y % 3 == 1)):
	print(0)
	return
P = 10 ** 9 + 7
A = (2 * Y - X) // 3
B = (2 * X - Y) // 3
num = 1
for i in range(A + 1, A + B + 1):
	num = num * i % P
den = 1
for j in range(1, B + 1):
	den = den * j % P
den = pow(den, P - 2, P)
print(num * den % P)


(X, Y) = map(int, input().split())

def cnb(n, k, p):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	(c, d) = (1, 1)
	for i in range(n - k + 1, n + 1):
		c = c * i % p
	for i in range(1, k + 1):
		d = d * i % p
	return c * pow(d, p - 2, p) % p
p = 10 ** 9 + 7
ans = 0
if X > 2 * Y or Y > 2 * X:
	pass
elif (X + Y) % 3:
	pass
else:
	ans = cnb((X + Y) // 3, (2 * Y - X) // 3, p)
print(ans)


import sys
(x, y) = [int(x) for x in input().split()]
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
	print(0)
	sys.exit()
n = (2 * y - x) // 3
m = (2 * x - y) // 3
if n < 0 or m < 0:
	print(0)
	sys.exit()
a = 1
for i in range(m + 1, n + m + 1):
	a = a * i % mod
b = 1
for i in range(1, n + 1):
	b = b * i % mod
b = pow(b, mod - 2, mod)
print(a * b % mod)


def combination(n, r, mod=10 ** 9 + 7):
	r = min(r, n - r)
	(up, down) = (1, 1)
	for i in range(r):
		up = up * (n - i) % mod
		down = down * (i + 1) % mod
	return up * pow(down, mod - 2, mod) % mod
(x, y) = map(int, input().split())
(n, m) = ((2 * y - x) // 3, (2 * x - y) // 3)
if (x + y) % 3 != 0 or n < 0 or m < 0:
	print(0)
	exit()
print(combination(n + m, m))


def nCk(n, k, m=10 ** 9 + 7):
	a = b = 1
	for i in range(k):
		a = a * (n - i) % m
		b = b * (i + 1) % m
	return a * pow(b, m - 2, m) % m
(x, y) = map(int, input().split())
if (x + y) % 3 != 0 or min(x, y) * 2 < max(x, y):
	ans = 0
else:
	n = (x + y) // 3 + 1
	k = x - (n - 1) + 1
	ans = nCk(n - 1, k - 1)
print(ans)


mod = 10 ** 9 + 7

def nCk(n, k, p):
	global mod
	k = min(k, n - k)
	X = 1
	for i in range(k):
		X = X * (n - i) % p
		X = X * pow(i + 1, p - 2, p) % p
	return X
(X, Y) = map(int, input().split())
ans = 0
if X <= 2 * Y and Y <= 2 * X and ((X + Y) % 3 == 0):
	a = (2 * Y - X) // 3
	b = (2 * X - Y) // 3
	ans = nCk(a + b, b, mod)
print(ans)


(X, Y) = map(int, input().split())
M = 10 ** 9 + 7
if X % 3 == Y % 3 == 1 or X % 3 == Y % 3 == 2:
	Answer = 0
else:
	dif = abs(X - Y)
	W = (min(X, Y) - dif) // 3
	X1 = W + dif
	Y1 = W
	Answer = 1
	N = X1 + Y1
	for i in range(1, X1 + 1):
		Answer = Answer * N * pow(i, -1, M) % M
		N -= 1
	for j in range(1, Y1 + 1):
		Answer = Answer * N * pow(j, -1, M) % M
		N -= 1
print(Answer)


def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
(X, Y) = list(map(int, input().split()))
if (2 * Y - X) % 3 == 0:
	if (2 * X - Y) % 3 == 0:
		a = (2 * Y - X) // 3
		b = (2 * X - Y) // 3
	else:
		print(0)
		return
else:
	print(0)
	return
print(cmb(a + b, a, p))


(X, Y) = list(map(int, input().split()))
import sys
if (2 * Y - X) % 3 != 0 or (2 * X - Y) % 3 != 0:
	print(0)
	return
if 2 * Y - X < 0 or 2 * X - Y < 0:
	print(0)
	return
x = (2 * Y - X) // 3
y = (2 * X - Y) // 3
fac = [0 for i in range(x + y + 1)]
inv = [0 for i in range(x + y + 1)]
finv = [0 for i in range(x + y + 1)]
p = 1000000007
fac[0] = fac[1] = 1
inv[1] = 1
finv[0] = finv[1] = 1
for i in range(2, x + y + 1):
	fac[i] = fac[i - 1] * i % p
	inv[i] = -(p // i) * inv[p % i] % p
	finv[i] = finv[i - 1] * inv[i] % p
print(fac[x + y] * finv[x] % p * finv[y] % p)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a != (2 * x - y) / 3 or b != (2 * y - x) / 3:
	print(0)
elif a < 0 or b < 0:
	print(0)
else:
	max = a + b + 10
	fac = [0] * max
	finv = [0] * max
	inv = [0] * max
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, max):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod
	ans = fac[a + b] * (finv[a] * finv[b] % mod) % mod
	print(ans)


(x, y) = map(int, input().split())
if (2 * y - x) % 3 != 0 or (2 * x - y) % 3 != 0 or 2 * x - y < 0 or (2 * y - x < 0):
	ans = 0
else:
	a = (2 * y - x) // 3
	b = (2 * x - y) // 3
	n = a + b
	ans = 1
	for i in range(min(a, b)):
		ans *= n - i
		ans %= 10 ** 9 + 7
		ans *= pow(i + 1, 10 ** 9 + 5, 10 ** 9 + 7)
print(ans % (10 ** 9 + 7))


import sys
(X, Y) = map(int, input().split())
(A, mod) = divmod(2 * Y - X, 3)
if mod != 0 or A < 0:
	print(0)
	sys.exit()
(B, mod) = divmod(2 * X - Y, 3)
if mod != 0 or B < 0:
	print(0)
	sys.exit()
mod = 10 ** 9 + 7
a = A + B
b = min(A, B)
ans = 1
for i in range(b):
	ans *= a - i
	ans %= mod
	ans *= pow(i + 1, mod - 2, mod)
ans %= mod
print(ans)


import sys
(x, y) = map(int, input().split())
if (x + y) % 3:
	print(0)
	return
n = y - (x + y) // 3
m = x - (x + y) // 3

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = m + n
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
print(cmb(m + n, n, mod))


def getComb(n, k, MOD):
	if n < k:
		return 0
	if n - k < k:
		k = n - k
	comb = 1
	for x in range(n - k + 1, n + 1):
		comb = comb * x % MOD
	d = 1
	for x in range(1, k + 1):
		d = d * x % MOD
	comb *= pow(d, MOD - 2, MOD)
	return comb % MOD
(x, y) = map(int, input().split())
if (x + y) % 3 == 0:
	n = (x + y) // 3
	if x < n or y < n:
		ans = 0
	else:
		MOD = 10 ** 9 + 7
		ans = getComb(n, x - n, MOD)
else:
	ans = 0
print(ans)


(X, Y) = map(int, input().split())

def cmb(n, k):
	(x, y) = (1, 1)
	for i in range(k):
		x = x * (n - i) % mod
		y = y * (k - i) % mod
	return x * pow(y, mod - 2, mod) % mod
if (X + Y) % 3 != 0:
	print(0)
else:
	m = (2 * X - Y) // 3
	n = (2 * Y - X) // 3
	if n < 0 or m < 0:
		print(0)
	else:
		mod = 10 ** 9 + 7
		ans = cmb(n + m, min(n, m))
		print(ans)


MOD = 10 ** 9 + 7
(x, y) = list(map(int, input().split()))
a = 2 * y - x
b = 2 * x - y
fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)

def com_init():
	fac_l[1] = 1
	inv_l[0] = 1
	inv_l[1] = 1
	finv_l[0] = 1
	finv_l[1] = 1
	for i in range(2, a + b + 1):
		fac_l[i] = fac_l[i - 1] * i % MOD
		inv_l[i] = MOD - inv_l[MOD % i] * int(MOD / i) % MOD
		finv_l[i] = finv_l[i - 1] * inv_l[i] % MOD

def ncr(n, r):
	return fac_l[n] * (finv_l[r] * finv_l[n - r]) % MOD % MOD
if a % 3 != 0 or b % 3 != 0 or a < 0 or (b < 0):
	print('0')
else:
	a = int(a / 3)
	b = int(b / 3)
	com_init()
	print(ncr(a + b, a))


import sys
mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
a = (-x + 2 * y) // 3
b = (2 * x - y) // 3
if a < 0 or b < 0:
	print(0)
	sys.exit()
f = [1]
for i in range(1, a + b + 1):
	f.append(f[-1] * i % mod)
if a + 2 * b == x and 2 * a + b == y:
	print(f[a + b] * pow(f[a] * f[b], mod - 2, mod) % mod)
else:
	print(0)


(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	exit()
mod = 10 ** 9 + 7
N = (X + Y) // 3
K = (2 * Y - X) // 3
if not 0 <= K <= N:
	print(0)
	exit()
ans = 1
for i in range(1, K + 1):
	ans *= (N + 1 - i) * pow(i, mod - 2, mod)
	ans %= mod
print(ans)


import math
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0 or 2 * x - y < 0 or (2 * y - x < 0):
	print(0)
else:
	b = (2 * x - y) // 3
	a = x - 2 * b
	c = min(a, b)
	s = 1
	t = 1
	for i in range(c):
		s = s * (a + b - i) % mod
		t = t * (c - i) % mod
	print(s * pow(t, mod - 2, mod) % mod)


(X, Y) = map(int, input().split())
import math
mod = 10 ** 9 + 7

def comb(n, r, mod):
	ans = 1
	for i in range(r):
		ans *= n - i
		ans %= mod
	for i in range(1, r + 1):
		ans *= pow(i, mod - 2, mod)
		ans %= mod
	return ans
if (2 * X - Y) % 3 != 0 or 2 * X - Y < 0 or -1 * X + 2 * Y < 0:
	print(0)
else:
	p = (2 * X - Y) // 3
	q = (-1 * X + 2 * Y) // 3
	print(comb(p + q, p, mod))


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
N = (X + Y) // 3
M = (N + X - Y) // 2
if (X + Y) % 3 != 0 or M < 0 or N < M:
	print(0)
else:
	ans = 1
	for m in range(1, M + 1):
		ans *= (N - M + m) * pow(m, mod - 2, mod)
		ans %= mod
	print(ans)


(x, y) = map(int, input().split())
a = max(x, y)
b = min(x, y)
s = a - b
A = a - s - s
if A >= 0 and A % 3 == 0:
	t = A // 3
	p = t + s
	q = t
	ans = 1
	for i in range(q):
		ans = ans * (p + q - i) * pow(i + 1, 10 ** 9 + 5, 10 ** 9 + 7)
		ans = ans % (10 ** 9 + 7)
	print(ans)
else:
	print(0)


mod = int(1000000000.0 + 7)
(x, y) = map(int, input().split())
if 2 * x < y or 2 * y < x or (2 * x - y) % 3 or (2 * y - x) % 3:
	print(0)
else:
	(x, y) = ((2 * x - y) // 3, (2 * y - x) // 3)
	fac = [0 for i in range(x + y + 1)]
	fac[0] = 1
	for i in range(1, x + y + 1):
		fac[i] = fac[i - 1] * i % mod
	ans = fac[x + y] * pow(fac[x], mod - 2, mod) * pow(fac[y], mod - 2, mod) % mod
	print(ans)


(X, Y) = [int(x) for x in input().split()]
M = 10 ** 9 + 7
if (X + Y) % 3:
	print(0)
else:
	x = X - (X + Y) // 3
	y = Y - (X + Y) // 3
	if x < 0 or y < 0:
		print(0)
	else:
		ans = 1
		for j in range(y):
			ans *= (x + j + 1) * pow(j + 1, -1, M)
			ans %= M
		print(ans)


(X, Y) = list(map(int, input().split()))
a = (2 * X - Y) // 3
b = (2 * Y - X) // 3
if not (2 * a + b == X and a + 2 * b == Y and (a >= 0) and (b >= 0)):
	print(0)
	exit()
C = 10 ** 9 + 7
A = 1
B = 1
D = 1
for i in range(a):
	A *= i + 1
	A = A % C
for j in range(b):
	B *= j + 1
	B = B % C
for k in range(a + b):
	D *= k + 1
	D = D % C
D *= pow(A, C - 2, C)
D *= pow(B, C - 2, C)
print(D % C)


def f(x, r, p):
	ans = 1
	for i in range(x, x - r, -1):
		ans = ans * i % p
	return ans

def comb(x, r, p):
	r = min(r, x - r)
	return f(x, r, p) * pow(f(r, r, p), p - 2, p) % p
(x, y) = map(int, input().split())
if (2 * y - x) % 3 != 0 or (2 * x - y) % 3 != 0 or 2 * y - x < 0 or (2 * x - y < 0):
	print(0)
	exit()
s = (2 * x - y) // 3
t = (2 * y - x) // 3
mod = 10 ** 9 + 7
print(comb(s + t, s, mod))


def com(n, r, mod):
	k = min(r, n - r)
	C = 1
	for i in range(1, k + 1):
		C = C * (n + 1 - i) * pow(i, mod - 2, mod) % mod
	return C
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
n = (2 * y - x) // 3 if (2 * y - x) % 3 == 0 else -1
m = (2 * x - y) // 3 if (2 * x - y) % 3 == 0 else -1
if n >= 0 and m >= 0:
	print(com(n + m, n, mod))
else:
	print(0)


MOD = 10 ** 9 + 7
(x, y) = list(map(int, input().split()))
if (x + y) % 3 != 0:
	print(0)
	return

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % MOD
N = (x + y) // 3
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % MOD)
	inverse.append(-inverse[MOD % i] * (MOD // i) % MOD)
	g2.append(g2[-1] * inverse[-1] % MOD)
print(cmb(N, x - N))


MOD = 10 ** 9 + 7
MAX = 1000010
finv = [0] * MAX
inv = [0] * MAX

def COMinit():
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, MAX):
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD

def COM(n, k):
	res = 1
	for i in range(k):
		res = res * (n - i) % MOD
	return res * finv[k] % MOD
(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	ans = 0
else:
	(s, t) = ((-x + 2 * y) // 3, (2 * x - y) // 3)
	if s < 0 or t < 0:
		ans = 0
	else:
		COMinit()
		ans = COM(s + t, s)
print(ans)


(x, y) = sorted(map(int, input().split()))
z = x + y

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
print((z % 3 < 1) * cmb(z // 3, (2 * x - y) // 3, 10 ** 9 + 7))


(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
else:

	def C(n, r, mod):
		num = 1
		den = 1
		for i in range(r):
			num *= n - i
			num %= mod
			den *= i + 1
			den %= mod
		return num * pow(den, mod - 2, mod) % mod
	mod = 10 ** 9 + 7
	minimun = (X + Y) / 3
	if X >= minimun and Y >= minimun:
		X -= minimun
		Y -= minimun
		print(C(int(X + Y), int(X), mod))
	else:
		print(0)


(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
	exit()
a = (2 * y - x) // 3
b = (2 * x - y) // 3
if a < 0 or b < 0:
	print(0)
	exit()
mod = 10 ** 9 + 7
F = [1]
for i in range(1, a + b + 1):
	tmp = F[-1] * i
	F.append(tmp % mod)
Ia = pow(F[a], mod - 2, mod)
Ib = pow(F[b], mod - 2, mod)
ans = F[a + b] * Ia * Ib % mod
print(ans)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
	print(0)
	exit()
if x * 2 < y or y * 2 < x:
	print(0)
	exit()
t = (x + y) // 3
f = [1]
for i in range(1, 10 ** 6 + 7):
	f.append(f[-1] * i % mod)

def comb(a, b, m):
	return f[a] * pow(f[b], m - 2, m) * pow(f[a - b], m - 2, m) % m
print(comb(t, x - t, mod))


def comb_mod(n, r, m):
	ans = 1
	for i in range(1, r + 1):
		ans *= (n - i + 1) % m
		ans *= pow(i, m - 2, m) % m
		ans = ans % m
	return ans
(x, y) = map(int, input().split())
m = 10 ** 9 + 7
if x > 2 * y or 2 * x < y or (x + y) % 3 != 0:
	ans = 0
else:
	n = (x + y) // 3
	r = x - n
	ans = comb_mod(n, r, m)
print(ans)


import math
(X, Y) = list(map(int, input().split()))
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	print(0)
	exit()
n = (2 * X - Y) // 3
m = (2 * Y - X) // 3
if n < 0 or m < 0:
	print(0)
	exit()
tmp = 1
for i in range(n, n + m):
	tmp = tmp * (i + 1) % mod
bunsi = tmp
bunbo = 1
tmp = 1
for i in range(m):
	tmp = tmp * (i + 1) % mod
bunbo = pow(tmp, mod - 2, mod)
ans = bunsi * bunbo
print(ans % mod)


(x, y) = list(map(int, input().split()))
mod = pow(10, 9) + 7

def comint(n, mod):
	fac = [0 for _ in range(n)]
	finv = [0 for _ in range(n)]
	inv = [0 for _ in range(n)]
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, n):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod
	return (fac, finv)

def com(n, k, fac, finv, mod):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
if (x + y) % 3 != 0:
	print(0)
else:
	n = (x + y) // 3
	a = x - n
	b = y - n
	(fac, finv) = comint(a + b + 1, mod)
	print(com(a + b, a, fac, finv, mod))


(x, y) = map(int, input().split())
m = 10 ** 9 + 7
n = (x + y) // 3
c = 0
if x * 0.5 <= y <= 2 * x and (x + y) % 3 == 0:
	r = x - n
	c = 1
	for i in range(1, r + 1):
		c *= (n - i + 1) % m
		c *= pow(i, m - 2, m)
		c = c % m
else:
	ans = 0
print(c)


mod = int(1000000000.0) + 7
f = [1]
for i in range(1, int(1000000.0)):
	f.append(i * f[i - 1] % mod)

def comb(a, b):
	return f[a] % mod * pow(f[b], mod - 2, mod) % mod * pow(f[a - b], mod - 2, mod) % mod
(x, y) = map(int, input().split())
if (2 * y - x) % 3 or (2 * x - y) % 3:
	print(0)
	return
else:
	(a, b) = ((2 * y - x) // 3, (2 * x - y) // 3)
	if not (a >= 0 and b >= 0):
		print(0)
		return
	print(comb(a + b, b))


import numpy as np
(x, y) = list(map(int, input().split()))

def comb(n, r, mod):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
if (x + y) % 3 != 0:
	print(0)
else:
	(mod, N) = (10 ** 9 + 7, 10 ** 6)
	(g1, g2, inverse) = ([1, 1], [1, 1], [0, 1])
	for i in range(2, N + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	a = np.array([[1, 2], [2, 1]])
	b = np.array([x, y])
	(x0, y0) = np.linalg.solve(a, b)
	print(comb(int(x0 + y0), int(x0), mod))


fact = [None] * 1000001
inv = [0, 1]
finv = [1, 1]
(x, y) = map(int, input().split())
total = x + y
ans = 0
MOD = 10 ** 9 + 7
if total % 3 == 0 and max(x, y) <= min(x, y) * 2:
	fact[1] = 1
	for i in range(2, 1000001):
		fact[i] = fact[i - 1] * i % MOD
		inv.append(-inv[MOD % i] * (MOD // i) % MOD)
		finv.append(finv[-1] * inv[-1] % MOD)
	step = int(total / 3)
	sa = abs(x - y)
	a = int((step - sa) / 2)
	b = int((step + sa) / 2)
	ans = fact[step] * finv[a] * finv[b] % MOD
print(ans)


(x, y) = list(map(int, input().split()))
a = -1
p = 10 ** 9 + 7
for i in range(x // 2 + 1):
	if i + 2 * (x - 2 * i) == y:
		a = i
		break
if a == -1:
	print(0)
	return
elif a == 0:
	print(1)
	return
else:
	gyaku = [0, 1]
	for i in range(2, a + 1):
		gyaku.append(p // i * -gyaku[p % i] % p)
	com = [1]
	for i in range(1, a + 1):
		com.append(com[-1] * gyaku[i] * (x - a + 1 - i) % p)
print(com[-1])


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
flflag = True
if (2 * x - y) % 3 == 0:
	a = (2 * x - y) // 3
else:
	flflag = False
if (2 * y - x) % 3 == 0:
	b = (2 * y - x) // 3
else:
	flflag = False

def kaijou(n):
	ans = 1
	for i in range(1, n + 1):
		ans *= i % mod
		ans %= mod
	return ans
if flflag:
	N = a + b
	R = min(a, b)
ans = 0
if flflag == True and a >= 0 and (b >= 0):
	ans = kaijou(N)
	ans1 = kaijou(N - R) * kaijou(R) % mod
	print(ans * pow(ans1, mod - 2, mod) % mod)
else:
	print(0)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7

def cmb(n, r, mod):
	r = min(r, n - r)
	x = 1
	y = 1
	for i in range(r):
		x = x * (n - i) % mod
		y = y * (i + 1) % mod
	y = pow(y, mod - 2, mod)
	return x * y % mod
if (x + y) % 3:
	print(0)
	exit()
n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
	print(0)
	exit()
print(cmb(x + y, x, mod))


import sys
(X, Y) = map(int, input().split())
MOD = 1000000007
if (2 * X - Y) % 3 != 0:
	print(0)
	sys.exit()
A = int((2 * X - Y) / 3)
B = int(X - 2 * A)
if A < 0 or B < 0:
	print(0)
	sys.exit()
ans = 1
inv = 1
for i in range(B):
	ans = ans * (A + B - i) % MOD
	inv = inv * (i + 1) % MOD
ans = ans * pow(inv, MOD - 2, MOD) % MOD
print(ans)


def nCr(n, r):
	(dividend, divisor) = (1, 1)
	for i in range(r):
		dividend *= n - i
		divisor *= 1 + i
		dividend %= MOD
		divisor %= MOD
	return dividend * pow(divisor, MOD - 2, MOD) % MOD
(X, Y) = map(int, input().split())
INF = 10 ** 15
MOD = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	print(0)
	exit()
n = (-X + 2 * Y) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
	print(0)
	exit()
print(nCr(n + m, n))


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
cnt = 0
for p in range(X // 2 + 1):
	if Y == 2 * X - 3 * p:
		A = 1
		for a in range(p):
			A *= X - p - a
			A %= mod
		B = 1
		for b in range(1, p + 1):
			B *= b
			B %= mod
		cnt += A * pow(B, mod - 2, mod) % mod
print(cnt)


(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
	exit()
if x < y:
	(x, y) = (y, x)
if 2 * y < x:
	print(0)
	exit()
mod = 10 ** 9 + 7
a = (2 * y - x) // 3
b = (2 * x - y) // 3
mx = 10 ** 6
k = [1] * (mx + 1)

def inv(n):
	return pow(n, mod - 2, mod)
for i in range(mx):
	k[i + 1] = k[i] * (i + 1) % mod
ans = k[a + b] * inv(k[a]) * inv(k[b]) % mod
print(ans)


(x, y) = map(int, input().split())
m = (-x + 2 * y) // 3
n = (2 * x - y) // 3
mod = 10 ** 9 + 7

def c(n, r):
	(p, q) = (1, 1)
	for i in range(r):
		p = p * (n - i) % mod
		q = q * (i + 1) % mod
	return p * pow(q, mod - 2, mod) % mod
if (x + y) % 3 != 0 or m * n < 0:
	print(0)
else:
	print(c(m + n, n))


fact = [1 for _ in range(1000000)]
inv = [1 for _ in range(1000000)]
fact_inv = [1 for _ in range(1000000)]
P = 10 ** 9 + 7
for i in range(2, 1000000):
	fact[i] = fact[i - 1] * i % P
	inv[i] = P - inv[P % i] * (P // i) % P
	fact_inv[i] = fact_inv[i - 1] * inv[i] % P
(X, Y) = map(int, input().split())
res = 0
if (X + Y) % 3 == 0:
	a = (-X + 2 * Y) // 3
	b = (2 * X - Y) // 3
	if a >= 0 and b >= 0:
		res = fact[a + b] * (fact_inv[a] * fact_inv[b] % P) % P
print(res)


mod = 7 + 10 ** 9

def ncr(n, c, mod):
	x = 1
	y = 1
	for i in range(n - c + 1, n + 1):
		x = x * i % mod
	for j in range(1, c + 1):
		y = y * j % mod
	return x * pow(y, mod - 2, mod) % mod
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	exit()
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
	print(0)
	exit()
ans = ncr(n + m, n, mod)
print(ans)


(X, Y) = list(map(int, input().split()))
if (X + Y) % 3 != 0 or X * 2 < Y or Y * 2 < X:
	print(0)
	return
n = (2 * X - Y) // 3
m = (2 * Y - X) // 3
P = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % P)
	inv.append(-inv[P % i] * (P // i) % P)
	factinv.append(factinv[-1] * inv[-1] % P)
print(fact[n + m] * factinv[n] * factinv[m] % P)


M = 10 ** 9 + 7
(x, y) = map(int, input().split())
r = 0
if (x + y) % 3 == 0:
	(a, b) = ((2 * y - x) // 3, (2 * x - y) // 3)
	if a >= 0 <= b:
		f = [1]
		for i in range(1, a + b + 1):
			f.append(f[-1] * i % M)
		r = f[a + b] * pow(f[a] * f[b], M - 2, M) % M
print(r)


MOD = 10 ** 9 + 7
(X, Y) = map(int, input().split())
if (X + Y) % 3 or Y > 2 * X or Y < X // 2:
	print(0)
	exit()
n = (X + Y) // 3
r = X - (X + Y) // 3
(num, den) = (1, 1)
if n - r < r:
	r = n - r
for i in range(1, r + 1):
	num *= n - i + 1
	num %= MOD
	den *= i
	den %= MOD
print(num * pow(den, MOD - 2, MOD) % MOD)


import math
(X, Y) = map(int, input().split())
if X > Y:
	(X, Y) = (Y, X)
if (2 * X - Y) % 3 != 0 or 2 * X - Y < 0:
	print(0)
	exit()
A = (2 * X - Y) // 3
B = Y - X + A
N = A + B
nu = 1
de = 1
for i in range(B + 1, N + 1):
	nu = nu * i % (10 ** 9 + 7)
for i in range(1, A + 1):
	de = de * i % (10 ** 9 + 7)
print(nu * pow(de, -1, 10 ** 9 + 7) % (10 ** 9 + 7))


def main():
	(x, y) = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	if 0 > 2 * y - x or (2 * y - x) % 3 != 0:
		print(0)
		return
	if 0 > 2 * x - y or (2 * x - y) % 3 != 0:
		print(0)
		return
	n = (2 * y - x) // 3
	m = (2 * x - y) // 3

	def cmb(n, r, mod):
		if r < 0 or r > n:
			return 0
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	N = 10 ** 6
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, N + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	print(cmb(n + m, n, mod))

def __starting_point():
	main()
__starting_point()


mod = int(1000000000.0 + 7)
(X, Y) = map(int, input().split())
if 2 * X - Y < 0 or -X + 2 * Y < 0 or (2 * X - Y) % 3 or (-X + 2 * Y) % 3:
	print(0)
	exit()
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if x > y:
	tmp = x
	x = y
	y = tmp
ans = 1
for i in range(1, x + 1):
	ans *= i + y
	ans %= mod
	ans *= pow(i, mod - 2, mod)
	ans %= mod
print(ans)


(x, y) = map(int, input().split())
import math
ans = 0

def conbi(n, r, mod):
	ue = 1
	for i in range(n - r + 1, n + 1):
		ue *= i
		ue %= mod
	sita = 1
	for i in range(1, r + 1):
		sita *= i
		sita %= mod
	sita = pow(sita, mod - 2, mod)
	return ue * sita % mod
for a in range(x + 1):
	b = (x - a) / 2
	if b - int(b) == 0:
		b = int(b)
		if y == 2 * a + b:
			ans += conbi(a + b, a, 10 ** 9 + 7)
print(ans)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7

def comb(n, r):
	if 2 * r > n:
		return comb(n, n - r)
	return fac[n] * inv[r] * inv[n - r] % mod
if (x + y) % 3 != 0:
	print(0)
	return
n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
	print(0)
	return
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % mod
inv[n] = pow(fac[n], mod - 2, mod)
for i in range(n - 1, 1, -1):
	inv[i] = inv[i + 1] * (i + 1) % mod
print(comb(x + y, x) % mod)


def CombiMod(n, r, mod):
	if n < r:
		return 0
	if n - r < r:
		r = n - r
	comb = 1
	for x in range(n - r + 1, n + 1):
		comb = comb * x % mod
	d = 1
	for x in range(1, r + 1):
		d = d * x % mod
	comb *= pow(d, mod - 2, mod)
	return comb % mod
(x, y) = map(int, input().split())
if (x + y) % 3:
	ans = 0
else:
	n = (x + y) // 3
	x -= n
	y -= n
	if x < 0 or y < 0:
		ans = 0
	else:
		ans = CombiMod(x + y, y, 10 ** 9 + 7)
print(ans)


(X, Y) = list(map(int, input().split()))
M = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	ans = 0
else:
	p = (2 * Y - X) // 3
	q = (2 * X - Y) // 3
	if p < 0 or q < 0:
		ans = 0
	else:
		a = b = 1
		pq = min(p, q)
		for i in range(0, pq):
			a *= p + q - i
			b *= pq - i
			a %= M
			b %= M
		ans = a * pow(b, M - 2, M) % M
print(ans)


(X, Y) = map(int, input().split())
if 2 * Y < X or 2 * X < Y or (not (2 * Y - X) % 3 == 0) or (not (2 * X - Y) % 3 == 0):
	print(0)
else:
	A = (2 * Y - X) // 3
	B = (2 * X - Y) // 3
	k = 1
	for i in range(A + 1, A + B + 1):
		k = k * i % 1000000007
	j = 1
	for i in range(1, B + 1):
		j = j * i % 1000000007
	l = pow(j, 1000000005, 1000000007) * k % 1000000007
	print(l)


(x, y) = map(int, input().split())
z = (x + y) // 3
n = abs(y - x)
r = (z - n) // 2

def mod(x):
	return x % (10 ** 9 + 7)
a = 1
for i in range(r, z):
	a = mod(a * (i + 1))
b = 1
for i in range(z - r):
	b = mod(b * (i + 1))
if (x + y) % 3 != 0:
	a = 0
c = pow(b, 10 ** 9 + 5, 10 ** 9 + 7)
print(mod(a * c))


(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0 or X + Y == 0:
	print(0)
	exit()
n = int((2 * Y - X) / 3)
m = int((2 * X - Y) / 3)
if n < 0 or m < 0:
	print(0)
	exit()
mod = 10 ** 9 + 7

def comb(n, r, mod):
	x = y = 1
	for i in range(r):
		x *= n
		y *= r
		x %= mod
		y %= mod
		n -= 1
		r -= 1
	return x * pow(y, mod - 2, mod) % mod
print(comb(n + m, n, mod))


from functools import reduce
(x, y) = list(map(int, input().split()))
mod = 10 ** 9 + 7
if (2 * y - x) % 3 != 0 or (2 * x - y) % 3 != 0:
	print('0')
	return
(a, b) = ((2 * y - x) // 3, (2 * x - y) // 3)
r = min(a, b)
if r == 0:
	print('1')
elif r < 0:
	print('0')
else:
	numerator = reduce(lambda x, y: x * y % mod, range(a + b - r + 1, a + b + 1))
	denominator = reduce(lambda x, y: x * y % mod, range(1, r + 1))
	print(numerator * pow(denominator, mod - 2, mod) % mod)


def modinv2(a, m):
	return pow(a, m - 2, m)
(X, Y) = map(int, input().split())
(X, Y) = (min(X, Y), max(X, Y))
if (X + Y) % 3 != 0 or X * 2 - Y < 0:
	ans = 0
else:
	a = (2 * X - Y) // 3
	b = (2 * Y - X) // 3
	m = 10 ** 9 + 7
	ans = 1
	for i in range(b + 1, a + b + 1):
		ans = ans * i % m
	for i in range(1, a + 1):
		ans = ans * modinv2(i, m) % m
print(ans)


(X, Y) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def permute(n, m):
	ret = 1
	while n >= m:
		ret *= n
		n -= 1
	return ret

def count_combinations(n, m):
	fact = [1] * (n + 1)
	inv = [i for i in range(n + 1)]
	fact_inv = [1] * (n + 1)
	for i in range(2, n + 1):
		fact[i] = fact[i - 1] * i % mod
		inv[i] = -inv[mod % i] * (mod // i) % mod
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod
	ret = fact[n] * fact_inv[m] * fact_inv[n - m] % mod
	return ret

def count_comb2(n, m):
	fact = [1, 1]
	factinv = [1, 1]
	inv = [0, 1]
	for i in range(2, n + 1):
		fact.append(fact[-1] * i % mod)
		inv.append(-inv[mod % i] * (mod // i) % mod)
		factinv.append(factinv[-1] * inv[-1] % mod)
	if m < 0 or n < m:
		return 0
	m = min(m, n - m)
	return fact[n] * factinv[m] * factinv[n - m] % mod
ret = 0
if (X + Y) % 3 == 0:
	m = (2 * X - Y) // 3
	n = (2 * Y - X) // 3
	if m >= 0 and n >= 0:
		ret = count_combinations(n + m, m)
print(ret)


(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
else:
	mod = int(1000000000.0 + 7)
	n = (2 * y - x) // 3
	m = y - 2 * n
	if n < 0 or m < 0:
		print(0)
	else:
		f = [1]
		for i in range(1, n + m + 1):
			f.append(f[-1] * i % mod)
		ans = f[n + m] * pow(f[n] * f[m], mod - 2, mod) % mod
		print(ans)


(x, y) = map(int, input().split())
if 2 * y < x:
	print(0)
elif y > 2 * x:
	print(0)
elif (x + y) % 3 != 0:
	print(0)
else:
	p = 10 ** 9 + 7
	s = int((2 * x - y) / 3)
	t = int((2 * y - x) / 3)
	u = min(s, t)
	v = s + t
	inv = [0] * (u + 1)
	inv[0] = 0
	ans = 1
	for i in range(1, u + 1):
		inv[i] = pow(i, p - 2, p)
		ans = ans * (v - i + 1) * inv[i] % p
	print(ans)


mod = 10 ** 9 + 7

def cmb(n, r, mod):
	a = 1
	b = 1
	r = min(r, n - r)
	for i in range(r):
		a = a * (n - i) % mod
		b = b * (i + 1) % mod
	return a * pow(b, mod - 2, mod) % mod
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	ans = 0
else:
	n = (2 * X - Y) // 3
	m = (2 * Y - X) // 3
	if n < 0 or m < 0:
		ans = 0
	else:
		ans = cmb(n + m, m, mod)
print(ans)


import sys
p = 10 ** 9 + 7
(x, y) = map(int, input().split())
if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
	print(0)
	sys.exit()
a = (-x + 2 * y) // 3
b = (2 * x - y) // 3
A = 1
for i in range(1, a + 1):
	A = A * i
	A = A % p
B = 1
for i in range(1, b + 1):
	B = B * i
	B = B % p
AB = 1
for i in range(1, a + b + 1):
	AB = AB * i
	AB = AB % p
C = AB * pow(A, p - 2, p) * pow(B, p - 2, p) % p
print(C)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	print(0)
	exit()
if X * 2 < Y or Y * 2 < X:
	print(0)
	exit()
t = (X + Y) // 3
f = [1]
for i in range(1, t + 100):
	f.append(f[-1] * i % mod)

def comb(a, b, m):
	return f[a] * pow(f[b], m - 2, m) * pow(f[a - b], m - 2, m) % m
print(comb(t, X - t, mod))


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if 2 * y - x < 0 or 2 * x - y < 0:
	print(0)
	return
if (2 * y - x) % 3 != 0 or (2 * x - y) % 3 != 0:
	print(0)
	return
xc = (2 * y - x) // 3
yc = (2 * x - y) // 3
p = 1
k = 1
for i in range(1, xc + 1):
	p *= yc + i
	k *= i
	p %= mod
	k %= mod
ans = p * pow(k, mod - 2, mod) % mod
print(ans)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7

def p(m, n):
	a = 1
	for i in range(n):
		a = a * (m - i) % mod
	return a

def c(m, n):
	return p(m, n) * pow(p(n, n), mod - 2, mod) % mod
if (X + Y) % 3 == 0 and Y // 2 <= X <= Y * 2:
	print(c((X + Y) // 3, (2 * X - Y) // 3))
else:
	print(0)


mod = 10 ** 9 + 7
(x, y) = map(int, input().split())
if (x + y) % 3 != 0 or x * 2 < y or y * 2 < x:
	print(0)
	exit()
l = [1]
for i in range(1, (x + y) // 3 + 100):
	l.append(l[-1] * i % mod)

def comb(n, r, m):
	return l[n] * pow(l[r], m - 2, m) * pow(l[n - r], m - 2, m) % m
(a, b) = (y - (x + y) // 3, x - (x + y) // 3)
print(comb(a + b, a, mod) % mod)


kMod = 1000000007
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	return
offset = (X + Y) // 3
(X, Y) = (X - offset, Y - offset)
if X < 0 or Y < 0:
	print(0)
	return
(X, Y) = (max(X, Y), min(X, Y))
ans = 1
for i in range(X + 1, X + Y + 1):
	ans *= i
	ans %= kMod
for i in range(2, Y + 1):
	ans *= pow(i, kMod - 2, kMod)
	ans %= kMod
print(ans)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
a = (-x + 2 * y) // 3
b = (2 * x - y) // 3
n = a + b

def fact(x, p):
	ret = 1
	for i in range(1, x + 1):
		ret *= i
		ret %= p
	return ret
if a + 2 * b == x and b + 2 * a == y and (a >= 0) and (b >= 0):
	ans = fact(n, mod) * pow(fact(b, mod), mod - 2, mod) * pow(fact(a, mod), mod - 2, mod)
	print(ans % mod)
else:
	print('0')


(x, y) = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, r, mod):
	n1 = n + 1
	numer = denom = 1
	for i in range(1, r + 1):
		numer = numer * (n1 - i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod - 2, mod) % mod
if (x + y) % 3 != 0 or (2 * x - y) // 3 < 0 or (2 * y - x) // 3 < 0:
	print(0)
else:
	n = (2 * x - y) // 3
	m = (2 * y - x) // 3
	print(comb(n + m, min(n, m), MOD))


(x, y) = map(int, input().split())
if (2 * y - x) % 3 == 0 and (2 * x - y) % 3 == 0 and (2 * y - x >= 0) and (2 * x - y >= 0):
	a = (2 * y - x) // 3
	b = (2 * x - y) // 3
	numerator = 1
	denominator = 1
	for i in range(a):
		numerator = numerator * (a + b - i) % (10 ** 9 + 7)
		denominator = denominator * (a - i) % (10 ** 9 + 7)
	print(numerator * pow(denominator, 10 ** 9 + 5, 10 ** 9 + 7) % (10 ** 9 + 7))
else:
	print(0)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7

def comb(a, b):
	comb = 1
	chld = 1
	for i in range(b):
		comb = comb * (a - i) % mod
		chld = chld * (b - i) % mod
	return comb * pow(chld, mod - 2, mod) % mod
if (x + y) % 3 != 0:
	print(0)
else:
	nm = (x + y) // 3
	n = y - nm
	m = x - nm
	if n >= 0 and m >= 0:
		print(comb(n + m, m))
	else:
		print(0)


class Factorial:

	def __init__(self, max_fact, mod):
		f = [1] * (max_fact + 1)
		for idx in range(2, max_fact + 1):
			f[idx] = f[idx - 1] * idx
			f[idx] %= mod
		if mod > max_fact:
			fi = [pow(f[-1], mod - 2, mod)]
			for idx in range(max_fact, 0, -1):
				fi += [fi[-1] * idx % mod]
			fi = fi[::-1]
		else:
			fi = [pow(n, mod - 2, mod) for n in f]
		self.mod = mod
		self.f = f
		self.fi = fi

	def factorial(self, n):
		return self.f[n]

	def factorial_inverse(self, n):
		return self.fi[n]

	def combination(self, n, r):
		f = self.f
		fi = self.fi
		return f[n] * fi[r] * fi[n - r] % self.mod

	def permutation(self, n, r):
		return self.f[n] * self.fi[n - r] % self.mod

	def homogeneous_product(self, n, r):
		f = self.f
		fi = self.fi
		return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod
max_fact = 10 ** 6
mod = 10 ** 9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product
(X, Y) = [int(_) for _ in input().split()]
i = X - (X + Y) // 3
j = Y - (X + Y) // 3
if (X + Y) % 3 or i < 0 or j < 0:
	ans = 0
else:
	ans = comb(i + j, i)
print(ans)


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

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
mod = 10 ** 9 + 7
N = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, N + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)

def knight(x, y):
	s = (0, 0)
	if x == y == 0:
		return 0
	if (x + y) % 3:
		return 0
	if (2 * y - x) % 3 or (2 * x - y) % 3:
		return 0
	(a, b) = ((2 * y - x) // 3, (2 * x - y) // 3)
	n = (x + y) // 3
	r = min(a, b)
	if a < 0 or b < 0:
		return 0
	return cmb(n, r, mod)
print(knight(x, y))


from math import factorial
(x, y) = list(map(int, input().split()))
mod = 10 ** 9 + 7
if (2 * y - x) % 3 != 0 or (2 * x - y) % 3 != 0:
	print(0)
	return
s = (2 * x - y) // 3
t = (2 * y - x) // 3

def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
p = mod
N = 10 ** 6 + 1
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
ans = cmb(s + t, s, p)
print(ans)


from functools import lru_cache
MOD = 10 ** 9 + 7
(x, y) = map(int, input().split())
summ = x + y

@lru_cache(maxsize=None)
def inv(n):
	return pow(n, -1, MOD)
if summ % 3 == 0 and summ // 3 <= x and (summ // 3 <= y):
	mn = min(x, y)
	n = mn - summ // 3
	a = summ // 3
	b = 1
	ans = 1
	for i in range(n):
		ans *= a
		ans *= inv(b)
		ans %= MOD
		a -= 1
		b += 1
	print(ans)
else:
	print(0)


(i, j) = map(int, input().split())
if (i + j) % 3 != 0 or max(i, j) / min(i, j) > 2:
	print(0)
else:
	TW = (i + j) // 3
	W = (TW - (i - j)) // 2

	def mod_cmb(n, r, mod=10 ** 9 + 7):
		r = min(r, n - r)
		res = 1
		for i in range(r):
			res = res * (n - i) % mod * pow(i + 1, mod - 2, mod) % mod
		return res
	print(mod_cmb(TW, W))


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7

def nCk(n, k, p):
	fact = [1, 1] + [0] * (n - 1)
	inv = [0, 1] + [0] * (n - 1)
	factinv = [1, 1] + [0] * (n - 1)
	for i in range(2, n + 1):
		fact[i] = i * fact[i - 1] % p
		inv[i] = -inv[p % i] * (p // i) % p
		factinv[i] = factinv[i - 1] * inv[i] % p
	return fact[n] * factinv[k] * factinv[n - k] % p
ans = 0
if (X + Y) % 3 == 0 and X <= 2 * Y and (Y <= 2 * X):
	a = (2 * Y - X) // 3
	b = (2 * X - Y) // 3
	ans = nCk(a + b, a, mod)
print(ans)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	print(0)
	exit()
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
	print(0)
	exit()
ans = 1
for i in range(1, n + 1):
	ans *= (n + m + 1 - i) * pow(i, mod - 2, mod)
	ans %= mod
print(ans)


def comb(n, k):
	s = 1
	r = min(k, n - k)
	p = 10 ** 9 + 7
	for c in range(r):
		s = s * (n - c) * pow(c + 1, p - 2, p) % p
	return s
(x, y) = map(int, input().split())
if (x + y) % 3:
	print(0)
else:
	m = y - (x + y) // 3
	n = x - (x + y) // 3
	if m < 0 or n < 0:
		print(0)
	else:
		print(comb(m + n, m))


def ncr(n, r):
	(num, den) = (1, 1)
	if n - r < r:
		r = n - r
	for i in range(1, r + 1):
		num *= n - i + 1
		num %= MOD
		den *= i
		den %= MOD
	return num * pow(den, MOD - 2, MOD) % MOD
MOD = 10 ** 9 + 7
(X, Y) = map(int, input().split())
Z = X + Y
if Z % 3 or Y > 2 * X or Y < X // 2:
	print(0)
else:
	print(ncr(Z // 3, X - Z // 3))


import sys
(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a < 0 or b < 0 or (X + Y) % 3 != 0:
	print(0)
	sys.exit()
a = int(a)
b = int(b)
N = a + b
f = [1]
for i in range(1, a + b + 1):
	f.append(f[-1] * i % mod)
ans = f[a + b] * (pow(f[a], mod - 2, mod) * pow(f[b], mod - 2, mod) % mod) % mod
print(ans)


(X, Y) = [int(_) for _ in input().split()]
p = 10 ** 9 + 7
N = 670000
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
	inv.append((p - inv[p % i] * (p // i)) % p)
	factinv.append(factinv[-1] * inv[-1] % p)

def combination(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p

def solve(X, Y):
	if (X + Y) % 3 != 0:
		return 0
	Z = (X + Y) // 3
	x = (Z + X - Y) // 2
	return combination(Z, x, p)
print(solve(X, Y))


def framod(x, p=10 ** 9 + 7):
	a = 1
	for i in range(1, x + 1):
		a = a * i % p
	return a
(X, Y) = map(int, input().split())
p = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	print(0)
else:
	a = (2 * X - Y) // 3
	b = (2 * Y - X) // 3
	t = a + b
	if a < 0 or b < 0:
		print(0)
	else:
		S = framod(t)
		T = pow(framod(a), p - 2, p)
		U = pow(framod(b), p - 2, p)
		print(S * T % p * U % p)


MOD = 10 ** 9 + 7

def choose(n, r):
	num = 1
	den = 1
	for i in range(r):
		num *= n - i
		num %= MOD
	for i in range(r):
		den *= i + 1
		den %= MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def solve(x, y):
	if (x + y) % 3 != 0:
		return 0
	k = (x + y) // 3
	if x < k or y < k:
		return 0
	return choose(k, min(y - k, x - k))
print(solve(*map(int, input().split())))


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7

def comb(n, r, mod):
	X = 1
	Y = 1
	for i in range(1, r + 1):
		X = X * (n - i + 1) % mod
		Y = Y * i % mod
	return X * pow(Y, mod - 2, mod) % mod
if (X + Y) % 3 != 0:
	print(0)
elif X < (X + Y) // 3 or Y < (X + Y) // 3:
	print(0)
else:
	i = X - (X + Y) // 3
	print(comb((X + Y) // 3, i, mod))


def nCr(n_, r_, m_):
	c = min(r_, n_ - r_)
	bunshi = 1
	bunbo = 1
	for i in range(1, c + 1):
		bunshi = bunshi * (n_ + 1 - i) % m_
		bunbo = bunbo * i % m_
	return bunshi * pow(bunbo, m_ - 2, m_) % m_
(x, y) = map(int, input().split())
s = max(x, y)
t = min(x, y)
u = 2 * t - s
if u % 3 != 0 or u < 0:
	print(0)
else:
	a = u // 3
	b = a + s - t
	ans = nCr(a + b, b, 10 ** 9 + 7)
	print(ans)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if x // 2 + 2 * (x % 2) <= y <= 2 * x and (2 * x - y) % 3 == 0:
	t = (2 * x - y) // 3
	maxt = max(t, x - t)
	a = 1
	b = 1
	ans = 1
	for i in range(1, maxt + 1):
		a = a * (maxt - i + 1) % mod
		b = b * i % mod
		if i == t or i == x - t:
			ans *= a * pow(b, mod - 2, mod) % mod
	print(ans)
else:
	print(0)


def C(n, r, m):
	(num, den) = (1, 1)
	for i in range(1, r + 1):
		num = num * (n - i + 1) % m
		den = den * i % m
	return num * pow(den, m - 2, m) % m
(x, y) = map(int, input().split())
m = (2 * x - y) // 3
n = (-x + 2 * y) // 3
if (x + y) % 3 != 0 or m < 0 or n < 0:
	print(0)
else:
	print(C(n + m, n, 10 ** 9 + 7))


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7

def binomial(n, k):
	x = 1
	y = 1
	for i in range(k):
		x = x * (n - i) % mod
		y = y * (i + 1) % mod
	return x * pow(y, mod - 2, mod) % mod
if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
	a = (2 * X - Y) // 3
	b = (2 * Y - X) // 3
	if a < 0 or b < 0:
		print(0)
	else:
		print(binomial(a + b, a) % mod)
else:
	print(0)


MOD = 10 ** 9 + 7
(X, Y) = map(int, input().split())
m = 2 * X - Y
n = 2 * Y - X
if m % 3 or n % 3 or m < 0 or (n < 0):
	print(0)
	quit()
m //= 3
n //= 3
factorial = [1] * (n + m + 1)
for i in range(n + m):
	factorial[i + 1] = factorial[i] * (i + 1) % MOD
print(factorial[m + n] * pow(factorial[m], MOD - 2, MOD) * pow(factorial[n], MOD - 2, MOD) % MOD)


M = 10 ** 9 + 7
(x, y) = map(int, input().split())
ans = 0
if (x + y) % 3 == 0:
	a = (2 * y - x) // 3
	b = (2 * x - y) // 3
	if a >= 0 and b >= 0:
		(f1, f2) = (1, 1)
		for i in range(a + 1, a + b + 1):
			f1 *= i
			f1 %= M
		for i in range(1, b + 1):
			f2 *= i
			f2 %= M
		ans = f1 * pow(f2, M - 2, M)
print(ans % M)


import sys
(x, y) = map(int, input().split())
T = x + y
MOD = 10 ** 9 + 7

def nCmMOD(A, B, Mod):
	(num, den) = (1, 1)
	for i in range(B):
		num *= A - i
		den *= i + 1
		num %= Mod
		den %= Mod
	return num * pow(den, Mod - 2, Mod) % Mod
if T % 3 != 0 or y / x < 1 / 2 or y / x > 2:
	print(0)
	sys.exit()
else:
	n = (2 * y - x) // 3
	m = (2 * x - y) // 3
	l = min(n, m)
	print(nCmMOD(n + m, l, MOD))


(X, Y) = map(int, input().split())
mod = pow(10, 9) + 7
(n, m) = (-1, -1)
for i in range(X + 1):
	if X - i == 2 * (Y - 2 * i):
		(n, m) = (i, Y - 2 * i)
if n == -1:
	print(0)
else:
	(a, b, m) = (1, 1, n + m)
	for i in range(1, n + 1):
		a = a * m % mod
		b = b * i % mod
		m -= 1
	b = pow(b, mod - 2, mod)
	print(a * b % mod)


import sys
MOD = 1000000007
(X, Y) = [int(x) for x in input().split()]

def mod_pow(x, n):
	ret = 1
	while n > 0:
		if n & 1:
			ret = ret * x % MOD
		x = x * x % MOD
		n >>= 1
	return ret
z = X + Y
if z % 3 != 0:
	print(0)
	return
n = z // 3
k = -1
for i in range(n, z - n + 1):
	if X == i or Y == i:
		k = z - n - i
		break
if k == -1:
	print(0)
	return
a = n
for i in range(n - 1, n - k, -1):
	a = a * i % MOD
b = k
for i in range(k - 1, 0, -1):
	b = b * i % MOD
ans = a * mod_pow(b, MOD - 2) % MOD
print(ans)


def cmbp(n, k):
	nCk = 1
	MOD = 10 ** 9 + 7
	for i in range(n - k + 1, n + 1):
		nCk *= i
		nCk %= MOD
	for i in range(1, k + 1):
		nCk *= pow(i, MOD - 2, MOD)
		nCk %= MOD
	return nCk
(x, y) = map(int, input().split())
if (x + y) % 3 == 0:
	n = int((2 * y - x) / 3)
	m = int((2 * x - y) / 3)
	if n >= 0 and m >= 0:
		print(cmbp(m + n, n))
	else:
		print(0)
else:
	print(0)


def ex_euclid(a, b):
	(x0, x1) = (1, 0)
	(y0, y1) = (0, 1)
	(z0, z1) = (a, b)
	while z1 != 0:
		q = z0 // z1
		(z0, z1) = (z1, z0 % z1)
		(x0, x1) = (x1, x0 - q * x1)
		(y0, y1) = (y1, y0 - q * y1)
	return (z0, x0, y0)

def mod_inv(a, n):
	(g, x, _) = ex_euclid(a, n)
	if g != 1:
		print('modular inverse does not exist')
	else:
		return x % n

def mod_factorial(x, modulo):
	ans = 1
	for i in range(1, x + 1):
		ans *= i
		ans %= modulo
	return ans
(X, Y) = map(int, input().split())
M = 10 ** 9 + 7
(a, b) = ((2 * X - Y) / 3, (2 * Y - X) / 3)
if a < 0 or b < 0:
	print(0)
elif a == 0 and b == 0:
	print(0)
elif a % 1 != 0 or b % 1 != 0:
	print(0)
else:
	(a, b) = (int(a), int(b))
	answer = 1
	answer *= mod_factorial(a + b, M)
	answer *= mod_inv(mod_factorial(a, M), M)
	answer %= M
	answer *= mod_inv(mod_factorial(b, M), M)
	answer %= M
	print(answer)


def main():
	(X, Y) = list(map(int, input().split()))
	if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
		a = (2 * X - Y) // 3
		b = (2 * Y - X) // 3
	else:
		print(0)
		return
	if a < 0 or b < 0:
		print(0)
		return
	print(comb_mod(a + b, a, 10 ** 9 + 7))

def comb_mod(n, k, p):

	def fact_mod(x, p):
		v = 1
		for i in range(1, x + 1):
			v *= i
			v %= p
		return v
	n_mod = fact_mod(n, p)
	k_mod = pow(fact_mod(k, p), p - 2, p)
	n_minus_k_mod = pow(fact_mod(n - k, p), p - 2, p)
	return n_mod * k_mod * n_minus_k_mod % p

def __starting_point():
	main()
__starting_point()


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7

def com(n, r):
	(p, q) = (1, 1)
	for i in range(r):
		p = p * (n - i) % mod
		q = q * (r - i) % mod
	return p * pow(q, mod - 2, mod) % mod
if (X + Y) % 3 != 0:
	print(0)
else:
	a = (2 * Y - X) // 3
	b = (X + Y) // 3 - a
	if a < 0 or b < 0:
		print(0)
	else:
		print(com(a + b, a))


(X, Y) = map(int, input().split())
MD = pow(10, 9) + 7

def choose(n, a):
	(x, y) = (1, 1)
	for i in range(a):
		x = x * (n - i) % MD
		y = y * (i + 1) % MD
	return x * pow(y, MD - 2, MD) % MD
a = (2 * Y - X) // 3
b = (Y - 2 * X) // -3
if a < 0 or b < 0 or (X + Y) % 3 != 0:
	print(0)
	import sys
	sys.exit()
print(choose(a + b, min(a, b)))


(x, y) = map(int, input().split())
mod = pow(10, 9) + 7
x_ = 2 * x - y
y_ = 2 * y - x
if x_ < 0 or y_ < 0 or x_ % 3 != 0 or (y_ % 3 != 0):
	print(0)
	exit()
x_ //= 3
y_ //= 3
n = x_ + y_
r = min(x_, y_)
(a, b) = (1, 1)
for i in range(r):
	a *= n - i
	a %= mod
	b *= i + 1
	b %= mod
c = a * pow(b, mod - 2, mod) % mod
print(c)


def solve():
	(x, y) = map(int, input().split())
	n = (2 * y - x) / 3
	m = (2 * x - y) / 3
	mod = 10 ** 9 + 7
	if n < 0 or m < 0 or (x + y) % 3 != 0:
		return 0
	cmb = 1
	n = int(n)
	m = int(m)
	cnt = 0
	for i in range(n):
		cnt += 1
		cmb *= n + m - i
		cmb *= pow(i + 1, mod - 2, mod)
		cmb %= mod
	return cmb
print(solve())


import sys
mod = 10 ** 9 + 7
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	sys.exit()
tot = (X + Y) // 3
x = X - tot
y = tot - x
if x < 0:
	print(0)
	sys.exit()
if x == 0 or y == 0:
	print(1)
	sys.exit()
ans = 1
for i in range(y + 1, tot + 1):
	ans *= i
	ans %= mod
for i in range(1, x + 1):
	ans *= pow(i, mod - 2, mod)
	ans %= mod
print(ans % mod)


MOD = 10 ** 9 + 7
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	exit()
a = (2 * X + -Y) // 3
b = (-X + 2 * Y) // 3
if a < 0 or b < 0:
	print(0)
	exit()
fac = [1, 1]
for i in range(2, a + b + 1):
	fac.append(fac[-1] * i % MOD)
print(fac[a + b] * pow(fac[a] * fac[b], MOD - 2, MOD) % MOD)


(X, Y) = map(int, input().split())
n = (2 * X - Y) // 3
m = (-X + 2 * Y) // 3
if n < 0 or m < 0 or (2 * X - Y) % 3 != 0 or ((-X + 2 * Y) % 3 != 0):
	print(0)
else:
	fac = [1, 1]
	finv = [1, 1]
	inv = [1, 1]
	MOD = 10 ** 9 + 7
	for i in range(2, n + m + 1):
		fac.append(fac[i - 1] * i % MOD)
		inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
		finv.append(finv[i - 1] * inv[i] % MOD)
	print(fac[n + m] * (finv[n] * finv[m] % MOD) % MOD)


MOD = 1000000007

def mod_inv(mod, a):
	(old_t, t) = (0, 1)
	(old_r, r) = (mod, a)
	while r != 0:
		quotient = old_r // r
		(old_r, r) = (r, old_r - quotient * r)
		(old_t, t) = (t, old_t - quotient * t)
	return old_t % mod

def combine(n, k, mod):
	if k > n // 2:
		k = n - k
	u = 1
	for i in range(n - k + 1, n + 1):
		u = u * i % mod
	v = 1
	for i in range(1, k + 1):
		v = v * i % mod
	return u * mod_inv(mod, v) % MOD

def main():
	(X, Y) = list(map(int, input().split()))
	m1 = X + Y
	if m1 % 3 == 0:
		m = m1 // 3
		if X < m or Y < m:
			print(0)
		else:
			print(combine(m, X - m, MOD))
	else:
		print(0)

def __starting_point():
	main()
__starting_point()


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

def nCk(n, k, mod=10 ** 9 + 7):
	ans = 1
	for i in range(1, k + 1):
		ans = ans * (n - i + 1) * pow(i, mod - 2, mod) % mod
	return ans
ans = 0
if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0 and (2 * y - x >= 0) and (2 * x - y >= 0):
	k = (2 * x - y) // 3
	l = (2 * y - x) // 3
	ans = nCk(k + l, min(k, l))
print(ans)


t = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7
X = t[0]
Y = t[1]
xy = 0
while X >= 0:
	if Y == 2 * X:
		break
	X -= 3
	Y -= 3
	xy += 1
if X < 0:
	print('0')
else:
	ans = 1
	for i in range(xy):
		ans = ans * (X + 2 * xy - i) * pow(i + 1, -1, mod) % mod
	print(ans)


(x, y) = map(int, input().split())
m = 10 ** 9 + 7
if (2 * x - y) % 3 == 0 and (2 * y - x) % 3 == 0 and (2 * x >= y) and (2 * y >= x):
	(a, b) = ((2 * x - y) // 3, (2 * y - x) // 3)
	c = min(a, b)
	p = 1
	for i in range(c):
		p = p * (a + b - i) * pow(i + 1, m - 2, m) % m
	print(p)
else:
	print(0)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7

def nCr(n, r, mod):
	r = min(r, n - r)
	number = denom = 1
	for i in range(1, r + 1):
		number = number * (n + 1 - i) % mod
		denom = denom * i % mod
	return number * pow(denom, mod - 2, mod) % mod
if (X + Y) % 3 != 0:
	print(0)
	exit()
n = (2 * X - Y) // 3
m = (X + Y) // 3 - n
if n < 0 or m < 0:
	print(0)
	exit()
print(nCr(n + m, min(n, m), mod))


inp = list(map(int, input().split()))
x = inp[0]
y = inp[1]
if (x + y) % 3 != 0:
	print(0)
else:
	flag = 0
	z = (x + y) // 3
	n = x - z
	m = y - z
	if m < 0 or n < 0:
		print(0)
		flag = 1
	else:
		arr = [1]
		v = pow(10, 9) + 7
		for i in range(1, m + n + 1):
			arr.append(arr[-1] * i % v)
		a = arr[m + n]
		b = arr[m] * arr[n] % v
		print(a * pow(b, v - 2, v) % v)


(X, Y) = map(int, input().split())
if (-X + 2 * Y) % 3 or (2 * X - Y) % 3 or -X + 2 * Y < 0 or (2 * X - Y < 0):
	print(0)
else:
	a = (-X + 2 * Y) // 3
	b = (2 * X - Y) // 3
	P = 10 ** 9 + 7
	fa = [1]
	for i in range(1, a + b + 100):
		fa.append(fa[-1] * i % P)
	print(fa[a + b] * pow(fa[a] * fa[b], P - 2, P) % P)


import sys
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.141592653589793

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return map(int, sys.stdin.readline().strip().split())

def read_ints2(x):
	return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())

def read_str_list():
	return list(sys.stdin.readline().strip().split())

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

def GCD(a: int, b: int) -> int:
	return b if a % b == 0 else GCD(b, a % b)

def LCM(a: int, b: int) -> int:
	return a * b // GCD(a, b)

class Combination:

	def __init__(self, n, p):
		self.n = n
		self.p = p
		self.note = [1, 1]
		self.noteinv = [1, 1]
		self.inv = [0, 1]
		self.calc()

	def calc(self):
		for i in range(2, self.n + 1):
			self.note.append(self.note[-1] * i % self.p)
			self.inv.append(-self.inv[self.p % i] * (self.p // i) % self.p)
			self.noteinv.append(self.noteinv[-1] * self.inv[-1] % self.p)

	def nCr(self, n, r):
		n = self.n
		if r < 0 or n < r:
			return 0
		r = min(r, n - r)
		return self.note[n] * self.noteinv[r] * self.noteinv[n - r] % self.p

def Main():
	(x, y) = read_ints()
	if (x + y) % 3 != 0:
		print(0)
		return
	n = (2 * x - y) // 3
	m = (2 * y - x) // 3
	cmb = Combination(n + m, MOD)
	print(cmb.nCr(n + m, min(n, m)))

def __starting_point():
	Main()
__starting_point()


import math

def main():
	(X, Y) = [int(n) for n in input().split(' ')]
	if (X + Y) % 3 != 0 or Y > 2 * X or X > 2 * Y:
		print(0)
		return 0
	p = 1000000007
	n_move = int((X + Y) / 3)
	i_move = int((2 * X - Y) / 3)
	j_move = int((2 * Y - X) / 3)
	f = [1, 1]
	finv = [1, 1] + [0] * n_move
	for i in range(n_move):
		f.append(f[-1] * (i + 2) % p)
	lf = len(f)
	finv[lf - 1] = modpower(f[-1], p - 2, p)
	for i in range(lf - 1):
		finv[lf - i - 2] = finv[lf - i - 1] * (lf - i - 1) % p
	print(f[n_move] * (finv[i_move] * finv[j_move]) % p % p)

def modpower(a, p, d):
	pp = [a]
	for i in range(int(math.log2(p)) + 1):
		pp.append(pp[-1] ** 2 % d)
	b_p = format(p, 'b')
	m = 1
	for i in range(len(b_p)):
		if b_p[-i - 1] == '1':
			m = m * pp[i] % d
	return m
main()


(X, Y) = map(int, input().split())
M = X + Y
mod = 10 ** 9 + 7
kaijou = [1]
for i in range(1, 10 ** 6 + 1):
	kaijou.append(kaijou[-1] * i % mod)

def C(n, k):
	return kaijou[n] * pow(kaijou[k], mod - 2, mod) * pow(kaijou[n - k], mod - 2, mod) % mod
if M % 3 != 0:
	print(0)
elif X < M // 3 or Y < M // 3:
	print(0)
else:
	print(C(M // 3, X - M // 3))


(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	exit()
A = int((X + Y) / 3)
B = int((2 * Y - X) / 3)
if A < 0 or B < 0:
	print(0)
	exit()
MOD = 10 ** 9 + 7

def comb(n, k):
	tmp = 1
	for i in range(n - k + 1, n + 1):
		tmp *= i
		tmp %= MOD
	for i in range(1, k + 1):
		tmp *= pow(i, MOD - 2, MOD)
		tmp %= MOD
	return tmp
ans = comb(A, B)
print(ans % MOD)


mod = 10 ** 9 + 7
fact = [1] * (10 ** 6 + 1)
for i in range(10 ** 6):
	fact[i + 1] = (i + 1) * fact[i] % mod

def comb(n, k):
	return fact[n] * pow(fact[k], mod - 2, mod) * pow(fact[n - k], mod - 2, mod) % mod
(X, Y) = map(int, input().split())
a = 2 * Y - X
b = 2 * X - Y
ans = 0
if a % 3 == 0 and b % 3 == 0 and (a >= 0) and (b >= 0):
	ans = comb((a + b) // 3, a // 3)
print(ans)


import math
(x, y) = map(int, input().split())
mod = pow(10, 9) + 7
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0 or (2 * y - x) / 3 < 0 or ((2 * x - y) / 3 < 0):
	print(0)
else:
	n = int((2 * y - x) / 3)
	m = int((2 * x - y) / 3)
	P = [1] * (n + m + 1)
	for i in range(1, n + m + 1):
		P[i] = P[i - 1] * i
		P[i] %= mod
	print(P[n + m] * pow(P[n], mod - 2, mod) * pow(P[m], mod - 2, mod) % mod)


import sys

def comb(n, r, mod):
	a = 1
	b = 1
	r = min(r, n - r)
	for i in range(r):
		a = a * (n - i) % mod
		b = b * (i + 1) % mod
	return a * pow(b, mod - 2, mod) % mod
(X, Y) = map(int, input().split())
(X, Y) = (min(X, Y), max(X, Y))
d = Y - X
if X - d != Y - 2 * d or (X - d) % 3 != 0 or X - d < 0:
	print(0)
	sys.exit()
a = (X - d) // 3
b = a + d
print(comb(a + b, b, 10 ** 9 + 7))


(a, b) = map(int, input().split())
aa = a
bb = b
x = 0
y = 0
while aa > 0 and bb > 0:
	if aa > bb:
		aa -= 1
		x += 1
	else:
		bb -= 1
		y += 1
	aa -= 1
	bb -= 1
if aa != 0 or bb != 0:
	print(0)
	exit()
mod = 10 ** 9 + 7
fac = [1]
for i in range(max(a, b)):
	fac.append(fac[i] * (i + 1) % mod)
x += y
r = pow(fac[y] * fac[x - y] % mod, mod - 2, mod)
print(fac[x] * r % mod)


def nCk(n, k, mod):
	a = 1
	for i in range(n, n - k, -1):
		a *= i
		a %= mod
	b = 1
	for i in range(1, k + 1):
		b *= i
		b %= mod
	a *= pow(b, mod - 2, mod)
	return a
(x, y) = list(map(int, input().split()))
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
	ans = 0
else:
	right = x - (x + y) // 3
	up = y - (x + y) // 3
	if right < 0 or up < 0:
		ans = 0
	else:
		ans = nCk(right + up, right, mod) % mod
print(ans)


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

def ncr(n, r, p):
	num = 1
	den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
if (x + y) % 3 == 0:
	n = (x + y) // 3
	if not n <= x <= 2 * n:
		print(0)
	else:
		print(ncr(n, x - n, 1000000007))
else:
	print(0)


import sys
(X, Y) = map(int, input().split())
if (X + Y) % 3 != 0:
	print(0)
	return
A = Y - (X + Y) // 3
B = X - (X + Y) // 3
if A < 0 or B < 0:
	print(0)
	return
N = A + B

def cmb(n, r, mod):
	inv = [0, 1]
	for i in range(2, N + 1):
		inv.append(-inv[mod % i] * (mod // i) % mod)
	cmd = 1
	for i in range(1, min(r, n - r) + 1):
		cmd = cmd * (N - i + 1) * inv[i] % mod
	return cmd
a = cmb(N, A, 10 ** 9 + 7)
print(a)


import sys
r = sys.stdin.readline
(X, Y) = list(map(int, r().split()))
if 2 * X - Y < 0 or (2 * X - Y) % 3 != 0 or 2 * Y - X < 0 or ((2 * Y - X) % 3 != 0):
	print(0)
	return
a = (2 * Y - X) // 3
b = (2 * X - Y) // 3
MOD = 10 ** 9 + 7

def pow(a, b):
	ans = 1
	while b:
		if b & 1:
			ans = ans * a % MOD
		a = a ** 2 % MOD
		b = b // 2
	return ans
N = a + b
K = a
fac = [1 for _ in range(N + 1)]
for i in range(2, N + 1):
	fac[i] = fac[i - 1] * i % MOD
A = fac[N]
B = fac[N - K] * fac[K] % MOD
print(A % MOD * pow(B, MOD - 2) % MOD)


mod = 10 ** 9 + 7

def comb(n, k):
	c = 1
	for i in range(k):
		c *= n - i
		c %= mod
	d = 1
	for i in range(1, k + 1):
		d *= i
		d %= mod
	return c * pow(d, mod - 2, mod) % mod
(x, y) = map(int, input().split())
ans = 0
z = x // 2
for q in range(z, x + 1):
	w = 2 * q - x
	if w * 2 + (q - w) == y:
		t = comb(q, w)
		ans += t
print(ans)


(x, y) = map(int, input().split())
MOD = 10 ** 9 + 7
if (x + y) % 3 != 0:
	print(0)
	exit()
m = (2 * x - y) // 3
n = (2 * y - x) // 3
if m < 0 or n < 0:
	print(0)
	exit()
ans = 1
i = 1
if n > m:
	(n, m) = (m, n)
while i <= n:
	ans *= (m + i) * pow(i, MOD - 2, MOD)
	ans %= MOD
	i += 1
print(ans)


def inv(a, p):
	if a == 1:
		return 1
	elif a == 0:
		return 0
	return p - inv(p % a, p) * (p // a) % p
(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print('0')
	return
if x == 0 and y > 0:
	print('0')
	return
if y / x > 2 or y / x < 0.5:
	print('0')
	return
n = (x + y) // 3
r = (2 * x - y) // 3
p = 10 ** 9 + 7

def fact(n, p):
	a = [[] for _ in range(n + 1)]
	a[0] = 1
	for i in range(n):
		a[i + 1] = a[i] * (i + 1) % p
	return a
f = fact(n, p)
c = f[-1]
d = f[r]
e = f[n - r]
dd = inv(d, p)
ee = inv(e, p)
ans = c * dd * ee % p
print(ans)


MOD = 10 ** 9 + 7

def fac(n):
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % MOD
	return ans
(X, Y) = map(int, input().split())
(a, b) = ((2 * Y - X) // 3, (2 * X - Y) // 3)
if (2 * X - Y) % 3 != 0 or a * b < 0:
	print(0)
else:
	print(fac(a + b) * pow(fac(a), MOD - 2, MOD) * pow(fac(b), MOD - 2, MOD) % (10 ** 9 + 7))


(X, Y) = map(int, input().split())
(A, B) = (1, 1)
mod = 10 ** 9 + 7
if (X + Y) % 3 == 0:
	x = (2 * Y - X) // 3
	y = (2 * X - Y) // 3
	if min(x, y) >= 0:
		for i in range(min(x, y)):
			A *= x + y - i
			A %= mod
			B *= i + 1
			B %= mod
		print(A * pow(B, mod - 2, mod) % mod)
	else:
		print(0)
else:
	print(0)


(X, Y) = map(int, input().split())
m = (-X + 2 * Y) // 3
n = (2 * X - Y) // 3

def combination(n, r, mod=10 ** 9 + 7):
	(n1, r) = (n + 1, min(r, n - r))
	numer = denom = 1
	for i in range(1, r + 1):
		numer = numer * (n1 - i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod - 2, mod) % mod
if (X + Y) % 3 != 0 or m * n < 0:
	print(0)
else:
	print(combination(m + n, n))


from math import factorial
(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
	return
(x, y) = (x - (x + y) // 3, y - (x + y) // 3)
(a, b) = (1, 1)
if min(x, y) < 0:
	print(0)
	return
if x > y:
	(x, y) = (y, x)
mod = 10 ** 9 + 7
for i in range(x):
	a *= x + y - i
	b *= i + 1
	(a, b) = (a % mod, b % mod)
print(a * pow(b, mod - 2, mod) % mod)


(a, b) = map(int, input().split())

def fac(n):
	p = 1
	for i in range(1, n + 1):
		p = p * i % (10 ** 9 + 7)
	return p
if (2 * a - b) % 3 == 0 and (-a + 2 * b) % 3 == 0 and (2 * a - b >= 0) and (-a + 2 * b >= 0):
	x = (2 * a - b) // 3
	y = (-a + 2 * b) // 3
	print(fac(x + y) * pow(fac(x), 10 ** 9 + 5, 10 ** 9 + 7) * pow(fac(y), 10 ** 9 + 5, 10 ** 9 + 7) % (10 ** 9 + 7))
else:
	print(0)


def combination(n, a):
	mod = pow(10, 9) + 7
	(x, y) = (1, 1)
	for i in range(a):
		x = x * (n - i) % mod
		y = y * (a - i) % mod
	return x * pow(y, mod - 2, mod) % mod
(x, y) = map(int, input().split())
(n, m) = ((2 * y - x) // 3, (2 * x - y) // 3)
if (x + y) % 3 != 0 or (n < 0 or m < 0):
	print(0)
else:
	ans2 = combination(n + m, n)
	print(ans2)


def cmb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)
(x, y) = map(int, input().split())
if (x + y) % 3:
	ans = 0
else:
	n = (x + y) // 3
	x -= n
	y -= n
	if x < 0 or y < 0:
		ans = 0
	else:
		ans = cmb(x + y, y, p)
print(ans)


def ext_gcd(a, b):

	def _ext_gcd(a, b):
		xs = [1, 0]
		ys = [0, 1]
		sign = 1
		while b != 0:
			(q, r) = (a // b, a % b)
			(a, b) = (b, r)
			(xtmp, ytmp) = (xs[1], ys[1])
			(xs[1], ys[1]) = (q * xs[1] + xs[0], q * ys[1] + ys[0])
			(xs[0], ys[0]) = (xtmp, ytmp)
			sign = -sign
		return (a, (sign * xs[0], -sign * ys[0]))
	if a < b:
		(d, (y, x)) = _ext_gcd(b, a)
		return (d, (x, y))
	return _ext_gcd(a, b)

def __starting_point():
	(X, Y) = map(int, input().split())
	if (2 * Y - X) % 3 != 0 or (2 * X - Y) % 3 != 0:
		print(0)
		return
	(a, b) = ((2 * Y - X) // 3, (2 * X - Y) // 3)
	if a < 0 or b < 0:
		print(0)
		return
	n = 1
	k = 1
	l = 1
	mod = 10 ** 9 + 7
	for i in range(2, a + b + 1):
		n = n * i % mod
		if i <= a:
			k = k * i % mod
		if i <= b:
			l = l * i % mod
	(_, (k, _)) = ext_gcd(k, mod)
	(_, (l, _)) = ext_gcd(l, mod)
	print(n * k * l % mod)
__starting_point()


MOD = 10 ** 9 + 7

def main():
	(X, Y) = list(map(int, input().split()))
	if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
		a = (2 * X - Y) // 3
		b = (2 * Y - X) // 3
	else:
		print(0)
		return
	if a < 0 or b < 0:
		print(0)
		return
	ab_mod = fact_mod(a + b)
	a_mod = pow(fact_mod(a), MOD - 2, MOD)
	b_mod = pow(fact_mod(b), MOD - 2, MOD)
	print(ab_mod * a_mod * b_mod % MOD)

def fact_mod(x):
	v = 1
	for i in range(1, x + 1):
		v *= i
		v %= MOD
	return v

def __starting_point():
	main()
__starting_point()


fact = [1]
mod = 10 ** 9 + 7
for i in range(1, 10 ** 6 + 1):
	fact.append(fact[-1] * i % mod)

def ncr(n, r):
	return fact[n] * pow(fact[r], mod - 2, mod) * pow(fact[n - r], mod - 2, mod) % mod
(x, y) = map(int, input().split())
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if (x + y) % 3 != 0 or min(a, b) < 0:
	print(0)
else:
	print(fact[a + b] * pow(fact[a], mod - 2, mod) * pow(fact[b], mod - 2, mod) % mod)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
	print(0)
else:
	N = int((2 * Y - X) / 3)
	M = int((2 * X - Y) / 3)
	if N < 0 or M < 0:
		print(0)
	if N == 0 or M == 0:
		print(1)
	if N > 0 and M > 0:
		List = [0 for i in range(N + M)]
		List[0] = 1
		for i in range(N + M - 1):
			List[i + 1] = List[i] * (i + 2) % mod
		print(List[N + M - 1] * pow(List[N - 1], mod - 2, mod) * pow(List[M - 1], mod - 2, mod) % mod)


def modinv(a, m):
	return pow(a, m - 2, m)
(x, y) = map(int, input().split())
if (x + y) % 3 != 0 or 2 * y - x < 0 or 2 * x - y < 0:
	print(0)
else:
	a = (2 * y - x) // 3
	b = (2 * x - y) // 3
	ans = 1
	mod = 10 ** 9 + 7
	for i in range(1, a + 1):
		ans = ans * (i + b) * modinv(i, mod) % mod
	print(ans)


(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
elif x * 2 < y or y * 2 < x:
	print(0)
else:
	a = (x + y) // 3
	b = y - a
	mod = 10 ** 9 + 7

	def inv(x):
		y = 1
		while x != 1:
			y *= mod // x + 1
			y %= mod
			x -= mod % x
		return y
	ans = 1
	for i in range(b):
		ans *= a - i
		ans %= mod
		ans *= inv(b - i)
		ans %= mod
	print(ans)


def f(x, y):
	if (x + y) % 3 != 0:
		return 0
	n = (x + y) // 3
	k = (2 * x - y) // 3
	if k < 0 or k > n:
		return 0
	ret = 1
	for i in range(k):
		ret = ret * (n - i) % MOD * pow(i + 1, MOD - 2, MOD) % MOD
	return ret
MOD = 10 ** 9 + 7
(x, y) = map(int, input().split())
print(f(x, y))


P = 10 ** 9 + 7
(X, Y) = map(int, input().split())

def factorial(n):
	res = 1
	for i in range(2, n + 1):
		res *= i
		res %= P
	return res
if (2 * X - Y) % 3 == 0 and (-X + 2 * Y) % 3 == 0 and (2 * X - Y >= 0) and (-X + 2 * Y >= 0):
	a = (-X + 2 * Y) // 3
	b = (2 * X - Y) // 3
	print(factorial(a + b) * pow(factorial(a), P - 2, P) * pow(factorial(b), P - 2, P) % P)
else:
	print(0)


(X, Y) = map(int, input().split())
MOD = 10 ** 9 + 7

def modinv(a):
	return pow(a, MOD - 2, MOD)
x = (2 * Y - X) // 3
y = (2 * X - Y) // 3
if (2 * Y - X) % 3 != 0 or (2 * X - Y) % 3 != 0 or x < 0 or (y < 0):
	print(0)
else:
	r = 1
	n = x + y
	k = min(x, y)
	for i in range(k):
		r *= n - i
		r *= modinv(i + 1)
		r %= MOD
	print(r)


(X, Y) = map(int, input().split())
mod = pow(10, 9) + 7
m = (2 * X - Y) // 3
n = (2 * Y - X) // 3
if m != (2 * X - Y) / 3 or n != (2 * Y - X) / 3 or m < 0 or (n < 0):
	print(0)
else:
	bunsi = 1
	bunbo = 1
	for i in range(0, n):
		bunsi = bunsi * (m + 1 + i) % mod
		bunbo = bunbo * (1 + i) % mod
	print(bunsi * pow(bunbo, mod - 2, mod) % mod)


(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if (x + y) % 3 != 0:
	print(0)
	exit()
if 2 * min(x, y) < max(x, y):
	print(0)
	exit()
n = (2 * x - y) // 3
m = (2 * y - x) // 3
if n == 0 or m == 0:
	print(1)
	exit()

def ka(x):
	a = 1
	while x != 1:
		a *= x
		x -= 1
		a %= mod
	return a
ans = ka(n + m) * pow(ka(m), mod - 2, mod) % mod * pow(ka(n), mod - 2, mod) % mod
print(ans)


(x, y) = map(int, input().split())
m = 10 ** 9 + 7
if not ((x + y) % 3 == 0 and abs(x - y) <= (x + y) // 3):
	print(0)
	exit()

def comb(n, k):
	a = 1
	for i in range(1, k + 1):
		a *= (n - (i - 1)) * pow(i, m - 2, m)
		a = a % m
	return a
n = (x + y) // 3
k = x - n
print(comb(n, k))


(x, y) = map(int, input().split())
mod = 1000000007
m = (x + y) // 3
a = (m + x - y) // 2
if (x + y) % 3 != 0 or a < 0 or a > m:
	print(0)
else:
	ans = 1
	for i in range(1, a + 1):
		ans *= (m - a + i) * pow(i, mod - 2, mod)
		ans %= mod
	print(ans)


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
if 2 * X < Y or 2 * Y < X:
	print(0)
elif (X + Y) % 3 != 0:
	print(0)
else:
	n = (X + Y) // 3
	(X, Y) = (X - n, Y - n)
	factorial = [1 for i in range(X + Y + 1)]
	for i in range(1, X + Y + 1):
		if i == 1:
			factorial[i] = 1
		else:
			factorial[i] = factorial[i - 1] * i % mod
	print(factorial[X + Y] * pow(factorial[X] * factorial[Y], -1, mod) % mod)


(x, y) = map(int, input().split())
a = 2 * x - y
b = 2 * y - x
if a % 3 == 0 and b % 3 == 0 and (a >= 0) and (b >= 0):
	a = a // 3
	b = b // 3
	c = a + b
	a1 = 1
	a2 = 1
	n3 = 10 ** 9 + 7
	for i in range(a):
		a1 *= c - i
		a2 *= i + 1
		a1 %= n3
		a2 %= n3
	a2 = pow(a2, n3 - 2, n3)
	print(a1 * a2 % n3)
else:
	print(0)


import sys
from collections import deque, defaultdict, namedtuple
import heapq
from math import sqrt, factorial, gcd, ceil, atan, pi

def input():
	return sys.stdin.readline()[:-1]
import string
import operator
import random
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1000000000.0) + 7
INF = float('inf')

def print_lines(data):
	sys.stdout.write('\n'.join((str(x) for x in data)))

def solve():
	(X, Y) = [int(x) for x in input().split()]

	def prod(a, b):
		ans = 1
		for x in range(a, b + 1):
			ans *= x
			ans %= MOD
		return ans

	def fact(x):
		ans = 1
		while x:
			ans *= x
			ans %= MOD
			x -= 1
		return ans

	def coef(n, k):
		if k > n:
			return 0
		return prod(n - k + 1, n) * pow(fact(k) % MOD, MOD - 2, MOD) % MOD
	ans = 0
	if (X + Y) % 3 == 0:
		y = (2 * X - Y) // 3
		x = X - 2 * y
		if y >= 0 and x >= 0:
			if x == 0 or y == 0:
				ans = 1
			else:
				ans = coef(x + y, x)
	print(ans)
T = 1
for case in range(1, T + 1):
	ans = solve()


import math
MOD = 10 ** 9 + 7
(X, Y) = map(int, input().split())
ans = 1
div = 1
a = (-X + 2 * Y) // 3
b = Y - 2 * a
if (X + Y) % 3 != 0 or a < 0 or b < 0:
	print(0)
	exit()
if a < b:
	(a, b) = (b, a)
for i in range(a + b, a, -1):
	ans = ans * i
	ans %= MOD
for i in range(1, b + 1):
	div = div * i
	div %= MOD
ans *= pow(div, MOD - 2, MOD)
print(ans % MOD)


(x, y) = map(int, input().split())
a = min(x, y)
b = max(x, y)
mod = pow(10, 9) + 7
if b - a > a or (a - (b - a)) % 3 != 0:
	print(0)
else:
	r = (a - (b - a)) // 3
	l = (a - (b - a)) // 3 + (b - a)
	c = 1
	d = 1
	for i in range(r):
		c = c * (l + r - i) % mod
		d = d * (r - i) % mod
	ans = c * pow(d, mod - 2, mod)
	print(ans % mod)


def cmb(n, r, mod=10 ** 9 + 7):
	fac = [1, 1]
	for i in range(2, n + 1):
		fac.append(fac[i - 1] * i % mod)
	ret = fac[n] * pow(fac[r] * fac[n - r] % mod, mod - 2, mod) % mod
	return ret
mod = 10 ** 9 + 7
(X, Y) = map(int, input().split())
Z = (X + Y) // 3
if (X + Y) % 3 != 0 or abs(X - Y) > Z:
	print(0)
else:
	print(cmb(Z, X - Z))


def COMinit():
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, max):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod

def COM(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
mod = 10 ** 9 + 7
(X, Y) = list(map(int, input().split()))
a = X % 2
b = X // 2
for i in range(b + 1):
	if a * 2 + b * 1 == Y:
		break
	a += 2
	b -= 1
if a * 2 + b * 1 != Y:
	print(0)
else:
	max = a + b + 1
	fac = [0] * max
	finv = [0] * max
	inv = [0] * max
	COMinit()
	print(COM(a + b, a))


(X, Y) = map(int, input().split())
mod = 10 ** 9 + 7
plus = X + Y
if not plus % 3 == 0:
	print(0)
elif abs(X - Y) > plus // 3:
	print(0)
else:
	row = plus // 3
	col = Y - row
	(l, r) = (1, 1)
	for c in range(col):
		l = l * (row - c) % mod
		r = r * (c + 1) % mod
	print(l * pow(r, mod - 2, mod) % mod)


mod = 10 ** 9 + 7

def nCr(n, r, mod):
	ret = [1] * (r + 1)
	for i in range(1, r + 1):
		ret[i] = ret[i - 1] * (n - i + 1) * pow(i, mod - 2, mod) % mod
	return ret
(X, Y) = map(int, input().split())
(x, y) = (2 * X - Y, 2 * Y - X)
if x < 0 or y < 0 or x % 3 != 0 or (y % 3 != 0):
	ret = 0
else:
	(x, y) = (x // 3, y // 3)
	nCrl = nCr(x + y, min(x, y), mod)
	ret = nCrl[min(x, y)]
print(ret)


MOD = 10 ** 9 + 7
(x, y) = map(int, input().split())
(n, r1) = divmod(2 * y - x, 3)
(m, r2) = divmod(2 * x - y, 3)

def com(n, r):
	X = Y = 1
	if r < 0 or n < r:
		return 0
	if n - r < r:
		r = n - r
	for i in range(1, r + 1):
		Y = Y * i % MOD
		X = X * (n - i + 1) % MOD
	Y = pow(Y, MOD - 2, MOD)
	return X * Y
if r1 or r2:
	print(0)
else:
	print(com(n + m, n) % MOD)


(X, Y) = map(int, input().split())
(a, b) = divmod(2 * X - Y, 3)
(c, d) = divmod(2 * Y - X, 3)
if not b == d == 0 or 2 * X < Y or 2 * Y < X:
	print(0)
else:
	(m, n) = (1, 1)
	mod = 10 ** 9 + 7
	for i in range(1, min(a, c) + 1):
		m = m * (a + c - i + 1) % mod
		n = n * i % mod
	ans = m * pow(n, mod - 2, mod) % mod
	print(ans)


(x, y) = map(int, input().split())
if (x + y) % 3 != 0:
	print(0)
else:
	n = (x + y) // 3
	nx = x - n
	ny = y - n
	if nx < 0 or ny < 0:
		print(0)
	else:
		mod = 10 ** 9 + 7
		fac = [1] * 1000000
		for i in range(1, n + 1):
			fac[i] = fac[i - 1] * i % mod
		print(fac[n] * pow(fac[nx], mod - 2, mod) * pow(fac[ny], mod - 2, mod) % mod)


def nCr(n, r, mod):
	(x, y) = (1, 1)
	for r_ in range(1, r + 1):
		x = x * (n + 1 - r_) % mod
		y = y * r_ % mod
	return x * pow(y, mod - 2, mod) % mod
(x, y) = map(int, input().split())
mod = 10 ** 9 + 7
if (x + y) % 3 or 2 * x < y or 2 * y < x:
	print(0)
else:
	print(nCr((x + y) // 3, (2 * x - y) // 3, mod))


M = 10 ** 9 + 7

def combination(n, k):
	if k > n - k:
		k = n - k
	p = [-1 for i in range(k + 1)]
	kp = {i: [] for i in range(n - k + 1, n + 1)}
	for i in range(2, k + 1):
		if p[i] != -1:
			continue
		for j in range(i, k + 1, i):
			if p[j] == -1:
				p[j] = i
		for j in range(((n - k) // i + 1) * i, n + 1, i):
			kp[j].append(i)
	count = [0 for i in range(k + 1)]
	for x in range(2, k + 1):
		buf = x
		while p[buf] != -1:
			m = p[buf]
			while buf > 1 and buf % m == 0:
				count[m] += 1
				buf = buf // m
	ans = 1
	for x in range(n - k + 1, n + 1):
		buf = x
		for i in kp[x]:
			while count[i] > 0 and buf % i == 0:
				buf = buf // i
				count[i] -= 1
		ans *= buf
		ans %= M
	return ans
(X, Y) = list(map(int, input().split()))
a = X + Y
b = a // 3
a = a % 3
if a == 0 and b <= X <= b * 2:
	print(combination(b, X - b))
else:
	print(0)


(x, y) = map(int, input().split())
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0 or 2 * min(x, y) < max(x, y):
	print(0)
	exit()
mod = 10 ** 9 + 7
n = (x + y) // 3
a = (max(x, y) * 2 - min(x, y)) // 3
fact = [1]
finv = [1]
for i in range(1, n + 1):
	fact += [fact[i - 1] * i % mod]
	finv += [pow(fact[i], mod - 2, mod)]
print(fact[n] * finv[a] * finv[n - a] % mod)


(X, Y) = list(map(int, input().split()))
mod = 1000000007
import sys
if (X + Y) % 3 != 0:
	print(0)
	return
offset = (X + Y) // 3
(X, Y) = (X - offset, Y - offset)
if X < 0 or Y < 0:
	print(0)
	return
(X, Y) = (max(X, Y), min(X, Y))

def C(n, r, mod):
	num = 1
	den = 1
	for i in range(r):
		num *= n - i
		num %= mod
		den *= i + 1
		den %= mod
	return num * pow(den, mod - 2, mod) % mod
print(C(X + Y, Y, mod))


(X, Y) = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k):
	ret = 1
	for i in range(1, k + 1):
		ret = ret * (n - i + 1) % MOD
		ret = ret * pow(i, MOD - 2, MOD) % MOD
	return ret
n = (2 * Y - X) / 3
m = (2 * X - Y) / 3
if n >= 0 and m >= 0 and (n == int(n)) and (m == int(m)):
	print(comb(int(n + m), int(n)))
else:
	print(0)