#include #define show(x) std::cerr << #x << " = " << x << std::endl using ll = long long; constexpr ll MOD = 1000000007LL; template class ModCombination { public: ModCombination(const std::size_t n) : fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1) { for (ll i = 2; i <= (ll)n; i++) { fact[i] = (fact[i - 1] * i) % mod, inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod, inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod; } } ll combination(const std::size_t n, const std::size_t k) const { return (((fact[n] * inv_fact[k]) % mod) * inv_fact[n - k]) % mod; } private: std::vector fact, inv, inv_fact; }; int main() { int N, R, B, G; std::cin >> N >> R >> B >> G; const int MAX = (N + 1) / 3; ModCombination<> mod(N + 2); ll ans = 0; std::vector p2(N + 2, 1); for (int i = 1; i <= N + 1; i++) { p2[i] = p2[i - 1] * 2 % MOD; } for (int a = 0; a <= std::min({R, B, MAX}); a++) { for (int b = 0; b <= std::min({R - a, G, MAX - a}); b++) { for (int c = std::min({B - a, G - b, MAX - a - b}); c >= 0; c--) { const int d = R - a - b, e = B - a - c, f = G - b - c; const int sp = (N + 1) - 3 * a - 3 * b - 3 * c - 2 * d - 2 * e - 2 * f; if (sp < 0) { break; } int sum = a + b + c + d + e + f + sp; ll p = p2[a + b + c]; (p *= mod.combination(sum, a)) %= MOD; sum -= a; (p *= mod.combination(sum, b)) %= MOD; sum -= b; (p *= mod.combination(sum, c)) %= MOD; sum -= c; (p *= mod.combination(sum, d)) %= MOD; sum -= d; (p *= mod.combination(sum, e)) %= MOD; sum -= e; (p *= mod.combination(sum, f)) %= MOD; sum -= f; (ans += p) %= MOD; } } } std::cout << ans << std::endl; return 0; }