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 math
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 mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
X,Y = map(int,input().split())
div = 1000000007
if (X+Y)%3 != 0:
    print(0)
else:
    count = (X+Y)//3
    if count > X or count > Y :
        print(0)
    else:
        leftX = X-count
        p = 1
        for i in range(count):
            p *=(i+1)
            p = p%div
        q = 1
        for i in range(leftX):
            q *=(i+1)
            q = q%div
        r = 1
        for i in range(count-leftX):
            r *=(i+1)
            r = q%div
        print((p*mod_inv(q,div)*mod_inv(r,div))%div)

Submission status: Wrong Answer

Solution code:
import math

def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        b, a = a, b
        u -= t * v
        v, u = u, v
    u = u % m
    if (u < 0):
        u += m
    return u

def fact(n):
    if n <= 1:
        return 1
    ret = 1
    for i in range(2, n + 1):
        ret *= i
        ret = ret % (10 ** 9 + 7)
    
    return ret

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

nx, ny = (2 * y - x) / 3, (2 * x - y) / 3

if nx.is_integer() and ny.is_integer() and (nx > 0.0 and ny > 0.0):
    n2x = int(nx)
    n2y = int(ny)
    gnx = modinv(fact(n2x), 10 ** 9 + 7)
    gny = modinv(fact(n2y), 10 ** 9 + 7)
    print((fact(n2x + n2y) * gnx % (10 ** 9 + 7)) * gny % (10 ** 9 + 7))
else:
    print('0')

Submission status: Wrong Answer

Solution code:
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
import sys
sys.setrecursionlimit(1000000000)
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())
if (x>3*y and 3*x<y) or (x+y)%3!=0:
    #print(1)
    print(0)
else:
    print(comb((x+y)//3, min(x,y)-(x+y)//3,10**9+7))

Submission status: Wrong Answer

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


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * mod_inverse(q, mod) % mod


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# aで割りたいときはa^(p-2)をかければよい（pは素数かつmodで使うやつ）
def mod_inverse(a, mod):
    return mod_pow(a, (mod - 2), mod)


# 移動1, 2を使う回数
n, m = 0, 0

for i in range(10 ** 6):
    if (X - i) // 2 == Y - 2 * i == 0 or (X - i) // 2 == Y - 2 * i != 0:
        n = i
        m = Y - 2 * n
        break
else:
    print(0)
    exit()

print(mod_cmb(n + m, n, mod))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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

# nCr
def nCr(n,r):
  if n<r:
    return 0
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def main():
  x,y=LI()

  sm=x+y
  if sm%3!=0:
    return 0

  cnt=sm//3
  ac=cnt//2-((x-y)//2)
  bc=cnt-ac

  # print(ac)
  # print(bc)

  return cmb(cnt,ac)%mod


# main()
print(main())

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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
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

X, Y = MAP()

x, y = 0, 0
while (X!=0 or Y!=0):
	if X >= 3 and Y >= 3:
		x += 1
		y += 1
		X -= 3
		Y -= 3
	else:
		if X-1 == 0 and Y-2==0:
			y += 1
			break
		elif X-2==0 and Y-1==0:
			x += 1
			break
		else:
			print(0)
			sys.exit()

H = 10**6//2
W = 10**6//2
factorial = [1]
for i in range(1, H+W):
	factorial.append(factorial[i-1] * i % mod)


def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, int(y/2)) ** 2 % mod
	else:
		return power(x, int((y-1)/2)) ** 2 * x % mod
def C(n, r):
	return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod

x_inv = [0] * (H+W)
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(H+W-2, -1, -1):
	x_inv[i] = x_inv[i+1] * (i+1) % mod

if x == 0 or y == 0:
	print(1)
else:
	print(C(x+y, y))

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7


def pwr(p, q):
    if q == 1:
        return p%mod
    elif q % 2 == 0:
        return (pwr(p, q//2)%mod)**2%mod
    else:
        return (pwr(p, q//2)%mod)**2*p%mod

x, y = map(int,input().split())
if (2*x-y)%3 != 0 or (2*y-x)%3 != 0:
    print(0)
elif x == 2 and y == 1:
    print(1)
elif x == 1 and y == 2:
    print(1)
else:
    n = (2*x-y)//3
    m = (2*y-x)//3

    s1 = 1
    s2 = 1
    for i in range(m+1, n+m+1):
        s1 *= i
        s1 %= mod
    for i in range(n):
        s2 *= (i+1)
        s2 %= mod

    print(s1*pwr(s2, mod-2)%mod)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def make_nCr_mod(max_n=2 * 10**5, mod=10**9 + 7):
    fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)
    fact[0] = 1
    for i in range(max_n):
        fact[i + 1] = fact[i] * (i + 1) % mod

    inv_fact[-1] = pow(fact[-1], mod - 2, mod)
    for i in reversed(range(max_n)):
        inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

    def nCr_mod(n, r):
        res = 1
        while n or r:
            a, b = n % mod, r % mod
            if a < b:
                return 0
            res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
            n //= mod
            r //= mod
        return res

    return nCr_mod


def main():
    x, y = map(int, input().split())

    t1 = t2 = min(x // 3, y // 3)

    x -= 3 * t1
    y -= 3 * t1

    if (x % 2) and (y % 2):
        print(0)
        return
    elif x // 2 == y:
        t1 += x // 2
    elif y // 2 == x:
        t2 += y // 2
    else:
        print(0)
        return

    nCr = make_nCr_mod(t1 + t2)
    print(nCr(t1 + t2, t1))


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

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


a,s=map(int,input().split())
if (2*a-s)%3==0:
  n=(a+s)//3
  r=(2*a-s)//3
  print((cmb(n,r))%(10**9+7))
else:print(0)

Submission status: Wrong Answer

Solution code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
x,y = map(int,input().split())
if (x+y)%3 != 0:
  print(0)
else:
  n = (x+y)//3
  r = min(abs(2*n-x),abs(n-x))
  a = cmb(n,r,mod)
  print(a)

Submission status: Wrong Answer

Solution code:
import math
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())
X = x
Y = y
ans = 0
while True:
    x -= 2
    y -= 1
    # print(x, y)
    if y == x * 2:
        ans = 1
        break
    elif x < 0 or y < 0:
        ans = 0
        break
# print(1, ans, x, y)
xx = 0
yy = 0
if ans == 0:
    print(ans)
else:
    xx = X - x
    xx //= 2
    yy = y // 2
# print(xx, yy)
print(comb(xx + yy, xx, 10 ** 9 + 7))
# print(xx, yy, x, y)

Submission status: Wrong Answer

Solution code:
import numpy as np
v=np.array(list(map(int, input().split())) )
mod = 10**9 +7

def cmb(n, r,mod):
    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 = (result*int(numerator[k]))%mod

    return result
  
A = np.array([[2,1],[1,2]])
inv_A = np.linalg.inv(A)

k = np.dot(inv_A,v)

if k[0]%1 == 0 and k[1]%1 == 0:
  print(cmb(int(k[0]+k[1]),int(k[0]),mod))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from math import factorial
MOD = 10 ** 9 + 7

#互いに素な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は互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
time = (X+Y) // 3
diff = X - Y
if diff > time:
    print(0)
    exit()
x_time = (time+diff) // 2
res = 1
for i in range(1,time+1):
    res = res*i%MOD
for i in range(1,x_time+1):
    res = res*mod_inv(i,MOD)%MOD
for i in range(1,time-x_time+1):
    res = res*mod_inv(i, MOD)%MOD
print(res)
#print(mod_combination(time, x_time, MOD))

Submission status: Wrong Answer

Solution code:
import math
#ABC共通 
abc = input()
abc_list = abc.split(' ')
 
#問題用変数
abc_intlist = []
 
#inputを整数化
for c1 in abc_list:
  abc_intlist.append(int(c1))
 
#以下処理
tesuu = (abc_intlist[0]+abc_intlist[1])/3
diff = max(abc_intlist)-min(abc_intlist)
k = (tesuu-diff)/2
 
#a = abc_intlist[0]
#b = abc_intlist[1]
#x = abc_intlist[2]
#if (a**2)*b<2*x:
#    print(math.degrees(math.atan(  2*(b-x/(a**2))/a  )  ))
#else:
#    print(math.degrees(math.atan(  a*(b**2)/(2*x))  ))
 
if (tesuu-diff)%2==1:
  print(0)
elif k<0:
  print(0)
else:
  #print(int(math.factorial(tesuu)/(math.factorial(k)*math.factorial(tesuu-k)))%(10**9+7))
  print(1)

Submission status: Wrong Answer

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

n, m = 0, 0
for i in range(x+1):
    j = (x - i)/2
    if 2*i + j== y:
        n, m = int(i+j), int(i)

import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

print(C(n, m)%(10**9 + 7))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10000)

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

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

    return result




def mod_combination(n, k, mod):
    # nCk (mod m)
    def mod_permutation(n, k, mod):
        if n<=k:
            return 1
        else:
            return (n * mod_permutation(n-1,k,mod))%mod

    def mod_inv_permutation(k, mod):
        k, mod = int(k), int(mod)
        if k<=1:
            return 1
        else:
            return (pow(k,mod-2,mod) * mod_inv_permutation(k-1, mod))%mod

    return (mod_permutation(n,n-k,mod) * mod_inv_permutation(k, mod))%mod


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

ans = 0
if (x + y) % 3 != 0:
    ans = 0
else:
    a = (x + y) // 3
    b = (2*x - y) // 3
    ans = cmb(a,b) % (10 ** 9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
words = lambda t : list(map(t, input().split()))
x,y = words(int)

MOD = 10**9+7

def modpow(a,b,mod):
    if b == 0: return 1
    if b % 2 == 0:
        h = modpow(a, b//2, mod)
        return (h * h) % mod
    else:
        return (a * modpow(a, b-1, mod)) % mod

def mod_comb(a,b,mod):
    #print(a,b)
    if a-b < b: return mod_comb(a,a-b,mod)
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a-i
        ans_div *= i+1
        ans_mul %= mod
        ans_div %= mod
    return (ans_mul * modpow(ans_div, mod-2, mod)) % mod


if (x+y) % 3 != 0:
    print(0)
else:
    k = (x + y) // 3
    #print(k, k, y-k)
    ans = mod_comb(k,y-k,MOD)
    print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

MOD = 10 ** 9 + 7

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

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

if 2 * a + b != X or a + 2 * b != Y:
    print(0)
    exit()

f, invf = [1] * maxf, [1] * maxf

for i in range(1, maxf):
    f[i] = f[i - 1] * i % MOD
invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD)
for i in range(maxf - 1, 0, -1):
    invf[i - 1] = invf[i] * i % MOD

comb = lambda a, b: f[a] * invf[b] * invf[a - b] % MOD

print(comb(a + b, b) % MOD)

Submission status: Wrong Answer

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


# modしながらコンビネーションを求める
def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * mod_inverse(q, mod) % mod


# modしたa^bを求める
def mod_pow(a, p, mod):
    if p == 0:
        return 1
    elif p % 2 == 1:
        return a * mod_pow(a, p - 1, mod)
    else:
        return (mod_pow(a, p // 2, mod) % mod) ** 2 % mod


# aで割りたいときはa^(p-2)をかければよい（pは素数かつmodで使うやつ）
def mod_inverse(a, mod):
    return mod_pow(a, (mod - 2), mod)


# 移動1, 2を使う回数
n, m = 0, 0

for i in range(10 ** 6):
    if (X - i) // 2 == Y - 2 * i != 0:
        n = i
        m = Y - 2 * n
        break
else:
    print(0)
    exit()

print(mod_cmb(n + m, n, mod))

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
	print(0)
	sys.exit()

tot = (X+Y) // 3

y = abs(tot-X)
x = tot - y

if x == 0 or y == 0:
	print(1)
	sys.exit()

ans = 1
for i in range(y+1, tot+1):
	ans *= i
	ans %= mod

for i in range(1,x+1):
	ans *= pow(i, mod-2, mod)
	ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7
#a(1,2)+b(2,1)
if (2 * Y - X) % 3 != 0:
  ans = 0
  print(ans)
  quit()
if (2 * X - Y) % 3 != 0:
  ans = 0  
  print(ans)
  quit()

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

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

ans = cmb(a + b,a)

print(int(ans % MOD))

Submission status: Wrong Answer

Solution code:
import math

def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        b, a = a, b
        u -= t * v
        v, u = u, v
    u = u % m
    if (u < 0):
        u += m
    return u

def fact(n):
    if n <= 1:
        return 1
    ret = 1
    for i in range(2, n + 1):
        ret *= i
        ret = ret % (10 ** 9 + 7)
    
    return ret

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

nx, ny = (2 * y - x) / 3, (2 * x - y) / 3

if nx.is_integer() and ny.is_integer() and nx * ny > 0.0:
    n2x = int(nx)
    n2y = int(ny)
    gnx = modinv(fact(n2x), 10 ** 9 + 7)
    gny = modinv(fact(n2y), 10 ** 9 + 7)
    print((fact(n2x + n2y) * gnx % (10 ** 9 + 7)) * gny % (10 ** 9 + 7))
else:
    print('0')

Submission status: Wrong Answer

Solution code:
x, y = map(int,input().split())
cnt = 0
for i in range(0, x + 1):
    for j in range(0, y + 1):
        if (i * 1 + j * 2) == x and (i * 2 + j * 1) == y:
            cnt += 1
print(cnt * 2)

Submission status: Wrong Answer

Solution code:
x, y = [int(i) for i in input().split()]
a = (2 * x - y) / 3
b = (-x + 2 * y) / 3
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


if a % 1 != 0 or b % 1 != 0:
    print(0)
else:
    ans = cmb(int(a+b), int(a)) % mod
    print(ans)
    #print(int(a_b / _a / _b % (10**9+7)))

Submission status: Wrong Answer

Solution code:
import functools, sys

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

mod = 10 ** 9 + 7

def modpow(x, y):
    z = 1
    while y > 0:
        if y % 2 == 0:
            x = (x * x) % mod
            y //= 2
        else:
            z = (z * x) % mod
            y -= 1
    return z

def modinv(x):
    return modpow(x, mod - 2)

def c(n, r):
    fct = [None] * (n + 1)
    fct[0] = 1
    for i in range(1, n + 1):
        fct[i] = fct[i - 1] * i % mod
    return fct[n] * (modinv(fct[n - r]) * modinv(fct[r]) % mod) % mod

def f():
    a = 0
    while True:
        p = x - a
        q = y - 2 * a
        if p <= 0 or q <= 0:
            return 0
        if p % 2 == 0 and p // 2 == q:
            b = q
            break
        a += 1
    
    print(a, b)
    return c(a + b, a)

print(f())

Submission status: Wrong Answer

Solution code:
import math
import sys

sys.setrecursionlimit(1000010)
(x,y) = map(int,input().split())

m=10**9 + 7 

def mod_combination(n, k, mod):
    # nCk (mod m)
    def mod_permutation(n, k, mod):
        if n<=k:
            return 1
        else:
            return (n * mod_permutation(n-1,k,mod))%mod

    def mod_inv_permutation(k, mod):
        k, mod = int(k), int(mod)
        if k<=1:
            return 1
        else:
            return (pow(k,mod-2,mod) * mod_inv_permutation(k-1, mod))%mod

    return (mod_permutation(n,n-k,mod) * mod_inv_permutation(k, mod))%mod


if ( 2 * y - x ) % 3 != 0:
    print(0)
    exit(0)
if ( 2 * x - y ) % 3 != 0:
    print(0)
    exit(0)

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

if x < 0  or y < 0 : 
    print(0)
    exit(0)

print(mod_combination(a+b,a,m))

Submission status: Wrong Answer

Solution code:
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom

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 = total//2 - (G[0] - G[1]) //2

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

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7


def pwr(p, q):
    if q == 1:
        return p%mod
    elif q % 2 == 0:
        return (pwr(p, q//2)%mod)**2%mod
    else:
        return (pwr(p, q//2)%mod)**2*p%mod

x, y = map(int,input().split())
if (2*x-y)%3 != 0 or (2*y-x)%3 != 0:
    print(0)
else:
    n = (2*x-y)//3
    m = (2*y-x)//3

    s1 = 1
    s2 = 1
    for i in range(m+1, n+m+1):
        s1 *= i
        s1 %= mod
    for i in range(n):
        s2 *= (i+1)
        s2 %= mod

    print(s1*pwr(s2, mod-2)%mod)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
from math import sqrt
input = sys.stdin.readline
mod = 10 ** 9 + 7

X, Y = map(int, input().split())
a_3 = -X + 2 * Y
b_3 = 2 * X - Y
if a_3 % 3 != 0 or b_3 % 3 != 0:
    print(0)
    exit()

a = a_3 // 3
b = b_3 // 3

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(1000000)
print(comb(a + b, a))

Submission status: Wrong Answer

Solution code:
MAX = 10**6 + 100
fac = [1]*(MAX+1)
mod = 10**9+7
for i in range(1,MAX+1):
    fac[i] = (fac[i-1]*i)%mod
rev_m = [1]*(MAX+1)
rev_m[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
    rev_m[i-1] = (rev_m[i]*i)%mod
def Comb(n,k):#nCk
    return (fac[n]*rev_m[k]*rev_m[n-k])%mod
X, Y = map(int, input().split())
if (X+Y)%3!=0:
  print(0)
else:
  m = (X+Y)//3
  a = (2*Y-X)//3
  b = (2*X-Y)//3
  print(Comb(m,a))

Submission status: Wrong Answer

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

P_MOD = 10 ** 9 + 7

def myinv(arg):
    bit = []
    tmp = P_MOD - 2
    for i in range(64):
        if tmp < 1: break
        bit.append(tmp % 2)
        tmp >>= 1
    N_bit = len(bit)
    #
    ret = 1
    arg_tmp = arg
    for i in range(N_bit):
        if bit[i] == 1:
            ret = (ret * arg_tmp) % P_MOD
        arg_tmp = (arg_tmp * arg_tmp) % P_MOD
    #
    return ret

if ((2 * X - Y) % 3 > 0) or ((2 * Y - X) % 3 > 0):
    print(0)
else:
    num_a = min((2 * Y - X) // 3, (2 * X - Y) // 3)
    num_b = max((2 * Y - X) // 3, (2 * X - Y) // 3)
    #
    ans = 1
    for i in range(num_a):
        ans = (ans * (num_b + i + 1)) % P_MOD
    for i in range(num_a):
        ans = (ans * myinv(i + 1)) % P_MOD
    #
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
mod = 10**9+7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
	print(0)
	sys.exit()

tot = (X+Y) // 3

y = abs(tot-X)
x = tot - y

if x == 0 or y == 0:
	print(1)
	sys.exit()

ans = 1
for i in range(x+1, tot+1):
	ans *= i
	ans %= mod

for i in range(1,x+1):
	ans *= pow(i, mod-2, mod)
	ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
def comb(a,b,m):
	if b == 0 or b == a:
		ret = 1
	else:
		ret = 1
		for i in range(a-b+1,a+1):
			ret = (ret * i) % m
		for i in range(1,b+1):
			ret = (ret * pow(i,m-2,m) ) % m
	return ret % m

mod = 10**9+7
x, y = [ int(v) for v in input().split() ]

ans = 0
if (2*x-y) % 3 == 0 and (2*y-x) % 3 == 0:
    x, y = (2*x-y) // 3, (2*y-x) // 3
    ans = comb(x+y,y,mod)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
MOD = 10 ** 9 + 7

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

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

x = X - (X + Y) // 3
y = Y - (X + Y) // 3

if x < y:
    x, y = y, x

# tmp = math.factorial(y)
tmp = 1
for i in range(1, y + 1):
    tmp *= i
    tmp %= MOD

ans = 1
for i in range(x + 1, x + y + 1):
    ans *= i
    ans %= MOD

def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u

tmp = modinv(tmp, MOD)

ans *= tmp

ans %= MOD

print (ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
M = 10**9 + 7
x, y = map(int, input().split())

# (1, 2) * a + (2, 1) * b = (x, y)
#
# a + 2 * b = x
# 2 * a + b = y
# b = y - 2 * a
# a = x - 2 * b
# b = y - 2 * (x - 2 * b)
#   = y - 2 * x + 4 * b
# 3 * b = - y + 2 * x

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

def fact(n):
    ans = n
    for i in range(1, n):
        ans *= i
        if ans >= M:
            ans %= M
    return ans

def pm(value, n):
    if n == 0:
        return 1
    if n % 2:
        return pm(value, n - 1) * value % M
    else:
        return pm(value, n // 2) ** 2 % M

# A * B ^ (M-2)
print(fact(a + b) * pm(fact(a) * fact(b) % M, M - 2) % M)

Submission status: Wrong Answer

Solution code:
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
  
X, Y=map(int, input().split())
a=-X/3+2*Y/3
b=2*X/3-Y/3
if not (a.is_integer() and b.is_integer() and a>=0 and b>=0):
  print(0)
else:
  print(comb(int(a+b), int(a), mod))