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 Ruby (2.3.3) (judge verdict: Wrong Answer)

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end
require "prime"
@r = 10**9 + 7
@t = na(10**6)
def kaijo2(l,m,n)
  max = [l,m].max
  min = [l,m].min
  ans = 1
  ind2 = 0
  (1..n).each do |i|
    if(i > max)
      i.prime_division.each do |a|
        @t[a[0]] += a[1]
      end
    end
    if i <= min
      i.prime_division.each do |a|
        @t[a[0]] -= a[1]
      end
    end
  end
  @t.each.with_index do |d,i|
    ans *= i**d
    ans %= @r
  end
  return ans
end

x,y = inp
kaisu1 = nil
kaisu2 = nil

eve_f = 0
if(x%2 == 1)
  x -= 1
  y -= 2
  eve_f = 1
  if ( x == 0 and y ==0)
    puts 1
    exit
  end
end


#全部2からの差
max_sa = 2*x - y

if(max_sa % 3 != 0)
  puts 0
  exit
end

kaisu2 = max_sa/3
kaisu1 = (x-kaisu2*2)
if(kaisu1 < -1)
      puts 0
      exit
end
p kaijo2(kaisu1+eve_f,kaisu2,kaisu1+kaisu2+eve_f)