#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("O3")

#define int long long

using namespace std;

const int MOD = 1e9 + 7;
vector<int> factor(1e6 + 11);


int binvos(int n, const int p) {
    if (p == 0) return 1;
    else if (p % 2 == 1) return (binvos(n, p - 1) * n) % MOD;
    else {
        int d = binvos(n, p / 2);
        return (d * d) % MOD;
    }
}

void build_factor() {
    factor[0] = 1;
    for (int i = 1; i <= 1e6 + 5; ++i) factor[i] = (i * factor[i - 1]) % MOD;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m; cin >> n >> m;
    build_factor();
    int k1 = 0, k2 = 0;
    while (n * 2 > m && n > 1 && m > 0) {
        k1++;
        n -= 2;
        m--;
    }
    if (2 * n != m) {
        cout << 0;
        return 0;
    }
    while (n > 0 && m > 0) {
        k2++;
        n--;
        m -= 2;
    }
    cout << ((factor[k1 + k2] * binvos(factor[k1], MOD - 2)) % MOD * binvos(factor[k2], MOD - 2)) % MOD;
}


