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 (GCC 5.4.1) (judge verdict: Accepted)

#define mod 1000000007

long long modmult (long long n, long long m){
	if(!m) return 1;
	if(m&1) return modmult(n, m-1)*n%mod;
	return modmult(n*n%mod, m>>1);
}

long long modinv(long long n) { return modmult(n, mod-2); }

unsigned long long count;

unsigned long long c(a,b){
	unsigned long long res = 1;
	int i;
	
	if(a<b*2)return c(a,a-b);
	for(i=a;i>b;i--)res=res*i%mod;
	for(i=2;i<=a-b;i++)res=res*modinv(i)%mod;

	return res;
}

main(){
	long long int x, y, x2s;
	scanf("%lld %lld", &x, &y);
	
	for(x2s=0;x2s<=x/2;x2s++){
		if(x2s + (x - x2s*2)*2 != y) continue;
//		printf("y: %lld * 2 + %lld\n", x-x2s*2, x2s);
		count+=c(x-x2s,x2s)%mod;
		count%=mod;
//		printf("-- %lld c %lld patterns available\n", x-x2s, x2s);
	}
	
	printf("%lld\n", count);
}