#include #include #include #include #include #include using namespace std; using ll = long long; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define input(...) __VA_ARGS__; in(__VA_ARGS__) template void print(vector a) { cout << "[ "; REP(i, a.size()) cout << a[i] << " "; cout << "]" << endl; } void print() { std::cout << std::endl; } template void print(Head&& head, Tail&&... tail) { std::cout << head << " "; print(std::forward(tail)...); } void in() { } template void in(Head&& head, Tail&&... tail) { cin >> head; in(std::forward(tail)...); } ll MOD = 1'000'000'007; ll powmod(ll v, ll x) { if (x == 0) return 1; if (x % 2 == 0) { ll tmp = powmod(v, x / 2); return (tmp * tmp) % MOD; } else { return (powmod(v, x - 1) * v) % MOD; } } ll prod(ll left, ll right, vector &cumprod) { // return cumprod[right] / cumprod[left]; return (cumprod[right] * powmod(cumprod[left], MOD - 2)) % MOD; } int main() { ll input(n); vector a(n); REP(i, n) cin >> a[i]; vector cumprod(a.size() + 1, 1); partial_sum(a.begin(), a.end(), cumprod.begin() + 1, [](ll v1, ll v2){ return (v1 * v2) % MOD; }); // print(cumprod); // print(a); vector one(n); ll ones = 0; REP(i, n) { if (a[n - i - 1] == 1) { one[n - i - 1] = ++ones; } else { ones = 0; } } // print(one); ll left = 0; ll p = a[0]; ll ans = 1; FOR(right, 1, n) { while (p >= 1000000000) { p /= a[left++]; } // print("range", left, right, p); ll prv = prod(0, right, cumprod); // print("---"); FOR(i, left, right - 1) { // print(i); if (a[i] == 1) { prv = powmod(prv, one[i]); i += (one[i] - 1); } else prv = prod(i, right, cumprod); // prv = prod(i, right, cumprod); // print(i, prv); (ans *= prv) %= MOD; } if (right < n) p *= a[right]; } print(ans); }