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:
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 = 1000000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cinit():
    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())
maxY = X * 2
if X!=0 and Y!=0 and (maxY - Y)%3==0:
    cinit()
    num2 = abs(maxY - Y)//3
    num1 = X - num2 * 2
    print(cmb(num1+num2,num2,mod))
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 = 1000000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cinit():
    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())
maxY = X * 2
if (maxY - Y)%3==0:
    cinit()
    num2 = abs(maxY - Y)//3
    num1 = X - num2 * 2
    print(cmb(num1+num2,num2,mod))
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 = 1000000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cinit():
    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())
maxY = X * 2
if (maxY - Y)%3==0:
    cinit()
    num2 = abs(maxY - Y)//3
    num1 = X - num2 * 2
    print(num1,num2)
    print(cmb(num1+num2,num2,mod))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

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

def A(i, j):
    if 0.5*i <= j and j <= 2*i and (i+j)%3==0:
        n, m = (2*j-i)//3, (2*i-j)//3
        return comb(n+m,m)%((10**9)+7)
    else:
        return 0

print(A(x, y))

Submission status: Wrong Answer

Solution code:
import itertools

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

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

if (n > 0 and m > 0) and (n.is_integer() and m.is_integer()):
    try:
        ans = len(list(itertools.combinations(range(int(m + n)), int(n))))
        print(ans)
    except:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np


MOD = 10**9 + 7

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

if (X + Y) % 3 != 0:
    print(0)
if (Y < X/2) or (Y > 2*X):
    print(0)
    
h = (2 * X - Y) // 3
v = (2 * Y - X) // 3

def extgcd(a, b):
    if b == 0:
        x = 1
        y = 0
    else:
        y, x = extgcd(b, a%b)
        y -= a//b * x
    return x, y
  
def low_inverse(a):
    ret, _ = extgcd(a, MOD)
    return ret
  
def low_combination(m, n):
    # calculate (m+n)!/n!m!
    ret = 1
    numerator = m + n
    for i in range(min(m, n)):
        inv_i = low_inverse(i + 1)
        ret = ret * (numerator - i) * inv_i % MOD
    return ret
  
print(low_combination(h, v))

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


if __name__ == "__main__":
    mod = 10**9 + 7
    x, y = map(int, input().split())

    if (x + y) % 3 != 0:
        print(0)
        exit

    n = (x + y) // 3
    k = (2 * x - y) // 3
    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inv = [0, 1]  # 逆元テーブル計算用テーブル

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

    print(cmb(n, k, mod))

Submission status: Wrong Answer

Solution code:
import math
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()
n = (x+y)//3
x -= n
y -= n
if x > y:
    c = math.factorial(x+1) // math.factorial(x + 1 - y)
else:
    c = math.factorial(y+1) // math.factorial(y + 1 - x)
print(c%MOD)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
x, y = map(int, input().split())
if (x+y)%3 != 0 or 3*x < x+y or 3*y < x+y:
    print(0)
    exit()

Submission status: Wrong Answer

Solution code:
X,Y  = map(int,input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    if n < 0 or m < 0:
        print(0)
    top = 1
    bot = 1
    n = int(n)
    m = int(m)
    for i in range(n):
        top *= (n + m) - i
        bot *= n - i

    result = (top/bot) % ((10**9)+7)
    result = int(result)
    print(result)

Submission status: Wrong Answer

Solution code:
def combination(n, r, mod=10 ** 9 + 7):
    n1, r = n + 1, min(r, n - r)
    numerator = denominator = 1
    for i in range(1, r + 1):
        numerator = numerator * (n1 - i) % mod
        denominator = denominator * i % mod
 
    return numerator * pow(denominator, mod - 2, mod) % mod

X,Y = map(int, input().split())
maxY = X * 2
if (maxY - Y)%3==0:
    num2 = abs(maxY - Y)//3
    num1 = X - num2 * 2
    print(combination(num1+num2,num2))
else:
    print(0)

Submission status: Wrong Answer

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

    result = (top/bot) % ((10**9)+7)
    result = int(result)
    print(result)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if (2*X - Y)%3 == 0 and (2*Y - X) and a >= 0 and b >= 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

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

FACT = [1]*1000001
FCTINV = [1]*1000001
for i in range(2, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD
    FCTINV[i] = DIV(FCTINV[i-1],FCTINV[i])

if a > 0 and b > 0 and (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0:
    print((FACT[a+b]*FCTINV[a]%MOD)*FCTINV[b]%MOD)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

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

FACT = [1]*1000001
FCTINV = [1]*1000001
for i in range(2, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD
    FCTINV[i] = DIV(FCTINV[i-1],FCTINV[i])

if a > 0 and b > 0 and (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

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

FACT = [1]*1000001
FCTINV = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD
# for i in range(1, 1000000):
#     FCTINV[i+1] = DIV(FCTINV[i+1],FCTINV[i])

if a > 0 and b > 0 and (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
# FCTINV = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if a > 0 and b > 0 and (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0:
    print(FACT[a+b]*INV(FACT[a])*INV(FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if a > 0 and b > 0 and (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if float.is_integer((2*X - Y) / 3) and float.is_integer((2*Y - X) / 3) and a > 0 and b > 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if float.is_integer((2*X - Y) / 3) and float.is_integer((2*Y - X) / 3) and a > 0 and b > 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if float.is_integer((2*X - Y) / 3) and float.is_integer((2*Y - X) / 3):
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

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

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = FACT[i-1]*i%MOD

if math.floor((2*X - Y) / 3) == (2*X - Y) / 3 and math.floor((2*Y - X) / 3) == (2*Y - X) / 3:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

x,y = map(int,input().split())
MOD = 10**9+7
N = 10**6
if (x+y)%3 != 0:
    print(0)
    sys.exit()
else:
    m = (2*x-y)//3
    n = (2*y-x)//3
    print(m)
    print(n)
    if n < 0 or m < 0:
        print(0)
        sys.exit()
    else:
        A = [1,1]
        B = [1,1]
        Inv = [0,1]
        for i in range(2,N+1):
            A.append((A[-1]*i)%MOD)
            Inv.append((-Inv[MOD%i]*(MOD//i))%MOD)
            B.append((B[-1]*Inv[-1])%MOD)
print(A[m+n]*B[m]*B[n]%MOD)

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
mod=10**9+7 
def nCr(n, r, mod):#mod=10**9+7 
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

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

n=((2*X)-Y)//3
m=((X+Y)//3)-n

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

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
mod=10**9+7 
def nCr(n, r, mod):#mod=10**9+7 
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

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

n=((2*X)-Y)//3
m=((X+Y)//3)-n

print(nCr(n+m,min(n,m),mod))

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
mod=10**9+7 
def nCr(n, r, mod):#mod=10**9+7 
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

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

n=((2*X)-Y)//3
m=(X+Y)//3-n

print(nCr(n+m,min(n,m),mod=10**9+7))

Submission status: Wrong Answer

Solution code:
# from scipy.special import comb
# from math import factorial
# from operator import mul
# from functools import reduce

# def combination(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


def combination(n, r, mod=10 ** 9 + 7):
    n1, r = n + 1, min(r, n - r)
    numerator = denominator = 1
    for i in range(1, r + 1):
        numerator = numerator * (n1 - i) % mod
        denominator = denominator * i % mod

    return numerator * pow(denominator, mod - 2, mod) % mod


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

if (x + y) % 3 != 0:
    print(0)
else:
    # (+1, +2) n
    # (+2, +1) m
    # n + 2m = x
    # 2n + m = y
    m = (2 * x - y) // 3
    n = (2 * y - x) // 3
    # score = factorial(n + m) // factorial(n) // factorial(m)
    # score = comb(n + m, n, exact=True)
    score = combination(n + m, n)
    print(score)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

# https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E3%83%A6%E3%83%BC%E3%82%B6%E5%AE%9A%E7%BE%A9%E5%9E%8B%EF%BC%93%E8%A9%95%E4%BE%A1-
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 = list(map(int, input().split()))

res = 0
if (X + Y) % 3 == 0:
  moves_x = (2 * X - Y) // 3
  moves_y = (2 * Y - X) // 3
  res = cmb(moves_x + moves_y, min(moves_x, moves_y))
  
print(res % (10 ** 9 + 7))

Submission status: Wrong Answer

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


x,y = map(int,input().split())
diff = abs(x-y)
mod = 10**9 + 7
if (x+y) % 3 != 0:
    print("0")
    exit()
else:
    cir = (min(x,y) - diff) // 3
    all_step = (x+y) // 3
    print(combination(all_step, cir, mod))

Submission status: Wrong Answer

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


x,y = map(int,input().split())
diff = abs(x-y)
mod = 10**9 + 7
if min(x,y) * 2 == max(x,y):
    print("1")
    exit()
elif (x+y) % 3 != 0:
    print("0")
    exit()
else:
    cir = (min(x,y) - diff) // 3
    all_step = cir * 2 + diff
    print(combination(all_step, cir, mod))

Submission status: Wrong Answer

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


x,y = map(int,input().split())
diff = abs(x-y)
mod = 10**9 + 7
n = 1
if min(x,y) * 2 == max(x,y):
    print("1")
elif (min(x,y) - diff) % 3 != 0:
    print("0")
else:
    cir = (min(x,y) - diff) // 3
    all_step = cir * 2 + diff
    print(combination(all_step, cir, mod))

Submission status: Wrong Answer

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

# 計算不可の場合の処理
exitflg = False
if (X + Y) % 3 != 0:
    exitflg = True
if X * 2 < Y or X > Y * 2:
    exitflg = True
if exitflg:
    print(0)
    exit()

# メイン処理
center = (X + Y) // 2
maxXY = center // 3 * 4
minXY = center // 3 * 2

out = 1

# 選ぶ個数を取得
if X >= center:
    diffalence = maxXY - X
else:
    diffalence = X - minXY

# 総数を取得
N = maxXY-minXY

# 場合の数の式  c = 答え、n=選ぶ総数, r=選ぶ個数
# c = n! / (r! * (n - r)!)
# diffalenceの数だけ自由に動けるので
# c = (maxXY - minXY)! / (diffalence! * (maxXY - minXY - diffalence)!)
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

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % JOSU )
    inverse.append( ( -inverse[JOSU % i] * (JOSU//i) ) % JOSU )
    g2.append( (g2[-1] * inverse[-1]) % JOSU )

out = cmb(N,diffalence,JOSU)

print(out)

Submission status: Wrong Answer

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

# 計算不可の場合の処理
exitflg = False
if (X + Y) % 3 != 0:
    exitflg = True
if (X + Y) % 2 != 0:
    exitflg = True
if X * 2 < Y or X > Y * 2:
    exitflg = True
if exitflg:
    print(0)
    exit()

# メイン処理
center = (X + Y) // 2
maxXY = center // 3 * 4
minXY = center // 3 * 2

out = 1

# 選ぶ個数を取得
if X >= center:
    diffalence = maxXY - X
else:
    diffalence = X - minXY

# 総数を取得
N = maxXY-minXY

# 場合の数の式  c = 答え、n=選ぶ総数, r=選ぶ個数
# c = n! / (r! * (n - r)!)
# diffalenceの数だけ自由に動けるので
# c = (maxXY - minXY)! / (diffalence! * (maxXY - minXY - diffalence)!)
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

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % JOSU )
    inverse.append( ( -inverse[JOSU % i] * (JOSU//i) ) % JOSU )
    g2.append( (g2[-1] * inverse[-1]) % JOSU )

out = cmb(N,diffalence,JOSU)

print(out)

Submission status: Wrong Answer

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

# 計算不可の場合の処理
exitflg = False
if (X + Y) % 3 != 0:
    exitflg = True
if (X + Y) % 2 != 0:
    exitflg = True
if X * 2 < Y or X > Y * 2:
    exitflg = True
if exitflg:
    print(0)
    exit()

# メイン処理
center = (X + Y) // 2
maxXY = center // 3 * 4
minXY = center // 3 * 2

out = 1

# あとは階乗で計算
if X >= center:
    diffalence = maxXY - X
else:
    diffalence = X - minXY

for i in range(diffalence, 0 , -1):
    out *= (maxXY - i)
    out %= JOSU
    
print(out)

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())
MOD = 10 ** 9 + 7
for s in range(max(x,y)):
    if 2 * x - 3 * s == y:
        flag = True
        break
t = x - 2 * s
print(cmb((t+s),s,mod))

Submission status: Wrong Answer

Solution code:
S = input()
li = S.split(" ")
X = int(li[0])
Y = int(li[1])
Z = int((X+Y)/3)
count = 0
a = 0
b = 0
up = 1
down = 1
if not (X+Y)%3==0:
    print(0)
else:
    for i in range(Z+1):
        if i*2+(Z-i)*1 == X and i*1+(Z-i)*2 == Y:
            a = i   #aは右に２上に１
            b = Z-i #bは右に１上に２
    if a==0 and b==0:
        print(0)
    else:
      a = min(a,b)
      b = max(a,b)
      for i in range(a):
            up *= a+b-i
      for i in range(a):
            down *= a-i

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7


def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


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

if not ((X + Y) / 3).is_integer():
    print(0)
    exit(0)


a = (X + Y) // 3
b = Y - a

ans = combination(a, b, mod=MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from operator import mul
MOD = 10 ** 9 + 7


def combination(n, r, mod=None):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif n < r:
        return 0
    if mod is None:
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under
    else:
        numer = denom = 1
        for i in range(1, r + 1):
            numer = numer * (n + 1 - i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod - 2, mod) % mod


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

if not ((X + Y) / 3).is_integer():
    print(0)
    exit(0)


a = (X + Y) // 3
b = Y - a

ans = combination(a, b, mod=MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from operator import mul
MOD = 10 ** 9 + 7


def combination(n, r, mod=None):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif n < r:
        return 0
    if mod is None:
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under
    else:
        numer = denom = 1
        for i in range(1, r + 1):
            numer = numer * (n + 1 - i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod - 2, mod) % mod


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

if not ((X + Y) / 3).is_integer():
    print(0)
    exit(0)

# a := →→↑ の個数
# b := →↑↑ の個数
# 2a + b = X
# a + 2b = Y より、
a = (2 * X - Y) // 3
b = X - 2 * a

ans = combination(a + b, a, mod=MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from operator import mul
MOD = 10 ** 9 + 7


def combination(n, r, mod=None):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif n < r:
        return 0
    if mod is None:
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under
    else:
        numer = denom = 1
        for i in range(1, r + 1):
            numer = numer * (n + 1 - i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod - 2, mod) % mod


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

if not ((X + Y) / 3).is_integer():
    print(0)
    exit(0)

# a := →→↑ の個数
# b := →↑↑ の個数
# 2a + b = X
# a + 2b = Y より、
a = (2 * X - Y) // 3
b = (2 * Y - X) // 3

ans = combination(a + b, a, mod=MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
li = S.split(" ")
X = int(li[0])
Y = int(li[1])
Z = int((X+Y)/3)
count = 0
a = 0
b = 0
up = 1
down = 1
if not (X+Y)%3==0:
    print(0)
else:
    for i in range(Z+1):
        if i*2+(Z-i)*1 == X and i*1+(Z-i)*2 == Y:
            a = i   #aは右に２上に１
            b = Z-i #bは右に１上に２
            break
    if a==0 and b==0:
        print(0)
    else:
        for i in range(a):
            up *= a+b-i
            down *= a-i
            
    print (int(float(up/down)%float(10**9+7)))

Submission status: Wrong Answer

Solution code:
S = input()
li = S.split(" ")
X = int(li[0])
Y = int(li[1])
Z = int((X+Y)/3)
count = 0
a = 0
b = 0
up = 1
down = 1
if not (X+Y)%3==0:
    print(0)
else:
    for i in range(Z+1):
        if i*2+(Z-i)*1 == X and i*1+(Z-i)*2 == Y:
            a = i   #aは右に２上に１
            b = Z-i #bは右に１上に２
    if a==0 and b==0:
        print(0)
    else:
        for i in range(a):
            up *= a+b-i
        for i in range(a):
            down *= a-i
    print (int(float(up/down)%float(10**9+7)))

Submission status: Wrong Answer

Solution code:
import math

def comb(a, b):
    v = 1
    for i in range(a, b, -1):
        v *= i
    return v

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

if y > x:
    x, y = y, x

nx = x // 3
ny = y // 3
rx = x % 3
ry = y % 3

if nx == ny and rx == 0 and rx == 0:
    print(comb(nx*2, nx) % (10**9+7))
elif nx == ny and rx == 2 and ry == 1:
    print(comb(nx*2+1, nx+1) % (10**9+7))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

def comb(a, b):
    v = 1
    for i in range(a, b, -1):
        v *= i
    return v

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

if y > x:
    x, y = y, x

nx = x // 3
ny = y // 3
rx = x % 3
ry = y % 3

if nx == ny and rx == 0 and rx == 0:
    print(comb(nx*2, nx))
elif nx == ny and rx == 2 and ry == 1:
    print(comb(nx*2+1, nx+1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

def comb(a, b):
    v = 1
    for i in range(a, b, -1):
        v *= i
    return v

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

if y > x:
    x, y = y, x

nx = x // 3
ny = y // 3
rx = x % 3
ry = y % 3

print(nx, ny, rx, ry)
if nx == ny and rx == 0 and rx == 0:
    print(comb(nx*2, nx))
elif nx == ny and rx == 2 and ry == 1:
    print(comb(nx*2+1, nx+1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
x, y = map(int, input().split())
if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (-x+2*y)//3
def comb(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
print(comb(a+b, a, 10**9+7))

Submission status: Wrong Answer

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

n = int(2*Y/3 - X/3)
m = int(2*X/3 - Y/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 = 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)%3 != 0:
    print(0)
else:
    if n<0 or m<0:
        print(0)
    else:
        print(cmb(n+m,n,mod))

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
B = Y - 1 / 2 * X
min_x = B / (3 / 2)
if min_x % 1 != 0 or X < min_x:
    print(0)
else:
    print(int(1 + min_x * ((X - min_x) / 2) % (10 ** 9 + 7)))

Submission status: Wrong Answer

Solution code:
X, Y = map(int, input().split())
B = Y - 1 / 2 * X
min_x = B / (3 / 2)
if min_x % 1 != 0 or X < min_x:
    print(0)
else:
    print(int(1 + min_x * (X - min_x / 2)) % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
X,Y=map(int,input().split())
s=(2*X-Y)/3
u=(2*Y-X)/3
m=10**9+7  
def fact(n,p):
  ans=1
  for i in range(1,n+1):
      ans=ans*i%p
  return ans
def cal(x,a,p):
  ans=x%p
  memo=1
  while True:
    if a==1:break
    if a%2==0:
      ans=(ans*ans)%p
      a=a//2
    else:
      a=a-1
      memo=memo*ans
  return (ans*memo)%p
  
if s.is_integer() and u.is_integer():
  s=int(s)
  u=int(u)
  n=s+u
  ans=1
  ans=fact(n,m)
  s=fact(s,m)
  u=fact(u,m)
  s=cal(s,m-2,m)
  u=cal(u,m-2,m)
  ans=(ans*s*u)%m 
else:
  ans=0
print(ans)

Submission status: Wrong Answer

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

if (X+Y)%3 != 0:
    ans = 0
else:
    p = (2*Y - X)//3
    q = (2*X - Y)//3
    if p<0 or q<0:
        ans = 1
    else:
        a = b = 1
        pq = min(p,q)
        for i in range(0,pq):
            a *= (p+q-i)
            b *= (pq-i)
            a %= M
            b %= M
        i=0
        ans = a*pow(b,M-2,M)%M
print(ans)