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: Accepted)

    /*
    Author: Arham_doshi
    @quote "Code like there's no tommorow!"
     ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
    */
    #include <bits/stdc++.h>
     
    #define int         long long
    #define double      long double
    #define pb          push_back
    #define pf          push_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
     
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define piii           pair<int,pair<int,int> >
     
     
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define hell        998244353 
    #define PI          3.141592653589
    #define bs(v,n)     binary_search(all((v)),(n))
    #define lb(v,n)     lower_bound(all((v)),(n))
    #define ub(v,n)     upper_bound(all((v)),(n))
    #define fo(i,l,u)   for(i=l;i<u;i++)
    #define rfo(i,l,u)  for(i=l;i>=u;i--)
    #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
    #define _init(b)     memset(b,-1,sizeof(b))
    #define _init0(b)     memset(b,0,sizeof(b))
    #define MOD         1000000007
    #define ef else if
    #define N           200005
     
     
    using namespace std;
     
    int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
    bool mod(double a,double b) {return a/b - floor(a/b);}
     
    int occurs(vi v,int n){
    auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}
     
    int logb(int base, int x) {
        return (log(x) / log(base));
    }
     
     
     int power(int n,int Pow){
                int result=1;
                while(Pow>0){
                    if(Pow%2==1){
                        result=(result*n)%MOD;
                    }
                    n=(n*n)%MOD;
                   Pow/=2LL;
                }
                return result;
            }
            
    int inverse(int a){
        return power(a,1000000005);
    }        
     
    int fun(int n,int r,int p){
        int i,fact[n+5];
        
        fact[0]=1;
        fact[1]=1;
        fo(i,2,n+1){
            fact[i]=fact[i-1]*i;
            fact[i]%=p;
        }
        
        int ans=fact[n];
        ans*=inverse(fact[r]);
        ans%=p;
        ans*=inverse(fact[n-r]);
        return ans%=p;
        
    }
     
    signed main()
    {
        int i,j,x,y,a,b;
          cin>>x>>y;
        if(x<y) swap(x,y);  
        int c=2*y-x;
        
        if(c>=0&&c%3LL==0){
            
            b=c/3LL;
            a=(x-b)/2LL;
            
                
                
            cout<<fun(a+b,b,1000000007LL);
            
            
            
            
        }
        else{
            cout<<0;
        }
     
        return 0;
    }