#include using namespace std; typedef long long ll; typedef pair PII; const int MM = 1e9 + 7; const double eps = 1e-8; const int MAXN = 2e6 + 10; void prework(){ } void read(){ } ll n, P; ll MAGIC0, MAGIC1; void precalc(){ __int128 x = (((__int128)1)<<63) - (((__int128)1)<<63)%P - 1,t; for(MAGIC1=0;t=((__int128)1)<> 64; if (MAGIC0 < 0) t += x; return x - (t >> (MAGIC1 - 64)) * P; } int f[70000000]; namespace nico{ int a, b, c, d, e; int T; int f[502][20010]; void upd(int &x, int y){ x += y; if (x >= MM) x -= MM; } void gao(){ // cout << "Case #" << casi << ": "; cin >> T; cin >> a >> b >> c >> d >> e; f[0][10000] = 1; for (int i = 1; i <= T; i++){ for (int j = 0; j <= 20000; j++) if (f[i-1][j]){ upd(f[i][j+a], f[i-1][j]); upd(f[i][j+b], f[i-1][j]); upd(f[i][j+c], f[i-1][j]); upd(f[i][j-a], f[i-1][j]); upd(f[i][j-b], f[i-1][j]); upd(f[i][j-c], f[i-1][j]); } } ll ans = 0; for (int i = d + 10000; i <= e + 10000; i++){ ans += f[T][i]; } cout << ans % MM << endl; } } void solve(int casi){ // cout << "Case #" << casi << ": "; n=1000000000000000000ll,P=800000011ll; if (P == 2){ cout << 0 << endl; return ; } //f[0] = 1; ll x = 2; precalc(); ll T, G, U; int flag = 0; n++; if (P < 70000000){ for (int i = 2; i <= n; i++){ x = mod(x * (x + 4)); if (f[x]){ flag = 1; T = (i - f[x]); G = f[x]; U = x; break; } else{ f[x] = i; } } } else{ for (int i = 2; i <= n; i++){ x = mod(x * (x + 4)); //cerr << x << ' ' << (x >> 4) <> 4]){ flag = 1; T = (i - f[x >> 4]); G = f[x >> 4]; U = x; break; } else{ f[x >> 4] = i; } } } } //cout << T << endl; //cout << flag << ' ' << T << ' ' << G << ' ' << U << endl; if (flag){ x = U; ll i = (n - G) % T; for (; i; i--){ x = mod(x * (x + 4)); } //cout << x << endl; if (x != -1) nico::gao(); } else{ if (x != -1) nico::gao(); } } void printans(){ } int main(){ std::ios::sync_with_stdio(false); prework(); int T = 1; // cin>>T; for(int i = 1; i <= T; i++){ read(); solve(i); printans(); } return 0; }