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: Wrong Answer)

program knight
    implicit none
    integer(4)::x, y
    integer(4):: i, d
    read*, x, y

    if (mod(x+y,3) /= 0) then
        print*, 0
        stop
    end if

    d = (x+y)/3
    x = x - d
    y = y - d

    if (x < 0 .or. y < 0) then
        print*, 0
        stop
    end if

    if (x==0 .or. y==0) then
        print*, 1
    end if

    print*, nikou(x+y, x)

    contains
    function nikou(a,b) result(ret)
        integer(4):: a,b
        integer(8):: ret
        integer(8), parameter:: md = 1000000007
        integer(8), allocatable:: fi(:), i_fi(:)
        
        allocate(fi(a), i_fi(a))
        fi(1) = 1

        do i=2,a
            fi(i) = mod(fi(i-1)*i, md)
        end do

        do i=1,max(b,a-b)
            i_fi(i) = inv((fi(i)),md)
        end do

        ret = mod(mod(fi(a)*i_fi(b),md)*i_fi(a-b),md)
    end function
    

    function inv(x, md) result(ret)
        integer(8):: x, md, ret, power
        power = md-2
        ret = 1
        do while(power > 0)
            if (mod(power,2) == 1) ret=mod(ret*x,md)
            x=mod(x*x,md)
            power = power/2
        end do

    end function
end program knight