#include<bits/stdc++.h>

using namespace std;

unsigned long long M = 1000000007;


unsigned long long pow1(unsigned long long a, unsigned long long p) {
	if (p == 0) {
		return 1;
	}
	if (p % 2 == 0) {
		unsigned long long ans = pow1(a, p / 2);
		return (ans * ans) % M;
	}
	return (a * pow1(a, p - 1)) % M;
} 

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<unsigned long long> f(4000001, 1);
	for (long long l = 2; l < 4000001; l++) {
		f[(int)l] = (f[(int)l - 1] * l) % M;
	}
	long long a, b, x, y;
	cin >> a >> b;
	y = (2 * a - b) / 3;
	x = a - 2 * y;
	if (x < 0 || y < 0 || (2 * a - b) % 3 != 0) {
		cout << 0;
		return 0;
	}
	//cout << f[x + y] << "\n";
	cout << (((unsigned long long)(((unsigned long long)f[(int)x + (int)y] * pow1(f[(int)x], M - 2)) % M) * pow1(f[(int)y], M - 2)) % M);
}