// #define _GLIBCXX_DEBUG // for STL debug (optional) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__) #define int long long int template void chmax(T &a, T b) {a = max(a, b);} template void chmin(T &a, T b) {a = min(a, b);} template void chadd(T &a, T b) {a = a + b;} typedef pair pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; // 各種組み合わせを求めるライブラリ template struct Combination { int LIMIT; vector fact_, finv_; Combination() {} Combination(int LIMIT_) : LIMIT(LIMIT_), fact_(LIMIT+1), finv_(LIMIT+1) { fact_[0] = finv_[LIMIT] = NumType(1); for(int i=1; i<=LIMIT; i++) { fact_[i] = fact_[i-1] * NumType(i); } finv_[LIMIT] /= fact_[LIMIT]; for(int i=LIMIT-1; i>=0; i--) { finv_[i] = finv_[i+1] * NumType(i+1); } } inline NumType fact(int k) const { return fact_[k]; } inline NumType finv(int k) const { return finv_[k]; } NumType P(int n, int r) const { if(r < 0 or n < r) return NumType(0); return fact_[n] * finv_[n-r]; } NumType C(int n, int r) const { if(r < 0 or n < r) return NumType(0); return fact_[n] * finv_[n-r] * finv_[r]; } // 重複組み合わせ NumType H(int n, int r) const { if(n < 0 or r < 0) return NumType(0); return r == 0 ? NumType(1) : C(n + r - 1, r); } // ベル数 (区別できる n 個のボールを区別できない k 個以下の箱に分割) // B(n, n) := n 個のボールを任意個のグループに分割する場合の数 NumType B(int n, int k) const { if(n == 0) return NumType(1); k = min(n, k); NumType ret(0); vector pref(k + 1); pref[0] = NumType(1); for(int i=1; i<=k; i++) { if(i & 1) pref[i] = pref[i-1] - finv_[i]; else pref[i] = pref[i-1] + finv_[i]; } for(int i=1; i<=k; i++) { // 累乗が必要なので適宜書き換える? // ModInt 使うならこれでいい ret += NumType(i).pow(n) * finv_[i] * pref[k-i]; } return ret; } // スターリング数 (区別できる n 個のボールを区別できない k 個の箱に分割) NumType S(int n, int k) const { if(n < k) return NumType(0); NumType ans(0); for(int i=0; i<=k; i++) { NumType val = C(k, i) * NumType(i).pow(n); if((k - i) % 2) ans -= val; else ans += val; } return ans * finv_[k]; } }; // P(n, k) := n の k 分割 (k 個の 0 以上の整数の和) template struct Partition { vector< vector > dp; Partition() : dp(LIMIT, vector(LIMIT)) { for(int k=0; k= 0) dp[i][j] += dp[i-j][j]; } } } inline NumType get(int n, int k) { if(n < 0 or k < 0) return NumType(0); return dp[n][k]; } }; // ModInt begin using ll = long long; template struct ModInt { ll v; ll mod_pow(ll x, ll n) const { return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod; } ModInt(ll a = 0) : v(a >= mod ? a % mod : a) {} ModInt operator+ ( const ModInt& b ) const { return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v)); } ModInt operator- () const { return ModInt(-v); } ModInt operator- ( const ModInt& b ) const { return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v)); } ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;} ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;} bool operator== ( const ModInt &b ) const {return v == b.v;} ModInt& operator+= ( const ModInt &b ) { v += b.v; if(v >= mod) v -= mod; return *this; } ModInt& operator-= ( const ModInt &b ) { v -= b.v; if(v < 0) v += mod; return *this; } ModInt& operator*= ( const ModInt &b ) { (v *= b.v) %= mod; return *this; } ModInt& operator/= ( const ModInt &b ) { (v *= mod_pow(b.v, mod-2)) %= mod; return *this; } ModInt pow(ll x) { return ModInt(mod_pow(v, x)); } // operator int() const { return int(v); } // operator long long int() const { return v; } }; template ostream& operator<< (ostream& out, ModInt a) {return out << a.v;} template istream& operator>> (istream& in, ModInt& a) { in >> a.v; return in; } // ModInt end const int S = 6010; signed main() { int N, R, G, B; cin >> N >> R >> G >> B; using mint = ModInt<1000000007LL>; Combination comb(S); vector pow2(S, mint(1)); for(int i=1; i B) continue; // 単体で使う B int w = B - z; // 余白が少なくとも x+y+z+w-1 個必要 if(space < x + y + z + w - 1) continue; int rem_space = space - (x + y + z + w - 1); // RG, RB, GB の順番、余白のいれかた mint mul = pow2[z] * pow2[x] * comb.H(x+y+z+w+1, rem_space); // 各パターンをどこにおくか mul *= comb.fact(x+y+z+w); mul *= comb.finv(x) * comb.finv(y) * comb.finv(z) * comb.finv(w); // RG で使われない R, G を配置 int NR = R - x, NG = G - x; mul *= comb.C(rem, NR) * comb.C(y, rem - z); ans += mul; } } cout << ans << endl; return 0; }