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)

//#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e6 + 10;
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }
int const MOD = 1e9 + 7;
int ans = 0;
// int vis[maxn][maxn];
ll n, m;
// map<pdi, int> dp;

void dfs(int x, int y) {
    if (x > n || y > m) return;
    if (x == n && y == m) {
        ans++;
        if (ans > MOD) ans -= MOD;
        return;
    }
    dfs(x + 1, y + 2);
    dfs(x + 2, y + 1);
}

ll pow_mod(ll a, ll x, ll mod) {
    if (x == 0) return 1;
    ll ans = pow_mod(a, x >> 1, mod);
    ans = ans * ans % mod;
    if (x & 1) ans = ans * a % mod;
    return ans;
}

ll calc(ll n) {
    ll ans = 1;
    for (ll i = 1; i <= n; i++) {
        ans = (ans * i) % MOD;
    }
    return ans;
}

ll C(ll n, ll m) {
    ll ans = 1;
    ans = (ans * calc(n)) % MOD;
    ans = (ans * pow_mod(calc(m), MOD - 2, MOD)) % MOD;
    ans = (ans * pow_mod(calc(n - m), MOD - 2, MOD)) % MOD;
    return ans;
}

int main(void) {
    FAST_IO;
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        puts("0");
        return 0;
    } 
    if (2 * y < x || 2 * x < y) {
        puts("0");
        return 0;
    } 
    int X = (2 * y - x) / 3, Y = (2 * x - y) / 3;
    cout << C(X + Y, X) % MOD << endl;

    return 0;
}