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 C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;

class Program
{
    static void Main(string[] args)
    {
        //入力を受け取る
        var XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var X = XY[0];
        var Y = XY[1];
        
      
        if(((2*X-Y)%3 == 0) && ((2*Y-X)%3 == 0)){
          long N = (X+Y)/3;
          long R = (long)Math.Min((2*X-Y)/3,(2*Y-X)/3);
          //N個のものからR個選ぶ組み合わせ
          var kaijo = new long[N+1];
          //階乗のモジュラー逆数
          var Ikaijo = new long[N+1];
          kaijo[0] = 1;
          for(long i = 1;i < N+1 ;i++){
            kaijo[i] = (kaijo[i-1]*i)%1000000007;
            Ikaijo[i] = RepeatSquaring(kaijo[i]);
          }
          long mo = 1000000007;
          long ans = (kaijo[N]*Ikaijo[R]%mo)*Ikaijo[N-R]%mo;
          Console.WriteLine(ans);
        }else{
          Console.WriteLine(0);
        }
    }
  
    //繰り返し2乗法
    static long RepeatSquaring(long N,long M = 1000000005,long mod = 1000000007){
      if(M == 0){
        return 1;
      }else if(M%2 == 0){
        var t = RepeatSquaring(N,(M/2),mod);
        return (t*t)%mod;
      }else{
        return (N*RepeatSquaring(N,M-1,mod))%mod;
      }
    }
}