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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

lint power(lint x, lint n, lint m) {
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
	}

int main() {
	lint M = 1000000007;
	lint X, Y;
	cin >> X >> Y;
	lint A = 1;
	lint B = 1;
	lint a = 0;
	lint b = 0;
	lint C = X - Y;
	if (C < 0){
		a+=abs(C);
		X -= abs(C);
		Y -= abs(C * 2);
	}
	if (C >= 0) {
		b += abs(C);
		Y -= abs(C);
		X -= abs(C * 2);
	}
	if (X % 3 == 0) {
		a += X / 3;
		b += Y / 3;
		//cout << a << ' ' << b;
		for (int i = 1; i <= a + b; i++) {
			A *= i;
			A %= M;
		}
		for (int i = 1; i <= a; i++) {
			B *= i;
			B %= M;
		}
		for (int i = 1; i <= b; i++) {
			B *= i;
			B %= M;
		}

		//cout << A << ' ' << B;
		lint D = power(B, M-2, M);
		//cout << D;
		cout << A * D % M;
		//cout << power(2, 3, 10000);
	}
	else {
		cout << 0 << endl;
	}
}