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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {


			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var a = inputArray[0];
			var b = inputArray[1];

			//X>=Yとしておく
			var X = Math.Max(a, b);
			var Y = Math.Min(a, b);

			//X方向に何回、Y方向に何回とぶのか調べる

			long xCount = 0;
			long yCount = 0;

			while (Y*2 > X) {
				yCount++;
				Y = Y - 2;
				X = X - 1;
			}

			if(Y*2 != X) {
				Console.WriteLine(0);
				return;
			}
			xCount = Y;

			//(xCount+yCount)Combination(yCount)が答えになる

			long result = 1;
			long divide = 1000000000 + 7;
			var sum = xCount + yCount;
			var c = yCount;
			checked {
				for (int i = 1; i <= yCount; i++) {
					var bunshi = (sum - yCount + i);
					var bunbo = i;
					result = (result * bunshi / bunbo) % divide;
				}
			}


			//答えの出力
			Console.WriteLine(result);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}