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

using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        class modMCalc
        {
            private const int M = 1000000007;       // 素数(int範囲)

            // 乗算結果 % Mを求める
            static public int Mul(int a, int b)
            {
                return (int)(Math.BigMul(a, b) % M);
            }

            // 冪乗(mod M)
            static public int Pow(int a, int m)
            {
                if (0 == m)
                {
                    return 1;
                }
                if (1 == m)
                {
                    return a;
                }

                int result = 1;
                int param = a;
                for (; m > 0; m >>= 1)
                {
                    if ((m & 0x01) == 1)
                    {
                        result = Mul(result, param);
                    }

                    param = Mul(param, param);
                }

                return result;
            }

            // 除算(mod M)
            static public int Div(int a, int b)
            {
                return Mul(a, Pow(b, M - 2));
            }
        }

        class CombinationPermutation
        {
            private readonly int[] fac;

            // コンストラクタ
            // (mod Mの)階乗テーブル作成する
            public CombinationPermutation(int n)
            {
                fac = new int[n + 1];
                fac[0] = 1;
                for (int i = 1; i <= n; ++i)
                {
                    fac[i] = modMCalc.Mul(fac[i - 1], i);
                }
            }

            // 階乗求める
            public int Factorial(int n)
            {
                return fac[n];
            }

            // nPr
            public int nPr(int n, int r)
            {
                if (n < r)
                {
                    return 0;
                }

                if (n == r)
                {
                    return 1;
                }

                int result = Factorial(n);
                result = modMCalc.Div(result, Factorial(n - r));

                return result;
            }

            // nCr
            public int nCr(int n, int r)
            {
                return modMCalc.Div(nPr(n, r), Factorial(r));
            }
        }


        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int X = int.Parse(s[0]);
            int Y = int.Parse(s[1]);

            if( 0 != ((X+Y) % 3))
            {
                Console.WriteLine(0);
                return;
            }

            if (X > Y * 2 || Y > X * 2)
            {
                Console.WriteLine(0);
                return;
            }

            int total = (X + Y) / 3;
            int ont = (2 * Y - X) / 3;

            CombinationPermutation p = new CombinationPermutation(total);

            int ans = p.nCr(total, ont);
            Console.WriteLine(ans);

            return;
        }
    }
}