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: interview

Starter code:

Solutions:
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)

mod = 10**9 + 7
 
def nCk(n,k,p):
    nonlocal 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=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
#(x+y)Cxを求める
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
  #p=(p//a)*a+(p%a) a^(-1)=-(p//a)*(p%a)^(-1)
  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))




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 itertools
# import math
import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
X, Y = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

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

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


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

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

    # (a+b)! % MOD
    ab_mod = fact_mod(a+b)
    # (a!)^(MOD-2) % MOD
    a_mod = pow(fact_mod(a), MOD-2, MOD)
    # (b!)^(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()

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


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)

mod=10**9+7

x,y=map(int,input().split())
if (x+y)%3!=0:
  print(0)
  return
  
if x*2<y or y*2<x:
  print(0)
  return
  
z=(x+y)//3

x-=z
y-=z

n=x+y
r=x

if x==0 or y==0:
  print(1)
  return
  

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)

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


import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

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)

# mod p
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 + 2m = X, 2n + m = Y => 3m = 2X - Y, 3n = 2Y - X
    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()

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
#print(X, Y, xy)

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)

# https://atcoder.jp/contests/abc145/tasks/abc145_d
MOD = 10**9 + 7
x, y = list(map(int, input().split()))

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

# https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E7%95%AA%E5%A4%96%E7%B7%A8


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 = 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((x + y) // 3, x - (x + y) // 3)))


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)

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


#print(s,t)

ans = cmb(s+t, s, 10**9+7)

print(ans)

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 = [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 nCr(n, r):
    num, den = 1, 1
    for i in range(n, n-r, -1):
        num = num * i % M       ##;print(num)
    for i in range(1, r+1):
        den = den * i % M       ##;print(den)
    den_inv = pow(den, -1, M)   #;print(num, den, den_inv) 
    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())
#X, Y =  103078,  214577
a, b = is_comb()   #; print(a, b)
if a==b==0:
    print(0)
else:
    n, r  = a+b, a
    print(nCr(n, r))

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

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

MOD = 10**9+7
x, y = map(int, input().split())
s, t = (-x+2*y)/3, (2*x-y)/3

if s < 0 or t < 0:
    ans = 0
elif not (s.is_integer() and t.is_integer()):
    ans = 0
else:
    s, t = int(s), int(t)
    COMinit()
    ans = COM((s+t), s)

print(ans)

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 = max(a,b)

if min(a,b) < 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)

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)

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

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)

class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        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)


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)

class common_function():
    """
        1. よく使いそうで予め用意してあるものをまとめた
        2. よく使いそうな関数群をまとめた
    """
    def __init__(self):
        """
            1. 英字の一覧をリストに格納しておいた変数
        """
        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):
        """
            mod の下での combination nCk を高速に求めるメソッド
            n が大きい場合(10^6)に使用する. 
            1回 nCk を求めるのに O(k) かかる.
        """
        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())
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())
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 = 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)

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

a=(2*y-x)/3
b=(2*x-y)/3
if a<0 or b<0 or (2*y-x)//3!=a or (2*x-y)//3!=b:
    print(0) 
else:
    a=(2*y-x)//3
    b=(2*x-y)//3
    fac=[0]*(a+b+1)
    finv=[0]*(a+b+1)
    inv=[0]*(a+b+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,a+b+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(fac[a+b]*(finv[a]*finv[b]%mod)%mod)

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)

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 = 1_000_000_007
    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))

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
ie = 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 = ie*(i + 1)%mod

ie = pow(ie, mod - 2, mod)
ans = ans*ie%mod
print(ans)

mod = 10**9 + 7
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

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 = 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:
    # (x,y) = (1,5)とかは無理
    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)

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)

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 # size >= n
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=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))

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 p
    n_mod = fact_mod(n, p)
    # k!^(p-2) mod p
    k_mod = pow(fact_mod(k, p), p-2, p)
    # (n-k)!^(p-2) mod 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

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

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

#(i,j)→（i+1,j+2）をx回、(i,j)→（i+2,j+1）がy回あるとすると
#x=(2Y-X)//3,y=(2X-Y)//3、となる
#これが整数or非負なら(x+y)Cxを求めればいい

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
#(x+y)Cxを求める

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)]
#初期条件
fac[0]=fac[1]=1
inv[1]=1
finv[0]=finv[1]=1
p=1000000007
for i in range(2,x+y+1):
  fac[i]=(fac[i-1]*i)%p
  #p=(p//a)*a+(p%a) pの世界で　a^(-1)=-(p//a)*inv[p%a]
  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))



# import itertools
# import math
import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
X, Y = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

if (X + Y) % 3 != 0:
    print(0)
    return
if (2 * Y - X) < 0 or (2 * X - Y) < 0:
    print(0)
    return

cnt = (X + Y) // 3

diff = abs(X - Y)



def comb(n, m, mod = 10 ** 9 + 7):
    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))

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=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(z)
    # print(min(x,y)-z)
    print((nCr(z,min(x,y)-z)))



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

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


def permute(n, m):
    ret = 1
    while n >= m:
        ret *= n
        # ret %= mod
        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
        # inv[i] = mod - 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]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用

    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)
        # ret = count_comb2(n+m, m)

print(ret)


X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0 or X*2<Y:
  print((0))
  return
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=list(map(int,input().split()))

if (x+y)%3!=0 or x*2<y or y*2<x :
    print((0))
    return

a=(2*x-y)//3
b=(2*y-x)//3

# ans = math.factorial(a+b)/math.factorial(a)
# ans=1
# for i in range(a+1,a+b+1):
#     ans*=i%(10**9+7)

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  # N は必要分だけ用意する
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(a+b,a,p)

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)

#!/usr/bin/env python3
def combination(N: int, R: int, MOD: int):
    """
    Return the number of combinations of N things taken R at a time
    Parameters
    ----------
    N : int
        Number of thing
    R : int
        Number of elements taken
    MOD : int
        MOD
    """
    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()

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)

mod = 10**9 + 7

def nCk(n,k,p):
    nonlocal 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)

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 #1の数
b = X//2 #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 = list(map(int,input().split()))
#xをベースに
r = 0 #→2 ↑1
u = x #→1 ↑2

while y != r + u*2:
    u -= 2
    r += 1
    if u < 0: #到達する方法がない
        print((0))
        return

#modありのコンビネーション計算
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 = u+r+1 #必要な数
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(u+r,r,mod)))


import sys
r=sys.stdin.readline
X,Y=list(map(int,r().split()))
#a=X-2b, b=Y-2a
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
#ex) ab, ba --> a+bCa
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))



# https://atcoder.jp/contests/abc145/tasks/abc145_d
MOD = 10**9 + 7
x, y = list(map(int, input().split()))

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

# https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E7%95%AA%E5%A4%96%E7%B7%A8


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


# 73

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


#!/usr/bin/env python3
def combination(N: int, R: int, MOD: int):
    """
    Return the number of combinations of N things taken R at a time
    Parameters
    ----------
    N : int
        Number of thing
    R : int
        Number of elements taken
    MOD : int
        MOD
    """
    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

    if (X + Y) % 3:
        print((0))
        return
    n = (2 * Y - X) // 3
    m = (2 * X - Y) // 3
    if n < 0 or m < 0:
        print((0))
        return
    print((combination(n + m, n, MOD)))


def __starting_point():
    main()

__starting_point()

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
#print(a,b)
if a==0 and b <= X <= b*2:
  print((combination(b, X-b)))
else:
  print((0))
  


#!/usr/bin/env python
# coding: utf-8

# In[8]:


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


# In[12]:


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


# In[14]:


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)


# In[ ]:






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)

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:
    # (n+m)Cn 通り
    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)

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)

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)

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  # N は必要分だけ用意する
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 = map(int, input().split())

def cmb(n, r, p):
    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)

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

s = X+Y

if s%3 != 0:
    print(0)
else:
    a = (s//3-(X-Y))//2
    print(cmb(s//3, a, 10**9+7))

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

mod=int(1e9)+7
f=[1]
for i in range(1,int(1e6)):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))

# -*- coding: utf-8 -*-
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] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1] # warning bytes
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8').strip()
import string
import operator
import random
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1e9)+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
# T = int(input())
for case in range(1,T+1):
    ans = solve()


"""

1 2
3 4
4 6

x (1, 2) + y (2, 1)

x + 2y = X
2x + y = Y

2x + 4y = 2X
-2x - y = -Y
3y = 2X - Y
y = (2 * X - Y)


3 3


2 1


"""


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)

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)))
#他者の解答を参考にした


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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
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)


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)

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

if (X+Y)%3:
    ans=0
else:
    N=(X+Y)//3
    if N<=X<=2*N and N<=Y<=2*N:
        ans=cmb(N,X-N,p)
    else:
        ans=0

print(ans)

#!/usr/bin/env python3
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))


import sys


MOD = 1_000_000_007


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)


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)


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=list(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)


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 = 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)
  return
a = (2*x - y) // 3
b = (2*y - x) // 3
if a < 0 or b < 0:
  print(0)
  return
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))

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)

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)

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