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)

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=10005;
int fac[N],ifac[N];
void init(int n=1e4){
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(R int n,R int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
inline int ch(R int n,R int m){return n==0&&m==0?1:C(n+m-1,m-1);}
int n,a,b,c,res;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d%d",&n,&a,&b,&c),res=0;
	init();
	if(b&1)return puts("0"),0;
	fp(i,0,a)fp(j,0,(c-i)/3){
		R int n1=i,n2=a-i,n3=j,n4=b>>1,k=c-i-j*3;
		if (n1<0||n2<0||n3<0||n4<0||k<0)continue;
		R int now=mul(fac[n1+n2+n3+n4],ch(k,n4));
		now=1ll*now*ifac[n1]%P*ifac[n2]%P*ifac[n3]%P*ifac[n4]%P;
		upd(res,now);
	}
	printf("%d\n",res);
	return 0;
}