#include<iostream>

using namespace::std;

#define MOD 1000000007

long long int fac[5000005],rev[5000005];

int main(){
	int x,y;
	cin>>x>>y;
	if((x+y)%3){
		cout<<0<<'\n';
		return 0;
	}
	int n=(x+y)/3;
	fac[0]=fac[1]=1;
	for(int i=2;i<=n;i++)
		fac[i]=(fac[i-1]*i)%MOD;
	rev[1]=1;
	for(int i=2;i<=n;i++)
		rev[i]=(MOD-(((MOD/i)%MOD)*rev[MOD%i])%MOD)%MOD;
	rev[0]=1;
	for(int i=2;i<=n;i++)
		rev[i]=(rev[i]*rev[i-1])%MOD;
	if(x<n || y<n)
		cout<<0<<'\n';
	else cout<<(fac[n]*((rev[y-n]*rev[x-n])%MOD))%MOD<<'\n';
}