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: Wrong Answer)

#include<bits/stdc++.h>
#define rint register int
#define rep(i,a,b) for (rint i=(a),_E=(b); i<=_E; ++i)
#define per(i,a,b) for (rint i=(a),_E=(b); i>=_E; --i)
#define REP(i,n) for (rint i=0,_E=(n); i<_E; ++i)
#define pb push_back
#define cmin(x,y) (y<x?x=y:0)
#define cmax(x,y) (y>x?x=y:0)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N = 10005;
const int mod = 1000000007;
int n, a, b, c, n1, n2, n3, n4, K, res, now;
int fac[N], rev[N];

inline int power(int x, int p) {
	int res = 1;
	while (p) {
		if (p & 1) res = 1ll * x * res % mod;
		x = 1ll * x * x % mod; p >>= 1;
	}
	return res;
}

inline int C(int n, int m) {
	if (m < 0 || m > n) return 0;
	return 1ll * fac[n] * rev[m] % mod * rev[n-m] % mod;
}

//将n划分为m份，可以为空
inline int calc(int n, int m) {
	return C(n + m - 1, m - 1);
}

int main() {
	scanf("%d%d%d%d", &n, &a, &b, &c);
	if (b & 1) return puts("0"), 0;
	fac[0] = rev[0] = 1;
	rep (i, 1, 10000) {
		fac[i] = 1ll * i * fac[i-1] % mod;
		rev[i] = power(fac[i], mod - 2);
	}
	rep (x, 0, min(a, c)) rep (y, 0, (c - x) / 3) {
		n1 = b / 2, n2 = y, n3 = a - x, n4 = x, K = c - x - 3 * y;
		if (n1 < 0 || n2 < 0 || n3 < 0 || n4 < 0 || K < 0) continue;
		now = 1ll * fac[n1 + n2 + n3 + n4] * calc(K, n1) % mod;
		now = 1ll * now * rev[n1] % mod * rev[n2] % mod;
		now = 1ll * now * rev[n3] % mod * rev[n4] % mod;
		res = (res + now) % mod;
	}
	printf("%d\n", res);
	return 0;
}