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
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


def main(x, y):
    if (x+y) % 3 != 0:
        return 0

    if x/2.0 < y or y/2.0 < x:
        return 0

    ret = reachable((0, 0), (x, y))
    return ret % (10**9 + 7)


def reachable(current, target):
    if current == target:
        return 1
    elif (current[0]>target[0]) or (current[1]>target[1]):
        return 0
    else:
        return reachable((current[0]+1, current[1]+2), target) + reachable((current[0]+2, current[1]+1), target)


if __name__ == '__main__':
    p = input().split(' ')
    print(main(int(p[0]), int(p[1])))

Submission status: Wrong Answer

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


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

n=a+b

p1=1
p2=1
p3=1

for i in range(n):
    p1=p1*(i+1)%mod

for i in range(max(a,b)):
    p2=p2*(i+1)%mod

    if i==b-1:
        p3=p2

if a+2*b==x and 2*a+b==y:
    print(p1*pow(p2,mod-2,mod)*pow(p3,mod-2,mod)%mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
a = ((x+y)/3 + (x-y))/2
b = ((x+y)/3 - (x-y))/2

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

#print(a)
#print(b)

if a.is_integer()and b.is_integer():
    print(cmb(int(a+b),int(min(a,b)))%(10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7         # 問題に合わせて適宜書き換え
list_size = 10**6+100  # 問題に合わせて適宜書き換え

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = ((f_list[i] * (i+2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(-2, -list_size-1, -1):
	f_r_list[i] = ((f_r_list[i+1] * (list_size + 2 + i)) % MOD)

def comb(n,r):
    if n == r or r == 0:
        return 1
    return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD

X,Y = map(int,input().split())
N = (X+Y)//3
X -= N
print(comb(N,X))

Submission status: Wrong Answer

Solution code:
x, y = map(int,input().split())
if (x+y)%3!=0:
  print(0)
  exit()
n = (x+y)//3
if 0 > x-n or 0 > y-n:
  print(0)
  exit()

m = min(x-n,y-n)
mod = 1000000007
a=1
b=1

for i in range(1,m+1):
  a = a *(n+1-i) % mod
  b = b * i %mod
print(a // b)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC145 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x,y = LI()
fact = [1]*(10**6+1)
for i in range(1,10**6+1):
    fact[i] = i*fact[i-1]
    fact[i] %= mod

if (x+y) % 3 != 0:
    print(0)
    quit()
n,m = (2*x - y)/3,(2*y - x)/3
if n % 1 == 0 and m % 1 == 0:
    n = int(n)
    m = int(m)
    ans = fact[n+m]*pow(fact[n],mod-2,mod)*pow(fact[m],mod-2,mod)
    ans %= mod
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
G = list(map(int, input().split()))
total = G[0] + G[1]
if total % 3 != 0:
  print(0)
  sys.exit(0)

total //= 3
dis = G[0] - total

mod = 10 ** 9 + 7
fact = [1]
fact_inv = [1]
for i in range(10**6):
    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(total, min([total-dis, dis]), mod))

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) // 3
n2 = (2 * X - Y) // 3

if n1 < 0 or n2 < 0 or (2 * Y - X) % 2 != 0 or (2 * X - Y) % 2 != 0:
    print(0)
elif n1 == 0 or n2 == 0:
    print(1)
else:
    print(combination(n1 + n2, n1) % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

 
a = x+y
a1 = a//3
if a % 3 != 0:
    print(0)
    
else:
    #2の数
    c = x % (a1)
    #1の数
    b = a1 -c
 
    if c ==0 or b ==0:
        print(1)
    else:
 
        d = cmb(c+b,b)
        print(int(d%(10**9 +7)))

Submission status: Wrong Answer

Solution code:
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

# A=(+1,+2)をM回、B=(+2,+1)をN回
# X=M+2N, Y=2M+N => (X+Y)/3 = M+N
ans = 0
if (X+Y)%3==0:
    Z = int((X+Y)/3)
    for m in range(Z+1):
        n = Z-m
        if X==m+2*n:
            # これが遅い
            # ans = math.factorial(n+m) // (math.factorial(n)*math.factorial(m)) % (10**9+7)

            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 )

            ans = cmb(n+m,min(n,m),mod)

            print(int(ans))
            break
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys
 
 
def Knight():
    def check(d):
        if not ((d[0] % 3 == 0 and d[1] % 3 == 0) or (d[0] % 3 == 1 and d[1] % 3 == 2) or (d[0] % 3 == 2 and d[1] % 3 == 1)):
            print(0)
            sys.exit()
    d = list(map(int, input().split()))
    check(d)
 
    x = d[0]
    y = d[1]
    diff = x - y if x > y else y - x  # aとbの回数の差
    d2 = [x - diff, y - diff * 2] if x < y else [x - diff * 2, y - diff]
    r = d2[0] // 3
 
    def cmb(n, r, mod):
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod
 
    mod = 10**9+7  # 出力の制限
    N = x if x > y else y
    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(r*2+diff, r, mod)
 
    print(a)
 
 
Knight()

Submission status: Wrong Answer

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


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

n=a+b

p1=1
p2=1
p3=1

for i in range(n):
    p1=p1*(i+1)%mod

for i in range(max(a,b)):
    p2=p2*(i+1)%mod

    if i==b-1:
        p3=p2

if a+2*b==x and 2*a+b==y:
    print(p1*pow(p2,mod-2,mod)*pow(p2,mod-2,mod)%mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
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())

pat = 0.0

if(y > x):
    swap = y
    y = x
    y = swap

sub = x - y

if(x > 2 * y):
    pat = 0
elif((y - sub) % 3 != 0):
    pat = 0
else:
    k = (y - sub) / 3 * 2
    print(k)
    pat = cmb(int(k + sub), int(k / 2)) % (10 ** 9 + 7)


print(pat)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

def modPow(a, x, p):
	res = 1
	while x > 0:
		if x % 2 != 0:
			res = res * a % p
		a = a * a % p
		x = x // 2
	return res
 
def modInverse(a, p):
	return modPow(a, p - 2, p)
 
def modBinomial(n, k, p):
	numerator = 1
	for i in range(k):
		numerator = (numerator * (n - i)) % p
	denominator = 1
	for i in range(1, k + 1):
		denominator = (denominator * i) % p
	return (numerator * modInverse(denominator, p)) % p


if __name__ == "__main__":
	X, Y = map(int, input().split())
	if (X + Y) % 3 != 0:
		print("0")
	else:
		n = (X + Y) // 3
		k = Y - n
		print(modBinomial(n, k, MOD))

Submission status: Wrong Answer

Solution code:
import sys
G = list(map(int, input().split()))
total = G[0] + G[1]
if total % 3 != 0:
  print(0)
  sys.exit(0)

total //= 3
dis = G[0] - total

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

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

print(mod_comb_k(total, dis, mod))

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

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

n, rn = divmod(2 * x - y, 3)
m, rm = divmod(2 * y - x, 3)

if rn != 0 or rm != 0 or n < 0 or m < 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:
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 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

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(comb(n + m, n, mod))

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
from operator import mul
import math
X, Y = map(int, input().split())
mod = 10**9 + 7


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


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


if X == Y // 2 or Y == X//2:
    print(1)
    exit(0)

X, Y = max(X, Y), min(X, Y)

diff = X - Y
x = X - 2*(X-Y)
y = Y - (X-Y)

if x % 3 != 0:
    print(0)
    exit(0)
else:
    k = x // 3

    ans = cmb(2*k+X-Y, k)
    print(ans % mod)

Submission status: Wrong Answer

Solution code:
def mod_comb(n, r, m):
  n = n+1
  r = min(r, n-r)
  numer = 1
  denom = 1
  for i in range(1, r+1):
    numer = (numer * (n - i)) % m
    denom = (denom * i) % m
  output = numer * pow(denom, m-2, m) % m
  return output

x, y = map(int, input().split())
c_up = (2*y-x)/3
c_do = (2*x-y)/3
if c_up.is_integer() and c_do.is_integer():
  c_up = int(c_up)
  c_do = int(c_do)
  result = mod_comb((c_up+c_do), c_up, 7+10**9)
else:
  result = 0
print(result)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
a = 0
b = 0
for i in range(X + 1):
    N = i
    if (X - N) % 2 != 0 and N != X:
        continue
    M = int((X - N) / 2)
    
    x = N + 2 * M
    y = 2 * N + M
    if X == x and Y == y:
        a = N
        b = M
#print(a)

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

if a != 0:
    #print(a, b)
    ans = cmb(a + b,a) % (10**9+7)
    print(ans)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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

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 * 2
    ans = combinations_count(case_num, small_rem + 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:
import sys
import math

xy = input().split()
x, y = int(xy[0]), int(xy[1])

if not ((2*y-x)%3==0 and (2*x-y)%3==0):
    print(0)
    sys.exit()

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

#ans = math.factorial(a+b) // (math.factorial(a)*math.factorial(b))
minab = int(min(a, b))
mod = 1000000007

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

print(int(ncr(a+b, minab, mod)))

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) // 3
n2 = (2 * X - Y) // 3

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

Submission status: Wrong Answer

Solution code:
import numpy as np
def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

U = 10**6
MOD = 10**9 + 7
fact, invfact = make_fact(U,MOD)

X, Y = [int(x) for x in input().split()]
if (X+Y) % 3 != 0:
    print(0)
    exit()
r = (X+Y) // 3
k = X - r
print(fact[r] * invfact[r-k] % MOD * invfact[k] % MOD)

Submission status: Wrong Answer

Solution code:
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

# A=(+1,+2)をM回、B=(+2,+1)をN回
# X=M+2N, Y=2M+N => (X+Y)/3 = M+N
ans = 0
if (X+Y)%3==0:
    Z = int((X+Y)/3)
    for m in range(Z+1):
        n = Z-m
        if X==m+2*n:
            # これが遅い
            # ans = math.factorial(n+m) // (math.factorial(n)*math.factorial(m)) % (10**9+7)

            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 )

            ans = cmb(n+m,min(n,m),mod)

            print(int(ans))
            break
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
if (2*x-y)%3==0 and (2*y-x)%3==0:
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  mod = 1000000007
  
  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
 
      return [w[0],w[1]]

  
  def mod_inv(a,m):
      x = extgcd(a,m)[0]
      return (m+x%m)%m
  
  m = 10**9+7
  res = 1
  for i in range(1,l+k+1):
      res = res*i%m
  for i in range(1,l+1):
      res = res*mod_inv(i,m)%m
  for i in range(1,k+1):
      res = res*mod_inv(i,m)%m
  ans=res




  
else:
  ans=0 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def mod_combination(n, k, mod = 10 ** 9 + 7):
    def extended_gcd(a, b):
        if b == 0:
            return (a, 1, 0)
        d, x, y = extended_gcd(b, a % b)
        return (d, y, x - (a // b) * y)
    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 p * (extended_gcd(q, mod)[1] % mod) % mod

def main():
  x, y = na()
  if (x + y) % 3 != 0:
    print(0)
    return
  n = (x + y) // 3
  print(mod_combination(n, y - n))
 

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
        if n<0 or r<0:
            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:
from math import factorial
X, Y = map(int,input().split())

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    m = (2*X-Y)/3
    n = (2*Y-X)/3
    if n < 0 or m < 0:
        print(0)
        exit()
    else:
        ans = factorial(n+m)/(factorial(m)*factorial(n))
        ans /= MOD
print(ans)

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+1):
    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(i+1, x//2) % (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:
mod=10**9+7
x,y=map(int,input().split())
a=[0]*101
b=[0]*101
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,100):
        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:
X, Y = map(int, input().split())
a = 0
b = 0
for i in range(X + 1):
    N = i
    if (X - N) % 2 != 0:
        continue
    M = int((X - N) / 2)
    
    x = N + 2 * M
    y = 2 * N + M
    if X == x and Y == y:
        a = N
        b = M
#print(a)

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

if a != 0:
    #print(a, b)
    ans = cmb(a + b,a) % (10**9+7)
    print(ans)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
a = ((x+y)//3 + (x-y))//2
b = ((x+y)//3 - (x-y))//2

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

if a!=0 and b!=0:
    print(cmb(a+b,min(a,b))%(10**9+7))
else:
    print(0)

Submission status: Wrong Answer

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

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    m = (2*X-Y)/3
    n = (2*Y-X)/3
    if n < 0 or m < 0:
        print(0)
        exit()
    else:
        ans = factorial(n+m)/(factorial(m)*factorial(n))
        ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
a = ((x+y)//3 + (x-y))//2
b = ((x+y)//3 - (x-y))//2

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

print(a)
print(b)
if a!=0 and b!=0:
    print(cmb(a+b,min(a,b))%(10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
from scipy.misc import comb

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 = (int(i) for i in input().split())
af, a = math.modf((2*y-x)/3)
bf, b = math.modf((2*x-y)/3)
a, b = int(a), int(b)
if (af != 0) or (bf != 0):
    print(0)
else:
    aa, bb = min(a, b), max(a, b)
    print(comb(aa+bb, aa, 10**9+7))

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 and (big_num + small_num) % 3 == 0:
    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:
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 (X+Y) % 3 != 0 or X > 2*Y or Y > 2*X:
  print(0)

if i%1 != 0 or j%1 != 0 or i < 0 or j < 0:
  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)