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

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

if((2*Y-X)%3 != 0 or (2*X-Y)%3 != 0):
    print("0")
else:
    a =  int((2*Y-X) / 3)
    b =  int((2*X-Y) / 3)

    if a == 0: 
        print(1)
    if a == 1:
        print(a+b)
    else:
        numerator = [b + k + 1 for k in range(a)]
        denominator = [k + 1 for k in range(a)]

        for p in range(2,a+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (b) % p
                for k in range(p-1,a,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

fac = [0] * (10**6+5)
ifac = [0] * (10**6+5)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
X ,Y = map(int, input().split())
n = 2 * Y - X
m = 2 * X - Y
a = 0
if n % 3 != 0:
    print(0)
elif m % 3 != 0:
    print(0)
elif m < 0:
    print(0)
elif n < 0:
    print(0)
else:
    a1 = math.factorial(n/3+m/3)
    a2 = math.factorial(n/3)*math.factorial(m/3)
    a = a1 // a2
print(a % (10**9+7))

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%mod)
    fact_inv.append(pow(new_fact,mod-2,mod)%mod)

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

print(mod_comb_k(total, dis, mod))

Submission status: Wrong Answer

Solution code:
import operator as op
from functools import reduce



def fact(n):
    x = n
    t = 1
    while(x>0):
        t *= x
        t %= (10**9+7)
        x -= 1
    return t



valid = True
zero = False
n = sorted([int(i) for i in input().split()])
a = n[0]
b = n[1]
x = 0
y = 0

x += b-a
t = a
a -= b-a
b -= 2*(b-t)


if(a==0 and b==0):
    zero = True
if(a>=0 and b>=0 and a%3==0):
    x += a//3
    y += a//3
else:
    valid = False

if(zero):
    print(x)
elif(valid):
    print ((fact(x+y)*pow(fact(x)*fact(y), 10**9+5, 10**9+7)) % (10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
import sys
sys.setrecursionlimit(100000)

if (2*a[0]- a[1])%3 != 0:
    print(0)
else:
    if (2*a[1] - a[0])%3 != 0:
        print(0)
    else:
        if a[0] == 0 or a[1] == 0:
            print(0)
        else:
            x = (2*a[1] - a[0])//3
            y = (2*a[0]- a[1])//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
        
            print((cmb(x+y,x))%(10**9 + 7))

Submission status: Wrong Answer

Solution code:
import itertools
import sys
from math import factorial
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

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

    return result

X, Y = map(int, input().split())
  
i = (2/3)*X - (1/3)*Y
j = (2/3)*Y - (1/3)*X

if i%1 != 0 or j%1 != 0 or i < 0 or j < 0:
  print(0)
  sys.exit()

n = i + j

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

Submission status: Wrong Answer

Solution code:
import math
X, Y = list(map(int, input().split()))
k = (2*Y-X)//3
l = Y - 2*k
flag = 0
if (2*Y-X)%3 != 0:
    flag = 1
if k < 0:
    flag = 1
if l < 0:
    flag = 1
# 行けない場合はflagが1になる
# print(int((math.factorial(k+l)/math.factorial(k)/math.factorial(l))%(10**9+7)))
if k > l:
    temp = k
    k = l
    l = k
if flag == 1:
    print(0)
else:
    ans = 1/math.factorial(k)
    for ii in range(k):
        ans = (ans*(k+l-ii))%(10**9+7)
    print(int(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 i%1 != 0 or j%1 != 0 or i == 0 or j == 0:
  print(0)
  sys.exit()

n = i + j

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

Submission status: Wrong Answer

Solution code:
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 #出力の制限x
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().strip().split())

min_num = min(X,Y)
z = min_num//3

tX = z * 3
tY = z * 3
cA = z
cB = z

rx = X - tX
ry = Y - tY
if rx == 0 and ry == 0:
    print(cmb(cA+cB, cA, mod))
    exit(0)

if rx != 0 and ry / rx == 2:
    cA += rx
elif ry != 0 and rx / ry == 2:
    cB += ry
else:
    print(0)
    exit(0)

print(cmb(cA+cB, cA, mod))
# 6.0

Submission status: Wrong Answer

Solution code:
import math
mod = (10**9) + 7

def kaijo(n):
    result = 1
    for i in reversed(range(1,n+1)):
        result = (result * i) % mod
    return result
def combinations_count(n, r):
    return (kaijo(n)) //(kaijo(n - r) * kaijo(r))

def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret


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

if (X+Y)%3 == 0:
    if X > Y:
        diff = X - Y
        all_num = (X+Y)//3
        count_2 = all_num//2 + diff//2
    elif Y > X:
        diff = Y - X
        all_num = (X+Y)//3
        count_2 = all_num//2 + diff//2
    else:
        all_num = (X+Y)//3
        count_2 = all_num//2

    print(nCk(all_num,count_2))
else:
    print(0)

Submission status: Wrong Answer

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

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 )

if X>Y:
    if X % 2 == 0:
        if Y - X//2 == 0:
            print(1)
            exit()
        else:
            print(0)
            exit()
    else:
        if Y - X//2 == 2:
            print(X//2+1)
            exit()
        else:
            print(0)
            exit()

elif X<Y:
    if Y % 2 == 0:
        if X - Y//2 == 0:
            print(1)
            exit()
        else:
            print(0)
            exit()

    else:
        if X - Y//2 == 2:
            print((Y//2)+1)
            exit()
        else:
            print(0)
            exit()
        
else:
    if X % 3 == 0:
        print(cmb(2*(X//3),X//3,mod))
        exit()
    else:
        print(0)
        exit()

Submission status: Wrong Answer

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

if (x+y)%3 !=0 or max(x,y)/min(x,y)>2:
    print(0)
    exit()

n =int((x+y)/3)
maxm = round((n+1)/2)
m= n*2 - max(x,y) +1
print(n,m)


if m==1:
    print(1)
elif m==2:
    print(int(m))
else:
    ss = numpy.cumsum(n)
    print(ss[0])

Submission status: Wrong Answer

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

# nCr
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(X+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:
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())

mm = (2*Y - X) / 3
nn = (2*X - Y) / 3

ans = 0

if mm.is_integer() and nn.is_integer():
    mm = int(mm)
    nn = int(nn)
    ans =comb(mm+nn, nn, 10**9+7)
      
print(ans)

Submission status: Wrong Answer

Solution code:
import math

x,y = map(int,input().split())
m = x//3
n = y//3
a = 1
if x%3==0 & y%3==0:	#(m+n)!/m!n!
	if m>n:
		for i in range(m+1,m+n+1):
			a *= i
		print(int(a/math.factorial(n)%1000000007)) 
	else:
		for i in range(n+1,m+n+1):
			a *= i
		print(int(a/math.factorial(m)%1000000007)) 
elif x%3==1 & y%3==2:#((m+1)+n)!/(m+1)!n!
	if m>n:
		for i in range(m+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(n)%1000000007))
	else:
		for i in range(n+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(m+1)%1000000007))
elif x%3==2 & y%3==1:#(m+(n+1))!/m!(n+1)!
	if m>n:
		for i in range(m+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(n+1)%1000000007))  
	else:
		for i in range(n+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(m)%1000000007))  
else:
	print(0)

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:
def main():
  x,y=map(int,input().split())
  mod=10**9+7

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

    result=0.0
    bunbo=1
    bunshi=1

    for i in range(int(a)):
      bunbo=bunbo*(a+b-i)
      bunshi=bunshi*(1+i)
      #print(bunbo,bunshi)
    result=bunbo/bunshi%mod
    print(int(result))

  else:
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if X * 2 < Y or X > Y * 2:
    print(0)
    exit()
xmax = 0
ymax = 0
while True:
    if (X + xmax) >= (Y - xmax) * 2:
        break
    xmax += 1

while True:
    if (X - ymax) * 2 <= (Y + ymax):
        break
    ymax += 1

if (X + xmax) == (Y - xmax) * 2 and (X - ymax) * 2 == (Y + ymax):
    print(xmax)
    print(ymax)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))


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])
            #print(result)
            result%=(10**9+7)

    return result


X,Y=acinput()

import numpy as np
from numpy.linalg import solve
 

x=solve([[1,2],[2,1]],[X,Y])

#print(x)

if np.all(x%1.0==0):
    print(cmb(int(np.sum(x)),int(np.min(x)))%(10**9+7))

else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

x,y = map(int,input().split())
m = x//3
n = y//3
print(m,n)

a = 1
if x%3==0 & y%3==0:	#(m+n)!/m!n!
	if m>n:
		for i in range(m+1,m+n+1):
			a *= i
		print(int(a/math.factorial(n)%1000000007)) 
	else:
		for i in range(n+1,m+n+1):
			a *= i
		print(int(a/math.factorial(m)%1000000007)) 
elif x%3==1 & y%3==2:#((m+1)+n)!/(m+1)!n!
	if m>n:
		for i in range(m+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(n)%1000000007))
	else:
		for i in range(n+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(m+1)%1000000007))
elif x%3==2 & y%3==1:#(m+(n+1))!/m!(n+1)!
	if m>n:
		for i in range(m+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(n+1)%1000000007))  
	else:
		for i in range(n+1,m+n+1):
			a *= i
		print(int(a*(m+n+1)/math.factorial(m)%1000000007))  
else:
	print(0)

Submission status: Wrong Answer

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

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

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

    return result

X, Y = map(int, input().split())
N = X + Y
C21 = 0
C12 = 0

ans = 0
if (N) % 3 != 0 or X >= 2*Y or Y >= 2*X:
  print(ans)
else:
  while N != 0:
    if X >= 333333 and Y >= 333333:
      C21 += 111111
      C12 += 111111
      X -= 333333
      Y -= 333333
      N -= 666666
    elif X >= Y:
      C21 += 1
      X -= 2
      Y -= 1
      N -= 3
    else:
      C12 += 1
      X -= 1
      Y -= 2
      N -= 3
  a = cmb(C21 + C12, C21)
  print(a % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
BIGMOD = 10**9+7

def modPow(x,n):
    ans = 1
    while n >= 1:
        if bin( n & 1)==bin(1):
            ans = (ans*x) % BIGMOD
        x = x * x % BIGMOD
        n = n>>1
    return ans % BIGMOD

def modFact(N):
    fact = []
    fact.append(1) #0! = 1
    for i in range(1,N+1):
        a = fact[i-1]*i % BIGMOD
        fact.append(a)
    return fact

def modInvFact(fact):
    invFact = []
    for i in range(1,N+2):
        a = modPow(fact[i-1],BIGMOD-2)
        invFact.append(a)
    return invFact

def modPlus(a,b):
    return (a + b) % BIGMOD

def modMinus(a,b):
    if a-b >= 0:
        return (a - b) % BIGMOD
    else:
        return (a - b + BIGMOD)
    
def modMulti(a,b):
    return a * b % BIGMOD

# fact(n),invFact(r),invFact(n-r)
def nCr(fact,invFact,n,r):
    return (fact[n] * invFact[r] * invFact[n-r] ) %BIGMOD

def nPr(fact,invFact,n,r):
    return(fact[n] * invFact[r])%BIGMOD

X,Y = map(int,input().split())
MIN = min(X,Y)
i = 0
b = 10**6
# b = 3
dp = [1]*(b+7)
for i in range(b+7):
    pi = i+1
    if (pi+1  <= X and pi+2 <= Y) and (pi+2 <= X and pi+1 <=Y):
        dp[i+1]=dp[i]*2 %BIGMOD
    elif (pi+2 <= X and pi+1 <=Y) or (pi+2 <= X and pi+1 <=Y):
        dp[i+1]=dp[i]*1 %BIGMOD
    else:
        for j in range(i+1,b+7):
            dp[j] = -1
        break
        
ans = 1
for i in range(b):
    if dp[i]==-1:
        break
    ans = dp[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
import math
X,Y=list(map(int,input().split()))
mod=10**9+7
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y/2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))
if X>Y:
    big=X
    small=Y
else:
    big=Y
    small=X


if (small+big)%3!=0:
    print(0)
    exit()
if small*2==big:
    print(small%mod)
    exit()
    
    
diff=big-small
big-=diff*2
small-=diff
if big<0 or big!=small:
    print(0)
    exit()

num=big//3
tmp=1
for i in range(num*2+diff):
    tmp*=(i+1)
    tmp%=mod
bunsi=tmp

bunbo=1
tmp=1
for i in range(num):
    tmp*=(i+1)
    #tmp%=mod
bunbo*=tmp
tmp=1
for i in range(num+diff):
    tmp*=(i+1)
    #tmp%=mod
bunbo*=tmp
#ans=div(bunsi,bunbo)
ans=bunsi/bunbo
print(ans%mod)

Submission status: Wrong Answer

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

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

ans = 0

def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

if a%1==0 and b%1==0:
    ans = mod_Combination(int(a + b), int(a), 10**9 + 7)
print(ans%(10**9 + 7))

Submission status: Wrong Answer

Solution code:
import math

N = 10 ** 9 + 7
X, Y = map(int, input().split())
B3 = 2 * X - Y
if B3 % 3:
    print(0)
    exit()
B = B3 // 3
A = X - 2 * B
if A < 0:
    print(0)
    exit()

# count = 1
# for i in range(A + 1, A + B + 1):
#     count *= i
# for i in range(1, A + 1):
#     count //= i
# print(count % N)

# def combinations_count(n, r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#
# print(combinations_count(A + B, A) % N)

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(cmb(A + B,A) % N)

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial
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()]
p = (X, 2 * X)
n1 = X
n2 = 0
f = False
while p != (X, Y):
    n1 -= 2
    n2 += 1
    p = (n1 + 2 * n2, 2 * n1 + n2)
    if p[1] <= 0:
        break
else:
    f = True
if f:
    print(combination(n1 + n2, n1))
else:
    print(0)

Submission status: Wrong Answer

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

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 = math.factorial(a1) //math.factorial(b) //math.factorial(c)
        print(int(d%(10**9 +7)))

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
if (X + Y)%3 != 0:
    print(0)
    exit()
sub = abs(X-Y)
print((2**((X+Y)//2//3)-sub)%(10**9+7))

Submission status: Wrong Answer

Solution code:
inf = 10**9+7
a = 1
import sys

def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i 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 * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
if x == 2*y:
    print(1)
    sys.exit()
if y == 2*x:
    print(1)
    sys.exit()
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break

if x < 0 or y < 0:
    print(0)
    sys.exit()
if a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))

Submission status: Wrong Answer

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

a = x+y
a1 = a//3
if a % 3 != 0:
    print(0)
    
else:
    #2の数
    c = x % (a1)
    #1の数
    b = a1 -c
    print(b,c)
    if c ==0 or b ==0:
        print(1)
    else:

        d = math.factorial(a1) //math.factorial(b) //math.factorial(c)
        print(int(d%(10**9 +7)))

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):
        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 = 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:
X, Y = map(int, input().split())
MOD = 10**9+7
N = 134*10**4

def power(base, num):
    if num == 0:
        return 1
    elif num % 2==0:
        return power(base, num//2) **2 % MOD
    elif num==1:
        return base % MOD
    else:
        return power(base, num//2) **2 * base % MOD
    
fact = [0 for i in range(N)]
inv_fact = [0 for i in range(N)]
 
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i-1] * i % MOD

inv_fact[N-1] = power(fact[N-1], MOD-2)
for i in range(1, N):
    inv_fact[N-1-i] = inv_fact[N-i] * (N-i) % MOD
 
def comb(x,y):
    return (fact[x] * inv_fact[y])%MOD * inv_fact[x-y] % MOD

if (2*X-Y)%3==0 and (-X+2*Y)%3==0 and 2*X-Y>0 and -X+2*Y>0:
    a = (2*X-Y) //3
    b = (-X+2*Y)//3
    ans = comb(a+b, min(a,b)) % MOD

    print(ans)

    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
X=(2/3)*x-(1/3)*y
Y=-(1/3)+(2/3)*y
if X<0 or Y<0 :
  print(0)
elif (x%3==0 and y%3==0) or (x%3==1 and y%3==2) or (x%3==2 and y%3==1):
  X=int(X)
  Y=int(Y)
  Xkai=1
  Ykai=1
  XYkai=1
  for i in range(1,X+1):
    Xkai=Xkai*i
  for i in range(1,Y+1):
    Ykai*=i
  for i in range(1,X+Y+1):
    XYkai*=i
  C=XYkai/(Xkai*Ykai)
  D=C%(10**9+7)	
  print(int(D))

Submission status: Wrong Answer

Solution code:
import sys

X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

n1 = (2 * X - Y)
n2 = (2 * Y - X)

if n1 == 0 and n2 == 0:
    print(0)
    sys.exit()

if n1 % 3 != 0 or n2 % 3 != 0:
    print(0)
    sys.exit()
else:
    n1 = n1 // 3
    n2 = n2 // 3



P = 10**9 + 7
N = 10 ** 6 + 1
inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10**9+7
res = 1
for i in range(1, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n2 + 1):
    res = res * inv_t[i] % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
num = max(X, Y) - ((max(X, Y) - min(X, Y)) * 2)
mod = 10 ** 9 + 7
#print(num)
if num >= 0 and num % 3 == 0:
    num2 = num // 3
    a = num2
    b = num2 + max(X, Y) - min(X, Y)
    #print(a, b)
    if a == 0:
        print(1)
    else:
        datalist = [[0 for i in range(a)] for j in range(b)]
        datalist[0][0] = 1
        for i in range(0, len(datalist)):
            for j in range(0, len(datalist[i])):
                if i == 0 and j == 0:
                    continue
                elif i == 0:
                    datalist[i][j] += datalist[i][j-1]
                elif j == 0:
                    datalist[i][j] += datalist[i-1][j]
                else:

                    datalist[i][j] += datalist[i - 1][j] + datalist[i][j-1]
        print(datalist[a-1][b-1] % mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
a=(2*y-x)/3
b=(2*x-y)/3
mod=10**9+7
if a==int(a) and b==int(b):
  def mul(x,y):
    return ((x%mod)*(y%mod))%mod
  
  def power(x,y):
    if y==0:
      return 1
    elif y==1:
      return x%mod
    elif y%2==0:
      return power(x,y//2)**2%mod
    else:
      return power(x,y//2)**2*x%mod
    
  def div(x,y):
    return mul(x,power(y,mod-2))
  
  p=1
  for i in range(int(a+1),int(a+b+1)):
    p=mul(p,i)
  q=1
  for i in range(1,int(b+1)):
    q=mul(q,i)
  print(div(p,q))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
# n+2m=i
# 2n+m=j
# (4n+2m=2j)
# n=(2j-i)/3
# m=(2i-j)/3
# n+m C n (n+m)!/n!/m!

MOD = 10**9+7
MAX = 10**6+5
fac = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX
def COMinit():
    fac[0]=1
    fac[1]=1
    finv[0]=1
    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
def COM(n,k):
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

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

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

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())
mod = 10**9 + 7

if x == y and x%3 == 0:
    p = int(x / 3)
    print(comb(p*2, p, mod)%mod)
elif x%2 == y:
    print(1%mod)
elif x == y%2:
    print(1%mod)
elif x+1 == y:
    p = int((x-1) / 3)
    print(comb(p*2, p, mod)%mod)
elif x == y+1:
    p = int((y-1) / 3)
    print(comb(p*2, p, mod)%mod)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
xy=list(map(int,input().split()))
xy.sort()

l=xy[1]-xy[0]
if int(xy[1]-(2*l))%3!=0:
    print(0)
else:
    m=(xy[1]-(2*l))//3+l
    r=xy[0]//3
    n=m+r
    mod=10**9+7

    def comb(n,k,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):
        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

    print(comb(n,r,mod))