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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		long mod = (long)(1e9 + 7);
		long X = GetLong();
		long Y = GetLong();

		if((X + Y) % 3 != 0 || (2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0)
		{
			WriteLine(0);
			return;
		}

		long a = (2 * Y - X) / 3;
		long b = (2 * X - Y) / 3;
		var mct = new ModCombTable(2 * (int)1e7 + 1, mod);
		WriteLine(mct.ModComb(a + b, a));
	}
}

public class ModCombTable
{
	private long[] f = null;
	private long[] fInv = null;
	private long mod;

	public ModCombTable(int N, long m)
	{
		mod = m;

		// calc factorial
		f = new long[N+1];
		f[0] = 1;
		for(int i = 1; i <= N; i++)
			f[i] = (f[i-1] * i) % mod;

		// calc factorial inverse
		fInv = new long[N+1];
		fInv[N] = ModInv(f[N]);
		for(int i = N; i > 0; i--)
			fInv[i-1] = (fInv[i] * i) % mod;
	}

	public long ModComb(long n, long k)
	{
		if(n < 0 || n < k)
			return 0;
		
		return (((f[n] * fInv[k]) % mod) * fInv[n-k]) % mod;
	}

	public long ModInv(long x)
	{
		return ModPow(x, mod - 2);
	}

	public long ModPow(long x, long n)
	{
		long res = 1;
		while(n > 0)
		{
			if((n & 1) == 1)
				res = (res * x) % mod;
			x = (x * x) % mod;
			n >>= 1;
		}
		return res;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}