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<iostream>
using namespace std;
int N,A,B,C;
long mod=1e9+7;
long F[5050],I[5050];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long comb(long a,long b){return F[a]*I[b]%mod*I[a-b]%mod;}
long H(long a,long b){return a==0?b==0:comb(a-1+b,b);}
main()
{
	cin>>N>>A>>B>>C;
	F[0]=1;
	for(int i=1;i<=N;i++)F[i]=F[i-1]*i%mod;
	I[N]=power(F[N],mod-2);
	for(int i=N;i--;)I[i]=I[i+1]*(i+1)%mod;
	if(B%2)
	{
		cout<<0<<endl;
		return 0;
	}
	long ans=0;
	for(int i=0;i<=C;i++)
	{
		for(int j=0;j<=A&&j+i<=C;j++)
		{
			if((C-i-j)%3)continue;
			(ans+=F[(C-i-j)/3+j+A-j+B/2]*I[(C-i-j)/3]%mod*I[j]%mod*I[A-j]%mod*I[B/2]%mod*H(B/2,i)%mod)%=mod;
		}
	}
	cout<<ans<<endl;
}