Example

Input

3 1 0 1


Output

18
#include <algorithm>
#include <climits>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> i_i;
int MOD = 1000000007;

ll F[1001], C[1001][1001], unko[1001][1001], pw[1001][1001];

ll gcd(ll x, ll y) {
	if (y) return gcd(y, x % y);
	return x;
}

vector<vector<int> > f(int N, ll x) {
	vector<vector<int> > dp(N + 1);
	for (int n = 1; n <= N; n++) {
		dp[n] = vector<int>(N / n + 1);
		dp[n][0] = 1;
	}
	for (int k = 1; k <= N; k++) {
		int d = gcd(k, x), n = k / d;
		for (int i = N / n; i >= 0; i--)
			for (int j = 1; j * d <= i; j++)
				dp[n][i] = (dp[n][i] + dp[n][i - j * d] * C[i * n][j * k] % MOD * unko[k][j * k]) % MOD;
	}
	return dp;
}

vector<vector<int> > g(int N, ll x) {
	vector<vector<int> > dp(N + 1);
	for (int n = 1; n <= N; n++) {
		dp[n] = vector<int>(N / n + 1);
		dp[n][0] = 1;
	}
	for (int k = 1; k <= N; k++) {
		int d = gcd(k, x), n = k / d;
		for (int i = N / n; i >= 0; i--)
			for (int j = 1; j * d <= i; j++)
				dp[n][i] = (dp[n][i] + dp[n][i - j * d] * C[i][j * d] % MOD * unko[d][j * d] % MOD * pw[n][j * (d - 1)]) % MOD;
		/*for (int i = 0; i <= N; i++)
			cout << dp[1][i] << ' ';
		cout << endl;*/
	}
	return dp;
}

int main() {
	F[0] = 1;
	for (int i = 1; i <= 1000; i++)
		F[i] = F[i - 1] * i % MOD;
	for (int i = 0; i <= 1000; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	}
	for (int i = 1; i <= 1000; i++) {
		unko[i][0] = 1;
		for (int j = 1; j <= 1000; j++)
			unko[i][j] = unko[i][j - 1] * (j % i ? j : 1) % MOD;
	}
	for (int i = 1; i <= 1000; i++) {
		pw[i][0] = 1;
		for (int j = 1; j <= 1000; j++)
			pw[i][j] = pw[i][j - 1] * i % MOD;
	}
	int N; ll X, Y, Z;
	cin >> N >> X >> Y >> Z;
	vector<vector<int> > a = f(N, 2), b = g(N, abs(X - Y + Z));
	/*for (int n = 1; n <= N; n++) {
		for (int i = 0; i < b[n].size(); i++)
			cout << b[n][i] << ' ';
		cout << endl;
	}*/
	if (!X && !Y && !Z) {
		int ans = a[1][N];
		for (int t = 0; t < N; t++)
			ans = (ll)ans * N % MOD;
		cout << ans << endl;
		return 0;
	}
	vector<int> dp(N + 1);
	dp[0] = 1;
	for (int n = 1; n <= N; n++)
		for (int j = N; j >= 0; j--)
			for (int i = 1; i * n <= j; i++)
				dp[j] = (dp[j] + (ll)dp[j - i * n] * C[j][i * n] % MOD * a[n][i] % MOD * b[n][i]) % MOD;
	cout << dp[N] << endl;
}