Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll MOD = 1e9+7;

ll add(ll x, ll y){
    return (x+y)%MOD;
}

ll mul(ll x, ll y){
    return (x%MOD)*(y%MOD)%MOD;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= MOD;
        x = (x*x) % MOD;
        y >>= 1LL;
    }
    return res;
}

ll div(ll x, ll y){
    return (x * powll(y,MOD-2)) % MOD;
}

ll nPr(ll n, ll r){
    ll res = 1LL;
    FOR(i,1,r){
        res = (res * ((n-i+1) % MOD)) % MOD;
    }
    return res;
}

ll nCr(ll n, ll r){
    ll res = nPr(n,r);
    FOR(i,1,r){
        res = (res * powll(i,MOD-2)) % MOD;
    }
    return res;
}

ll dp[1001][1001];
ll a, b, c, d;

ll calc(int n, ll x){
    if (dp[n][x] > 0) return dp[n][x];
    if (n == 0) return dp[n][x] = 1;
    if (x > n || x > b) return 0;
    ll res = calc(n,x+1), p = 1;
    // cout << n << " " << x << endl;
    FOR(i,c,d){
        ll y = x * i;
        if (y > n) break;
        if (i == c){
            REP(j,c){
                p = (p * nCr(n-j*x, x)) % MOD;
            }
            p = div(p, (ll)c);
        }else{
            ll m = n - x*(i-1);
            p = (p * nCr(m, x)) % MOD;
            p = div(p, (ll)i);
        }
        // printf("%d %lld %d %lld %lld\n", n, x, i, p, calc(n-y,x+1));
        res = (res + p * calc(n-y, x+1)) % MOD;
    }
    return dp[n][x] = res;
}

int main() {
    int n;
    cin >> n >> a >> b >> c >> d;
    ll ans = 0;

    ans = calc(n,a);
    cout << ans << endl;

    // REP(i,n+1){
    //     REP(j,n+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}

Compiler output:
a.cc: In function 'll calc(int, ll)':
a.cc:85:20: error: call of overloaded 'div(ll&, ll)' is ambiguous
   85 |             p = div(p, (ll)c);
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/stdlib.h:992:14: note: candidate: 'div_t div(int, int)'
  992 | extern div_t div (int __numer, int __denom)
      |              ^~~
a.cc:49:4: note: candidate: 'll div(ll, ll)'
   49 | ll div(ll x, ll y){
      |    ^~~
/usr/include/c++/14/cstdlib:219:3: note: candidate: 'lldiv_t __gnu_cxx::div(long long int, long long int)'
  219 |   div(long long __n, long long __d)
      |   ^~~
/usr/include/c++/14/cstdlib:181:3: note: candidate: 'ldiv_t std::div(long int, long int)'
  181 |   div(long __i, long __j) _GLIBCXX_NOTHROW { return ldiv(__i, __j); }
      |   ^~~
a.cc:89:20: error: call of overloaded 'div(ll&, ll)' is ambiguous
   89 |             p = div(p, (ll)i);
      |                 ~~~^~~~~~~~~~
/usr/include/stdlib.h:992:14: note: candidate: 'div_t div(int, int)'
  992 | extern div_t div (int __numer, int __denom)
      |              ^~~
a.cc:49:4: note: candidate: 'll div(ll, ll)'
   49 | ll div(ll x, ll y){
      |    ^~~
/usr/include/c++/14/cstdlib:219:3: note: candidate: 'lldiv_t __gnu_cxx::div(long long int, long long int)'
  219 |   div(long long __n, long long __d)
      |   ^~~
/usr/include/c++/14/cstdlib:181:3: note: candidate: 'ldiv_t std::div(long int, long int)'
  181 |   div(long __i, long __j) _GLIBCXX_NOTHROW { return ldiv(__i, __j); }
      |   ^~~