Problem:
 Score : 400 points    Problem Statement 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 1 3 3      Sample Output 1 2  There are two ways: (0,0) \to (1,2) \to (3,3) and (0,0) \to (2,1) \to (3,3) .       Sample Input 2 2 2      Sample Output 2 0  The knight cannot reach (2,2) .       Sample Input 3 999999 999999      Sample Output 3 151840682  Print the number of ways modulo 10^9 + 7 .

Solution (Python):
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    X, Y = MI()
    
    exist = False
    for x1 in range(0, X+1):
        y1 = Y - 2 * x1
        if x1 + 2 * y1 == X:
            exist = True
            break
    if not exist:
        print(0)
        sys.exit()

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

    a = cmb(x1+y1,y1,mod)
    print(a)
    
if __name__ == "__main__":
    main()

Solution (Python):
import sys









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)


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)
        exit()
    
    n = (2 * x - y) // 3
    m = (2 * y - x) // 3
    cmb = Combination(n + m, MOD)
    print(cmb.nCr(n + m, min(n, m)))

if __name__ == '__main__':
    Main()

Solution (Python):
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 = 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)


if __name__ == '__main__':
    main()

Solution (Python):
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 = 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)


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):

"""

import numpy as np
i8 = np.int64
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(in_file):
    stdin = open(in_file)
    X, Y = [int(x) for x in stdin.readline().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 main2():
    main('/dev/stdin')
"""
import os, sys
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
if len(sys.argv) == 1:
    import subprocess
    if p == "":
        pymain = "./" + pymain
    subprocess.call(pymain)
else:
    import gzip, base64, stat
    gz = b'H4sIANSfUV8C/+19C3hTVbbwSV+EVxMQpSIDQQu2PNqGFmjLK6UNnEgKHVoe4yukaUqjedTkBIrjKNqWIYYi48x1GD/vHebNzHVGZnS8gg5QEcowo6KgVEFEBEkoCI4KRYX8a+29T3LOaQ6v8bv3+7+PKN1Z6+y99lprr7X2M2c/YrbOTNFoOPGTwk3jEFo/xERgE8Pn/DieBXDFXG/4O5wbxmUAnCbJZ+JMsrSbkRZTLcuXysoVp1C4OMUkS4eyfGKqkaTpnPRjkqWdd3OylOMM8XLIa46byeNeLEtXMaIbM+TlUli5iIdiI57FspRL4WSpKF8a+1fD8DVMLjGtYPkqJPnxU3VMqCN6Wcj0stAkS59h+Z5RlPsulMvgrvyjZ+k8Vp+aXjpTOVkqtkO+21U7sSjfXTfO7fIGm8Y1FU8cN7EoL+DLG0940rO8s+bMj7d3ioTnQQyHz3OfHD9w4oSFg/5x76StVZ91Df5Vdt9T+KyAlekF/1oy9Yv75fZOwZIr+nEafFaEeoF/f/jRlFefcfxtR59H19qeP1j4ztjPbPfuq17fvKrVcdP9//HCuP8a2vjSoHX9ypss97+Ya37Heim9aKCygUnwy7nk+HBacvyulOT421XoWzTJ8WNU8PaM5Pi/quB7qdT7O5X8xvTk+Isq+Mkq9NtV+M9TyZ+tkv9NFf3PUKGzR6VdvquSv1al3j+p1HuvSvt+raLPsanJ8Teq8LNRhZ/fqNQ7UAW/SKXeGSr6GarCz0kV+iPU+Fexk3dV6rWo0Hlahf+ISruMVKn3iEq73KCCX6lS7wIVPvXxHkP+qVChcwLwI7gbuV0szoplWzmKjzD8IoY/kELxJtbviPG7kdGpYvgshl8CehiA+RkdMW7PYfpZn2WS8TOatYtpiBwvpFP6DYz+CoafxPjk3XL8wgysdwi37QHGJ6u4jrXXnpvl9Icz/GJFvRz0LwGhzjFmDPYpEzmbb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zkH6OivHhOQ2CI7MuUx99Pno3FfPFzU6z8Ooa4m+HTFee6xM8cdkYrRXGOq5sh1rOCGUx2reI81QJ2dipFcS5snVZ+DkxNf/eyM1hiefEciZ8tuDYp+E9RpPezM10iLJ43OcPKb+MS/Kcmkf9BptMUxTmyjQPk58iU+hPlb2HlZyjOpa0fKD/Hls7KKMuvYTrJUJzjKx4sP++m1v4hRXnxPEwVK2hIlefXK9KfKMqL5y0a2cHAJwuSlxc/TyvKi/t4abPl5+/U+F+v8D9xX1XPyuf0k+dXtt8Gpf+yfevihRR+5jL1v6goL57r6WTlG1MvXf82RXnx3At/F4XXai5d/9vwL1Ny/lDcL89xJ9e3VpEewj0eSXlxH77YnZxfZfkTjH+xvLhvbmLlNyj4V8azcxLfkp5bjHjkjpqhqFcvCQjS+sVzTBHflcmfrigfP1fQyOxLc+nymYry4r7j+gcuXb/4GaShOLG8uM+58YHEeaJL6e9mVr/CzeLlq67gvHBKso7Nz+wpk4ufe7ojSfzpLdWd5JPDNqQ6B1w6fg9QKc89yc57aC5d/v8BQ7g+7uiaAAA='
    bin = gzip.decompress(base64.b64decode(gz))
    with open(pymain, "wb") as f:
        f.write(bin)
    os.chmod(pymain, 0o775)

Solution (Python):
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)
    exit(0)
  else:
    n=(2*y-x)//3
    m=(2*x-y)//3
    if n<0 or m<0:
      print(0)
      exit(0)
    else:
      init(n+m)
      print(com(n+m,n,mod))
      
main()