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.



Sample input:
3 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

X, Y = [int(x) for x in input().strip().split()]
n1 = 2 * Y - X
n2 = 2 * X - Y

if n1 < 0 or n2 < 0:
    print(0)
else:
    print(combination(n1 + n2, n1) % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
import math

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

a = (2*X - Y) / 3
b = (2*Y - X) / 3
if not (a.is_integer() or b.is_integer()):
    print(0)
    exit()
else:
    if a < b:
        a, b = b, a
    c = 1
    for i in range(int(a+b), int(a-1), -1):
        c *= i
    for i in range(1, int(b)):
        c /= i
    print(c % (10**9+7))

Submission status: Wrong Answer

Solution code:
x,y = [int(x) for x in input().split()]

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

if (a==int(abs(a)) and b==int(abs(b))):
    n=1
    for i in range(1,int(a+b+1)):
        n*=i
    print(n%(1000000000+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 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

def main():
    x, y = MAP()
    if (x + y) % 3 != 0:
        print(0)
        sys.exit()
    m = x - (x + y) // 3
    n = y - (x + y) // 3
    print(cmb(n + m, n) % mod)


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def cmb(n, r, prime):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n % prime

    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] = numerator[k - offset] // pivot
                denominator[k] = denominator[k] // pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = (result % prime) * (numerator[k] % prime)
    
    result = result % prime
    return result


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

ans = 0

#if (x + y) % 3 == 0 and (2*x - y) % 3 == 0:
a = (x + y) // 3
b = (2*x - y) // 3
if a >= 0 and b >= 0:
    ans = cmb(a,b, pow(10,9) + 7)
#ans = mod_combination(a,b,pow(10,9) + 7)


print(ans)

Submission status: Wrong Answer

Solution code:


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

  if (2*x-y)%3==0 and (2*y-x)%3==0:
    a=(2*x-y)//3
    b=(2*y-x)//3
    #print(a,b)

    result=1.0


    for i in range(int(a)):
      result=result*(a+b-i)/(1+i)

    result=result%mod
    print((result))

  else:
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
A = max(X, Y)
cnt = 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

for i in range(A//2):
    x = X - i
    y = Y - 2*i
    if x/2 == y and i != x//2:
        if x > i:
            print(cmb(y+1, i) % (10**9 + 7))
        else:
            print(cmb(x+1, i) % (10**9 + 7))
        exit()
    elif x/2 == y and i == x//2:
        print(cmb(x, i)% (10**9 + 7))
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
 
x = (2*Y - X)/3
y = (2*X - Y)/3
 
ans = 0
 
def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

if (2*Y - X)%3!=0 or (2*X - Y)%3!=0 or (2*X - Y)<0 or (2*X - Y)<0:
    ans = 0
if x//1==x and y//1==y:
    ans = mod_Combination(int(x + y), int(x), 10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
Y,X = [int(i) for i in input().split()]
def check(x,y):
    if x/2 == y:
        return 0
    elif x/2 < y:
        return 1
    else:
        return 9
cnt = 0
possible = True

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def cmb(n,r):
    m = 10**9+7
    res = 1
    for i in range(1,n+1):
        res = res*i%m
    for i in range(1,r+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,n-r+1):
        res = res*mod_inv(i,m)%m
    return res

while True:
    check_num =  check(X,Y)
    if check_num == 0:
        break
    elif check_num == 1:
        X += 1
        Y -= 1
        cnt += 1
    else:
        possible = False
        break
if possible == True:
    n = X // 2 
    r = cnt
    print(cmb(n,r))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math


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())
#print(X, Y)
amari = 10 ** 9 + 7
large = max(X, Y)
small = min(X, Y)
kaisu1 = 0
isOK = False
for i in range(0, 333334):
    if large + i * 3 == small * 2:
        isOK = True
        kaisu1 = i
        #print(kaisu1)
        break
if not isOK:
    print(0)
else:

    kaisu2 = large - kaisu1 * 2
    '''
    tmp = max(kaisu2, kaisu1)
    #print(tmp)
    #print(kaisu2+kaisu1)
    result = 1
    if X == 999999 and Y == 999999:
        print(151840682)
        exit(0)
    for i in range(tmp + 1, (kaisu1 + kaisu2)):
        result *= i
        result %= amari
    print(result % amari)
    kaisu2 = large - kaisu1 * 2
    print(kaisu2,kaisu1)
    result = math.factorial(kaisu1 + kaisu2) // math.factorial(kaisu2)
    '''
    print(cmb(kaisu1+kaisu2,kaisu2) % amari)

Submission status: Wrong Answer

Solution code:
#Beginner COnetst 145 /2019/11/16
#Probrem A
#import math
from operator import mul
from functools import reduce

DEBUG = 0

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def calc(x,y):
    if (x*2-y)%3 != 0 or (y*2-x)%3 != 0: return 0
    m = (x*2-y)//3
    n = (y*2-x)//3
    return combinations_count(m+n,m)

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

if DEBUG:print(X,Y)

print(calc(X,Y)%(10**9+7))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
import math


z = 10**9+7

X, Y = map(int, input().split())
x = (-X+2*Y)/3
y = (2*X-Y)/3
if x.is_integer() and y.is_integer() and x>0 and y>0:
    x = int(x)
    y = int(y)
    maximam = max(x,y)
    minimam = min(x,y)
    bunbo = 1
    for i in range(1,minimam+1):
        bunbo = bunbo * (maximam + i) / i % z
    print(int(bunbo))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
from math import factorial
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())
  
i = (2/3)*X - (1/3)*Y
j = (2/3)*Y - (1/3)*X

if i%1 != 0 or j%1 != 0 or i < 0 or j < 0 or (X+Y) % 3 != 0 or X > 2*Y or Y > 2*X:
  print(0)
  sys.exit()

if i == 0 or j == 0:
  print(1)
  sys.exit()
  
  
n = i + j

a = cmb(int(n),int(i))#factorial(n) / factorial(i) / factorial(n - i)
print(int(a)%1000000007)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
 
x = (2*Y - X)/3
y = (2*X - Y)/3
 
ans = 0
 
def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

if (2*Y - X)%3!=0 or (2*X - Y)%3!=0 or x<0 or y<0:
    ans = 0
if x//1==x and y//1==y:
    ans = mod_Combination(int(x + y), int(x), 10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
def binomial(n, k):
    num = 1
    for i in range(1, min(k, n - k) + 1):
        num = ( (num * n) // i) % (10**9 + 7)
        n -= 1
    return num % (10**9 + 7)

x, y = [int(a) for a in input().split()]

if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    ans = 0
else:
    a = (2 * x - y) // 3
    b = (2 * y - x) // 3
    ans = binomial( a + b, b)

print(ans)

Submission status: Wrong Answer

Solution code:
class Solution:
    def solve(self, x: int, y: int) -> int:

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

        m = (2*x - y) // 3
        n = (-x + 2*y) // 3

        if m <= 0 or n <= 0:
            return 0

        # calculate {m+n}C{n}
        def egcd(a, b):
            if a == 0:
                return b, 0, 1
            else:
                g, y, x = egcd(b % a, a)
                return g, x - (b // a) * y, y

        def modinv(a, m):
            g, x, y = egcd(a, m)
            if g != 1:
                raise Exception('modular inverse does not exist')
            else:
                return x % m

        def convination(n: int, r: int, mod: int = 10**9+7) -> int:
            r = min(r, n-r)
            res = 1
            for i in range(r):
                res = res * (n-i) * modinv(i+1, mod) % mod
            return res

        return convination(n+m, m)


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(x, y))

Submission status: Wrong Answer

Solution code:
def cmb(n, r, prime):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n % prime

    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] = numerator[k - offset] // pivot
                denominator[k] = denominator[k] // pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = (result % prime) * (numerator[k] % prime)
    
    result = result % prime
    return result


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

ans = 0

if (x + y) % 3 == 0 and (2*x - y) % 3 == 0:
    a = (x + y) // 3
    b = (2*x - y) // 3
    if a >= 0 and b >= 0:
        ans = cmb(a,b, pow(10,9) + 7)
    #ans = mod_combination(a,b,pow(10,9) + 7)


print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

if (X+Y) % 3 != 0 or X < 3 or Y < 3:
  print(0)
  exit()

# t=X方向に+1する回数(=Y方向に+2する回数)を仮にXと同じ値にする
t = X

# tを調整
while(t * 2 > Y):
  t -= 1
#print(t)

# r=総移動回数
r = t + (X-t)//2
#print(r)

ans = math.factorial(r) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce


def knight_move(X, Y):
    if (X + Y) % 3 != 0:
        return 0
    n = (X + Y) // 3
    i = min(X - n, n - (X - n))
    numer = reduce(mul, range(n, n - i, -1), 1)
    denom = reduce(mul, range(1, i + 1), 1)
    return (numer // denom) % (10 ** 9 + 7)


X, Y = map(int, input().split())
res = knight_move(X, Y)
print(res)

Submission status: Wrong Answer

Solution code:
import math


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())
#print(X, Y)
amari = 10 ** 9 + 7
large = max(X, Y)
small = min(X, Y)
kaisu1 = 0
isOK = False
for i in range(0, 333334):
    if large + i * 3 == small * 2:
        isOK = True
        kaisu1 = i
        #print(kaisu1)
        break
if not isOK:
    print(0)
else:

    kaisu2 = large - kaisu1 * 2
    '''
    tmp = max(kaisu2, kaisu1)
    #print(tmp)
    #print(kaisu2+kaisu1)
    result = 1
    if X == 999999 and Y == 999999:
        print(151840682)
        exit(0)
    for i in range(tmp + 1, (kaisu1 + kaisu2)):
        result *= i
        result %= amari
    print(result % amari)
    kaisu2 = large - kaisu1 * 2
    print(kaisu2,kaisu1)
    result = math.factorial(kaisu1 + kaisu2) // math.factorial(kaisu2)
    '''
    print(cmb(kaisu1+kaisu2,kaisu1) % amari)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

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

big_num = max(X, Y)
small_num = min(X, Y)
three_quot = small_num // 3
big_rem = big_num - three_quot * 3
small_rem = small_num - three_quot * 3
div_num = 10 ** 9 + 7
ans = 0
if big_rem == small_rem * 2:
    case_num = small_rem + three_quot
    ans = permutations_count(case_num + 1, three_quot) % div_num
#     ans = 1
#     for i in range(three_quot):
#         ans *= (case_num + 1)
#         ans %= div_num
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def cmb(n, r, prime):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n % prime

    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] = numerator[k - offset] // pivot
                denominator[k] = denominator[k] // pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = (result % prime) * (numerator[k] % prime)
    
    result = result % prime
    return result


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

ans = 0

if (x + y) % 3 == 0 and (2*x - y) % 3 == 0:
    a = (x + y) // 3
    b = (2*x - y) // 3
    ans = cmb(a,b, pow(10,9) + 7)
    #ans = mod_combination(a,b,pow(10,9) + 7)


print(ans)

Submission status: Wrong Answer

Solution code:
import math
X, Y = map(int, input().split())
p = (((X+Y)/3)+Y-X)/2
m = p+X-Y


def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


if p % 1 != 0 or p<0:
    ans = 0

else:
    q = p+m
    q = int(q)
    p = int(p)
    ans = comb(q,p,10**9+7)
  

print(ans)

Submission status: Wrong Answer

Solution code:
import math
X, Y = map(int, input().split())

# from collections import defaultdict
# float("inf")
# E = defaultdict(lambda: defaultdict(lambda: 0))
# E[0][0] = 1
_max = max(X, Y)
_min = min(X, Y)
se = _max // 2
ammari = _max % 2
flag = False
_se = 0
_on = 0
for i in range(se, -1, -1):
    if _min == 1*(se-i)+2*(i*2)+2*ammari:
        flag = True
        _on = se - i
        _se = i*2



if flag:
    # print(True)
    # print(_on)
    # print(_se)
    # print(ammari)
    print(math.factorial(_on + _se + ammari)%(10**9+7))
else:
    print(0)
    exit()

Submission status: Wrong Answer

Solution code:


def kai(a, b, c=0, mod=0 ):
    K = 1
    if c == 1:
        for k in range(a):
            if k == 0:
                t = b
            K *= t
            K %= mod
            t -= 1
            
    else:
        for k in range(a):
            if k == 0:
                t = b
            K *= t
            t -= 1
    return K

X, Y = map(int, input().split())
diff = X - Y
D = (min(X, Y)- abs(diff))
ans = 0
mod = 10**9 + 7
if D%3 != 0:
    print(0)
else:
    m1 = abs(diff) + (D//3)
    m2 = D//3
    s  = m1 + m2

    ans = kai(m2, s,1,mod)%mod * (1/kai(m2, m2))%mod

    print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
import sys
x, y = map(int, input().split(' '))

# print(x, y)
count_x1 = 0
count_x2 = 0
count_y1 = 0
count_y2 = 0 

ans = 0

while True:
  if x > y:
    x -= 2
    y -= 1
    count_x2 += 1
    count_y1 += 1
  else:
    x -= 1
    y -= 2
    count_x1 += 1
    count_y2 += 1
  
  if x < 1 or y < 1:
    break

if x == 0 and y == 0:
  if count_x1 == 0 or count_x2 == 0:
    print(1)
    sys.exit()
  
  if count_x1 == count_x2:
    ans = 2 ** count_x1
  else:
    min_count = min(count_x1, count_x2)
    ans = 2 ** min_count + 1
else:
  ans = 0

print(ans % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
mod=10**9+7
x,y=map(int,input().split())
a=[0]*1001
b=[0]*1001
a[1]=1
if (x+y)%3!=0:
    print(0)
    exit()
#move cnt
m=(x+y)//3

if x>m*2 or y>m*2:
    print(0)
    exit()
for i in range(m):
    for j in range(1,1000):
        if i%2==0:
            if a[j]==a[j-1]==0: break
            b[j]=(a[j]+a[j-1])%mod
        elif i%2:
            if b[j]==b[j-1]==0: break
            a[j]=(b[j]+b[j-1])%mod
    if i%2==0:
        a=[i for i in b]
    else:
        b=[i for i in a]
o=min(x,y)
p=max(x,y)
print(a[abs(p-o-m)])

Submission status: Wrong Answer

Solution code:
class Solution:
    def solve(self, x: int, y: int) -> int:

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

        m = (2*x - y) // 3
        n = (-x + 2*y) // 3

        # calculate {m+n}C{n}
        def egcd(a, b):
            if a == 0:
                return b, 0, 1
            else:
                g, y, x = egcd(b % a, a)
                return g, x - (b // a) * y, y

        def modinv(a, m):
            g, x, y = egcd(a, m)
            if g != 1:
                raise Exception('modular inverse does not exist')
            else:
                return x % m

        def convination(n: int, r: int, mod: int = 10**9+7) -> int:
            r = min(r, n-r)
            res = 1
            for i in range(r):
                res = res * (n-i) * modinv(i+1, mod) % mod
            return res

        return convination(n+m, m)


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(x, y))

Submission status: Wrong Answer

Solution code:
def solve():
    X, Y = map(int, input().split())
    if (2 * Y - X) % 3 > 0 or (2 * X - Y) % 3 > 0: print(0)
    else:
        a = (2 * Y - X) // 3
        b = (2 * X - Y) // 3
        if a > 0 and b > 0:
            mod = 7 + 10 ** 9
            fact = [0] * (2 * 10 ** 6 + 1)
            revfact = [0] * (2 * 10 ** 6 + 1)
            fact[1] = 1
            for i in range(2, 2 * 10 ** 6 + 1):
                fact[i] = (i * fact[i-1]) % mod
            revfact[2 * 10 ** 6] = pow(fact[2 * 10 ** 6], mod - 2, mod)
            for i in reversed(range(2 * 10 ** 6)):
                revfact[i] = ((i + 1) * revfact[i + 1]) % mod

            print((fact[a + b] * revfact[a] * revfact[b]) % mod)
        else: print(0)

    

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**6)
input=sys.stdin.readline

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


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

if (X+Y)%3 != 0:
    print(0)
    sys.exit()

val = [X,Y]
val_min = min(val)

val_min_sho = int(val_min/3)

X_henkan = X - 3*val_min_sho
Y_henkan = Y - 3*val_min_sho
if (X_henkan == 0 and Y_henkan == 0):
    n = (val_min_sho)*2
    n_2 = int(n/2)
    print(comb(n,n_2,10**9+7))
elif Y_henkan != 0 and (X_henkan / Y_henkan == 2):
    n = (val_min_sho)*2 + Y_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
elif X_henkan != 0 and (Y_henkan / X_henkan == 2):
    n = (val_min_sho)*2 + X_henkan
    n_2 = val_min_sho
    print(comb(n,n_2,10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
x,y = [int(x) for x in input().split()]

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

if (a==int(a) and b==int(b)):
    n=1
    for i in range(1,int(a+b+1)):
        n*=i
    print(n%(1000000000+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

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

if X < 3 or Y < 3:
  print(0)
  exit()

# t=X方向に+1する回数(=Y方向に+2する回数)を仮にXと同じ値にする
t = X

# tを調整
while(t * 2 > Y):
  t -= 1
#print(t)

# r=総移動回数
r = t + (X-t)//2
#print(r)

ans = math.factorial(r) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
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())
s=int((2*y-x)/3)
t=int((2*x-y)/3)
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(10**9+7))

Submission status: Wrong Answer

Solution code:
from math import factorial

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


if x == y:
    print(factorial((x*2//3)) // (factorial(x//3) ** 2) % (10**9+7))
else:
    print(factorial((x + y) // 3) //
          (factorial(x//3) * factorial(y//3)) % (10**9+7))

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(200000)
MOD = 10 ** 9 + 7


def main():
    X, Y = map(int, input().split())
    while X != Y:
        if X > Y:
            X -= 2
            Y -= 1
            if X < 0 or Y < 0:
                print(0)
                exit()
        else:
            X -= 1
            Y -= 2
            if X < 0 or Y < 0:
                print(0)
                exit()

    if X % 2 == 1 and Y % 2 == 1:
        ab = math.factorial((X + Y) // 3)
        a = math.factorial(X // 3)
        b = math.factorial(Y // 3)
        print(ab // (a * b) % MOD)
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))
class BigCombination(object):

    def __init__(self, mod: int=10**9+7, max_n: int=5*(10**6)):
        fac, inv=[1], []
        fac_append, inv_append=fac.append, inv.append

        for i in range(1, max_n+1):
            fac_append(fac[-1] * i % mod)

        inv_append(pow(fac[-1], mod-2, mod))

        for i in range(max_n, 0, -1):
            inv_append(inv[-1] * i % mod)

        self.mod, self.factorial, self.inverse=mod, fac, inv[::-1]

    def get_combination(self, n, r):
        if n < r:
            return 0
        return self.factorial[n] * self.inverse[r] * self.inverse[n-r] % self.mod

    def get_permutation(self, n, r):
        if n < r:
            return 0
        return self.factorial[n] * self.inverse[n-r] % self.mod
def main():
    
    X,Y = MI()
    if (X+Y)%3 != 0:
        print(0)
        return 
    S = X+Y
    X-=S//3
    Y-=S//3
    B = BigCombination()
    ans = B.get_combination(X+Y,X)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
ans = 0
if Y//2 > X:
  na_max = X+1
else:
  na_max = Y//2+1
if X//2 > Y:
  nb_max = Y+1
else:
  nb_max = X//2+1
  
if   X%2==1 and Y%2==1:
  for na in range(1,na_max,2):
    for nb in range(1,nb_max,2):
      if na+2*nb==X and 2*na+nb==Y:
        ans+=1
  print(ans%(10**9+7))
elif X%2==1 and Y%2==0:
  for na in range(1,na_max,2):
    for nb in range(0,nb_max,2):
      if na+2*nb==X and 2*na+nb==Y:
        ans+=1
  print(ans%(10**9+7))
  
elif X%2==0 and Y%2==1:
  for na in range(0,na_max,2):
    for nb in range(1,nb_max,2):
      if na+2*nb==X and 2*na+nb==Y:
        ans+=1
  print(ans%(10**9+7))
  
elif X%2==0 and Y%2==0:
  for na in range(0,na_max,2):
    for nb in range(0,nb_max,2):
      if na+2*nb==X and 2*na+nb==Y:
        ans+=1
  print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
import math
X,Y = list(map(int, input().split()))
cnts = [0,0]
while X>0 and Y>0:
    if X <= Y:
        unit =  Y-X + 1
        cnts[1] +=unit
        X -= unit
        Y -= 2*unit
    else:
        unit =  X-Y
        cnts[0] +=unit
        X -= 2*unit
        Y -= unit
        
if X == 0 and Y == 0:
    i = cnts[0]
    j = cnts[1]
    print(math.factorial(i+j)//(math.factorial(i)*math.factorial(j)) % (10**9 + 7))
else:
    print(0)