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:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    X, Y = Scanner.map_int()
    if (X + Y) % 3 != 0:
        print(0)
        return
    n = (X + Y) // 3
    X -= n
    Y -= n
    MAX = 670000
    fac = [0 for _ in range(MAX)]
    finv = [0 for _ in range(MAX)]
    inv = [0 for _ in range(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

    if X > 0 and Y > 0:
        ans = fac[X + Y] * (finv[X] * finv[Y] % MOD) % MOD
        print(ans)
    else:
        print(0)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    X, Y = Scanner.map_int()
    if (X + Y) % 3 != 0:
        print(0)
        return
    m = (2 * X - Y) // 3
    n = X - 2 * m
    MAX = 670000
    fac = [0 for _ in range(MAX)]
    finv = [0 for _ in range(MAX)]
    inv = [0 for _ in range(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

    if m > 0 and n > 0:
        ans = fac[n + m] * (finv[n] * finv[m] % MOD) % MOD
        print(ans)
    else:
        print(0)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    X, Y = Scanner.map_int()
    if (X + Y) % 3 != 0:
        print(0)
        return
    N = (X + Y) // 3
    n = (X - Y + N) // 2
    m = Y - N
    MAX = 670000
    fac = [0 for _ in range(MAX)]
    finv = [0 for _ in range(MAX)]
    inv = [0 for _ in range(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

    if 2 * n + m == X and n + 2 * m == Y and n + m == N:
        ans = fac[N] * (finv[n] * finv[m] % MOD) % MOD
        print(ans)
    else:
        print(0)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
x, y = map(int, input().split())
if x+y % 3 == 0:
    print(0)
    sys.exit()

mod = 10**9 + 7
n = (x+y) // 3
a = min(
    (2 * x - y) // 3, (2 * y - x) // 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)

ans = cmb(n, a, mod)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    mod = 10 ** 9 + 7
    X, Y = map(int, input().split(" "))
    if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
        s = (2 * X - Y) // 3
        t = (2 * Y - X) // 3
        if s < 0 or t < 0:
            print(0)
        else:
            numerator = 1
            denominator = 1
            for i in range(s - t + 1, s + 1):
                numerator = (numerator * i) % mod
            for i in range(1, t + 1):
                denominator = (denominator * i) % mod
            print(numerator * pow(denominator, mod - 2, mod) % mod)
            # math.factorialはTLEになりそう?
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    mod = 10 ** 9 + 7
    X, Y = map(int, input().split(" "))
    if (2 * X - Y) % 3 == 0 and (2 * Y - X) % 3 == 0:
        s = (2 * X - Y) // 3
        t = (2 * Y - X) // 3
        numerator = 1
        denominator = 1
        for i in range(s - t + 1, s + 1):
            numerator = (numerator * i) % mod
        for i in range(1, t + 1):
            denominator = (denominator * i) % mod
        print(numerator * pow(denominator, mod - 2, mod) % mod)
        # math.factorialはTLEになりそう?
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

mod = 10**9+7
N = 1333334
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1,N+1):
  fac[i] = i*fac[i-1]%mod
  rev[i] = pow(fac[i], mod-2, mod)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

a, b = (2*X-Y)//3, (2*Y-X)//3
if a<0 or b<0 or (2*X-Y)%mod or (2*Y-X)%mod:
    print(0)
else:
    print(comb(a+b, a))

Submission status: Wrong Answer

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

mod = 10**9+7
N = 1333334
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1,N+1):
  fac[i] = i*fac[i-1]%mod
  rev[i] = pow(fac[i], mod-2, mod)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

a, b = (2*X-Y)//3, (2*Y-X)//3
if a<0 or b<0:
    print(0)
else:
    print(comb(a+b, a))

Submission status: Wrong Answer

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

mod = 10**9+7
N = 670000
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1,N+1):
  fac[i] = i*fac[i-1]%mod
  rev[i] = pow(fac[i], mod-2, mod)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

a, b = (2*X-Y)//3, (2*Y-X)//3
if a<0 or b<0:
    print(0)
else:
    print(comb(a+b, a))

Submission status: Wrong Answer

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

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

cnt_d1 = 0
cnt_d2 = 0

diff = Y - X
if diff == 0:
    if X % 3 != 0:
        print(0)
        exit()
    cnt_d1 = X // 3
    cnt_d2 = cnt_d1
elif diff > 0:
    Y -= 2 * diff
    X -= 1 * diff
    if X < 0 or X % 3 != 0:
        print(0)
        exit()

    cnt_d1 = X // 3
    cnt_d2 = diff + X // 3
else:
    X -= 2 * diff
    Y -= 1 * diff
    if X < 0 or X % 3 != 0:
        print(0)
        exit()

    cnt_d1 = diff + X // 3
    cnt_d2 = X // 3

MOD = 10**9 + 7
fact = [1]
fact_inv = [1]
for i in range(cnt_d1+cnt_d2 + 10):
    new_fact = fact[-1]*(i+1) % MOD
    fact.append(new_fact)
    fact_inv.append(pow(new_fact, MOD-2, MOD))


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] % mod


print(mod_comb_k(cnt_d1+cnt_d2, cnt_d1, MOD))

'''
dp = np.array([[0] * (Y + 1) for _ in range(X + 1)], dtype=np.int64)
#dp = [np.zeros(Y+1, np.int64) for _ in range(X+1)]
print(dp)

for i in range(X):
    if i > 0:
        dp[i] = dp[i]
'''

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
MOD = 10**9+7

def combination(n, r, mod):
	r = min(r, n-r)
	num = 1
	d = 1
	for i in range(1, r+1):
		num = num * (n+1-i) % mod
		d = d * i % mod
	return num * pow(d, mod-2, mod) % mod
if (x+y)%3 != 0:
	print (0)
	exit()
n = (x+y)/3
yy = (2*x-y)/3
xx = (2*y-x)/3
if xx.is_integer() and yy.is_integer():
	print (combination(int(xx+yy),int(xx),MOD))
else:
	print (0)

Submission status: Wrong Answer

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

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)

Submission status: Wrong Answer

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

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res % (10**9+7))

Submission status: Wrong Answer

Solution code:
def main():
    X,Y = list(map(int,input().split()))
    mod = 1000000007

    a = (2*Y-X)//3
    b = Y-2*a
    s = (X+Y)//3

    if (2*Y-X)%3 == 0 and 0 < a and 0 < b:
        ans = 1
        for n in range(2,s+1):
            ans = (ans*n)%mod
        div = 1
        for n in range(2,a+1):
            div = (div*n)%mod
        for n in range(2,b+1):
            div = (div*n)%mod
        ans = (ans*pow(div,1000000005,mod))%mod
        print(ans)
    else:
        print(0)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X,Y = list(map(int,input().split()))
    mod = 1000000007

    a = (2*Y-X)//3
    b = Y-2*a
    s = (X+Y)//3
    if (2*Y-X)%3 == 0 and 0 < a and 0 < b:
        ans = 1
        for n in range(s-min(a,b)+1,s+1):
            ans = (ans*n)%mod
        div = 1
        for n in range(2,min(a,b)+1):
            div = (div*n)%mod

        ans = (ans*pow(div,1000000005,mod))%mod
        print(ans)
    else:
        print(0)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X,Y = list(map(int,input().split()))
    mod = 1000000007

    if (2*Y-X)%3 == 0:
        a = (2*Y-X)//3
        b = Y-2*a
        s = (X+Y)//3

        ans = 1
        for n in range(s-min(a,b)+1,s+1):
            ans = (ans*n)%mod
        div = 1
        for n in range(2,min(a,b)+1):
            div = (div*n)%mod

        ans = (ans*pow(div,1000000005,mod))%mod
        print(ans)
    else:
        print(0)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

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

if (x + y) % 3 != 0 or n<0 or n>m:
    print(0)
else:


    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)

Submission status: Wrong Answer

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

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2 * y - x) // 3
    m = (2 * x - y) // 3

    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)

Submission status: Wrong Answer

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

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2 * y - x) // 3
    m = (2 * x - y) // 3

    print(n, m)
    # exit()

    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)

Submission status: Wrong Answer

Solution code:
def abp(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        tmp = abp(a, b // 2, p)
        return (tmp * tmp) % p
    if b % 2 == 1:
        return (a * abp(a, b - 1, p)) % p

def nCr1000000007(n, r):
    p = 1000000007
    total = 1
    for i in range(r):
        total *= (n - i) * abp(r - i, p - 2, p)
        total %= p
    return total

def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    n = (x + y) // 3
    r = min((2 * y - x) // 3, (2 * x - y) // 3)
    return nCr1000000007(n, r)

_x, _y = map(int, input().split())
print(solve(_x, _y))

Submission status: Wrong Answer

Solution code:
X,Y = list(map(int,input().split(" ")))



MOD = 10 ** 9 + 7

def inv_fact(a,mod = MOD): #あるmod下における a ! の逆元を求める関数
    ans = 1
    for i in range(1,a + 1):
        ans *= pow(i, MOD - 2 ,MOD)
        ans %= MOD
    return ans



if (2 * X - Y ) % 3 == 0 and (2 * Y - X ) % 3 == 0: # 到達可能であれば
    a = (2 * Y - X ) //3
    b = (2 * X - Y) // 3
    a_inv = inv_fact(a)
    b_inv = inv_fact(b)
    ans = 1
    for i in range(1, a + b + 1):
        ans *= i
        ans %= MOD
    mul = (a_inv * b_inv )% MOD
    ans *= (mul)
    ans %= MOD
    print(ans)

else: #
    print(0)

Submission status: Wrong Answer

Solution code:
X,Y = list(map(int,input().split(" ")))



MOD = 10 ** 9 + 7

def inv_fact(a,mod = MOD): #あるmod下における a ! の逆元を求める関数
    ans = 1
    for i in range(1,a + 1):
        ans *= pow(i, MOD - 2 ,MOD)
        ans %= MOD
    return ans
NOTFOUND = True
for a in range(X):
    # a → 上に2,横に1の移動
    # b → 上に1,横に2の移動
    b = (X - a) //2
    if 2 * a + b == Y and (X - a) % 2 == 0: #上手くハマるbが見つかったら
        NOTFOUND = False
        break
if NOTFOUND: #
    print(0)
else:
    # (a + b) ! *(a! )-1 * (b!) -1
    a_inv =inv_fact(a)
    b_inv = inv_fact(b)
    ans = 1
    for i in range(1,a + b + 1):
        ans *= i
        ans %= MOD
    mul = a_inv * b_inv %MOD
    ans *=(mul)
    ans %= MOD
    print(ans)

Submission status: Wrong Answer

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

if (x+y) % 3 != 0 or (2 * x - y) % 3 != 0 or 2 * x - y < 0 or 2 * y - x < 0:
    print(0)
    sys.exit(0)
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7
n = (x+y)//3
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    if n <= 0 or m <= 0 or n < m: return 0
    m = min(m, n-m)
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res)

Submission status: Wrong Answer

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

if (2 * x - y) % 3 != 0 or 2 * x - y < 0 or 2 * y - x < 0:
    print(0)
    sys.exit(0)
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    if n <= 0 or m <= 0 or n < m: return 0
    m = min(m, n-m)
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res)

Submission status: Wrong Answer

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

if (2 * x - y) % 3 != 0 or 2 * x - y < 0:
    print(0)
    sys.exit(0)
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    if n <= 0 or m <= 0 or n < m: return 0
    m = min(m, n-m)
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res)

Submission status: Wrong Answer

Solution code:
x,y = list(map(int,input().split(" ")))
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    if n <= 0 or m <= 0 or n < m: return 0
    m = min(m, n-m)
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res)

Submission status: Wrong Answer

Solution code:
x,y = list(map(int,input().split(" ")))
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    if n < 0 or m < 0 or n < m: return 0
    m = min(m, n-m)
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res)

Submission status: Wrong Answer

Solution code:
x,y = list(map(int,input().split(" ")))
a = (2*x - y)//3
b = (2*y - x)//3

mod = 10**9+7

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, 666667):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)


def nChoosem(n,m):
    return g1[n] * g2[n-m] * g2[m] % mod

res = nChoosem(a+b,a)
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
x,y=[int(x) for x in input().split()]
mod=10**9+7
def inv(a,n,mod):
    result=1
    while n>0:
        if n & 1==1:
            result*=a
            result%=mod
        a=a*a%mod
        n >>=1
    return result%mod

if (2*x-y)%3 !=0 or (2*y-x)%3!=0:
    print(0)
else:
    # p+2q=x
    # 2p+q=y
    p=(2*y-x)//3
    q=(2*x-y)//3
    ans=1
    for i in range(q):
        ans*=(p+q-i)%mod
        ans%=mod
        ans*=inv(i+1,mod-2,mod)
        ans%=mod
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
x,y=[int(x) for x in input().split()]
mod=10**9+7
def inv(a,n,mod):
    result=1
    while n>0:
        if n & 1==1:
            result*=a
            result%=mod
        a=a*a%mod
        n >>=1
    return result%mod

if (2*x-y)%3 !=0 or (2*y-x)%3!=0:
    print(0)
else:
    # p+2q=x
    # 2p+q=y
    p=(2*y-x)//3
    q=(2*x-y)//3
    ans=1
    for i in range(q):
        ans*=(p+q-i)%mod
        ans%=mod
        ans*=inv(i+1,mod-2,mod)
        ans%=mod
    print(p,q,ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math
from operator import mul
from functools import reduce

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    
    tokens = iterate_tokens()
    X = int(next(tokens))
    Y = int(next(tokens))

    solve(X, Y)

def solve(X: int, Y: int):
    divi_num = 10**9 + 7
    # x  + 2y = X
    # 2x + y  = Y
    if ((X + Y) % 3) == 0:
        y = int((2*X - Y)/3)
        x = int((-1*X +2*Y)/3)
        answer = nCr(x+y, x)
        print(answer%divi_num)
    else:
        print(0)

    return

def nCr(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

if __name__ == "__main__":
    propare()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    
    tokens = iterate_tokens()
    X = int(next(tokens))
    Y = int(next(tokens))

    solve(X, Y)

def solve(X: int, Y: int):
    divi_num = 10**9 + 7
    # x represents the number of moves to the x-axis.
    # y represents the number of moves to the y-axis.
    # x + y is the number of moves.
    # 
    # x  + 2y = X
    # 2x + y  = Y
    if ((X + Y) % 3) == 0:
        y = int((2*X - Y)/3)
        x = int((-1*X +2*Y)/3)
        answer = nCk(x+y, x)
        print(answer)
    else:
        print(0)

    return


def sq(a, b, mod):
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod
 
 
def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer

if __name__ == "__main__":
    propare()

Submission status: Wrong Answer

Solution code:
import math
x,y = list(map(int, input().split()))
mod = 7 + (10**9)
ans = 0
#互いに素なa,bについて、a*x+b*y=1の一つの解
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]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod
if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    exit()
else:
    m = (2*x - y)//3
    n = (2*y - x)//3
    if n <= 0 or m <= 0:
        print(0)
        exit()
    #m+n C m を計算
    #(m+n)! / n! * m!を計算したいが、mod上で割り算できない。
    #逆元を使う
    factorial = [1]*(m+n+1)
    for i in range(1,m+n+1):
        factorial[i] = (factorial[i - 1] * i) % mod
    ans = factorial[m+n] * mod_inv(factorial[m], mod)
    ans %= mod
    ans *= mod_inv(factorial[n], mod)
    ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 24 18:55:49 2020
abc145d
@author: manakamura
"""
import sys
import math
from operator import mul
from functools import reduce

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

tmp = input().split()
x,y = list(map(lambda a: int(a), tmp))

if((x+y)%3!=0):
    print(0)
    sys.exit()
n=(x+y)//3
#r=n+abs(x-y)
r=abs(n-x)
#print(n,r)

#print(math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))
print(combinations_count(n,r))

Submission status: Wrong Answer

Solution code:
#組み合わせのmod対応
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


x, y = map(int, input().split())
ans = 0
if ((x+y)%3 == 0):
    X = (2*x - y)//3
    Y = (2*y - x)//3
    ans = comb(X+Y, X,10**9+7)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return
    
    n = (x + y) // 3
    r = n // 2 - abs(x-y) // 2
    print(n, r)
    print(nCr(n, r))
    return
    
main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return
    
    n = (x + y) // 3
    r = 0
    if n % 2 == 0:
        r = n // 2 - abs(x-y) // 2
    else:
        r = (n + 1) // 2 -abs(x-y) // 2
    print(nCr(n, r))
    return
    
main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return

    n = (x + y) // 3
    r = n // 2 + abs(x - y) // 2
    print(nCr(n, r))
    return
    
main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
x, y = map(int, input().split())

mod = 10**9 + 7
f = [1]
for i in range(10**6):
    f.append(f[-1] * (i+1) % mod)
    
def nCr(n, r):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def main():
    if (x + y) % 3 != 0 or (x + y) // 3 < abs(x - y):
        print(0)
        return

    n = (x + y) // 3
    r = n - abs(x - y)
    print(nCr(n, r))
    return
    
main()

Submission status: Wrong Answer

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