Language: C++

#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

//Repeat Square Method x^n MOD 
long long RSM(long long x, long long n, long long MOD) {
	long long y = 1;
	for (; n > 0; n >>= 1, (x *= x) %= MOD) if (n & 1) (y *= x) %= MOD;
	return y;
}

vector<long long> Factorial(int N, long long mod){
	vector<long long> ret(N + 1,1);
	for (int i = 1; i < N + 1; ++i) (ret[i] *= (i*ret[i - 1]) %mod) %= mod;
	return ret;
}

vector<vector<long long>> Permutation(int N, long long mod) {
	vector<long long> fac(N + 1, 1);
	for (int i = 1; i < N + 1; ++i) (fac[i] *= (i*fac[i - 1]) % mod) %= mod;
	vector<long long> inv(N + 1, 1);
	for (int i = 1; i < N + 1; ++i) inv[i] = RSM(fac[i],mod-2,mod);
	vector<vector<long long>> ret(N + 1,vector<long long>(N + 1, 1));
	for (int i = 1; i < N + 1; ++i) for (int j = 1; j < i; ++j) ret[i][j] = (fac[i] * inv[i - j]) % mod;
	return ret;
}

int main() {
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	auto Fact = Factorial(N, MOD);
	auto Perm = Permutation(N, MOD);
	V<V<ll>> Factk(N + 1, V<ll>(N + 1, 1));
	FOR(i, 1, N + 1) FOR(j, 1, N + 1) Factk[i][j] = (Factk[i][j - 1] * Fact[i]) % MOD;


	V<V<ll>> dp(N + 1, V<ll>(N + 1, 0));
	dp[A-1][0] = 1;
	FOR(i,A,B+1){
		FOR(j,0,N + 1){
			(dp[i][j] += dp[i - 1][j]) %= MOD;



			REP(k, D - C + 2) {
				if (N - (j - g[k] * i) < 0 || j - g[k] * i < 0) continue;
				ll cnt = 1;
				(cnt *= dp[i - 1][j - g[k] * i]) %= MOD;
				(cnt *= Perm[N - (j - g[k] * i)][g[k] * i]) %= MOD;
				(cnt *= RSM(Factk[i][g[k]], MOD - 2, MOD)) %= MOD;
				(cnt *= RSM(Fact[g[k]], MOD - 2, MOD)) %= MOD;
				(dp[i][j] += cnt) %= MOD;
			}

		}
	}
	ll ans = dp[B][N];
	REP(i, B + 1) print("dp",i, dp[i]);
	print("k", g);
	print("Fact", Fact);
	REP(i, N)print("PErm",i,Perm[i]);
	REP(i, N)print("Factk",i,Factk[i]);
	cout << ans << endl;
	cin >> N;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:88:46: error: 'g' was not declared in this scope
   88 |                                 if (N - (j - g[k] * i) < 0 || j - g[k] * i < 0) continue;
      |                                              ^
a.cc:90:55: error: 'g' was not declared in this scope
   90 |                                 (cnt *= dp[i - 1][j - g[k] * i]) %= MOD;
      |                                                       ^
a.cc:101:20: error: 'g' was not declared in this scope
  101 |         print("k", g);
      |                    ^