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.

Solution in Fortran (gfortran v4.8.4) (judge verdict: Runtime Error)

program kadai
    implicit none
integer(8)  ::  x,y,i
integer(8)  ::  newx,newy
integer(8),allocatable  ::  ue(:),shita1(:),shita2(:)
integer(8)  ::  ans

read(*,*) x,y

newx=-x+2*y
newy=2*x-y

if (mod(newx,3) /= 0 .or. mod(newy,3) /=0 .or. newx<0 .or. newy<0) then
    write(*,*) 0
    stop
end if
newx=newx/3
newy=newy/3

allocate(ue(newx+newy))
allocate(shita1(10**9+7))
allocate(shita2(newy+newy))

ue(1)=1
shita1(1)=1
shita2(1)=1

do i=2,newx+newy
    ue(i)=mod(ue(i-1)*i,10**9+7)
    shita1(i)=10**9+7-mod(shita1(mod(10**9+7,i)) * ((10**9+7)/i) , 10**9+7)
    shita2(i)=mod(shita2(i-1)*shita1(i),10**9+7)
end do

!do i=1,10**9+5
!    ans=mod(ans*shita1*shita2,10**9+7)
!end do

ans=mod(ue(newx+newy)*mod(shita2(newx)*shita2(newy),10**9+7),10**9+7)
write(*,*) ans

stop
contains
end program kadai