Problem:
Score : 1500 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

Consider all integers between 1 and 2N, inclusive.
Snuke wants to divide these integers into N pairs such that:

Each integer between 1 and 2N is contained in exactly one of the pairs.

In exactly A pairs, the difference between the two integers is 1.

In exactly B pairs, the difference between the two integers is 2.

In exactly C pairs, the difference between the two integers is 3.

Note that the constraints guarantee that N = A + B + C, thus no pair can have the difference of 4 or more.

Compute the number of ways to do this, modulo 10^9+7.

Constraints

1 ≤ N ≤ 5000

0 ≤ A, B, C

A + B + C = N

Input

The input is given from Standard Input in the following format:

N A B C

Output

Print the answer.

Sample Input 1

3 1 2 0

Sample Output 1

2

There are two possibilities: 1-2, 3-5, 4-6 or 1-3, 2-4, 5-6.

Sample Input 2

600 100 200 300

Sample Output 2

522158867

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

const ll N = 100000, MOD = 1e9 + 7;
ll inv[N], fac[N], invfac[N];

ll multinom(ll n, vl ks) {
	if (n < 0) return 0;
	ll res = fac[n];
	for (ll k: ks) {
		if (k < 0 || k > n) return 0;
		res = res * invfac[k] % MOD;
	}
	return res;
}

ll calc(ll a, ll b, ll c) {
	if (b % 2) return 0;
	b /= 2;
	
	ll res = 0;
	if (b == 0) {
		FOR(p,0,a+1) FOR(q,0,(c-p)/3+1) {
			if (p + 3*q == c) res = (res + multinom(a+q+b, {p,q,a-p,b})) % MOD;
		}
	} else {
		FOR(p,0,a+1) FOR(q,0,(c-p)/3+1) {
			res = (res + multinom(a+q+b, {p,q,a-p,b}) * multinom(b+c-p-3*q-1, {b-1, c-p-3*q})) % MOD;
		}
	}
	return res;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	inv[1] = fac[0] = invfac[0] = 1;
	FOR(n,2,N) inv[n] = (MOD/n) * (MOD - inv[MOD%n]) % MOD;
	FOR(n,1,N) {
		fac[n] = n * fac[n-1] % MOD;
		invfac[n] = inv[n] * invfac[n-1] % MOD;
	}

	ll n, a, b, c; cin >> n >> a >> b >> c;
	cout << calc(a,b,c) << endl;
}