#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Pll = pair; using Pii = pair; constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 60; constexpr ll MOD = 1000000007; constexpr ll MAX = 1000000000; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; ll modpow(ll a, ll t) { if(t < 0) assert(false); ll ret = 1LL; while(t){ if(t & 1LL){ ret *= a; ret %= MOD; } a *= a; a %= MOD; t >>= 1; } return ret; } ll modinv(ll a) { return modpow(a, MOD-2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n+1, 1); bool includes_zero = false; for(int i=1;i<=n;++i) { cin >> a[i]; includes_zero |= !a[i]; } if(includes_zero) { cout << 0 << endl; return 0; } vector r(n+1, 0); r[0] = 1; ll p = 1LL; for(int i=1;i<=n;++i) { r[i] = max(i, r[i-1]); if(r[i] == i) p = 1LL; while(r[i] <= n) { if(a[r[i]] >= MAX/p) { break; } else { p *= a[r[i]]; ++r[i]; } } p /= a[i]; } vector weighted_product(n+1, 1); vector product(n+1, 1); for(int i=1;i<=n;++i) { weighted_product[i] = (weighted_product[i-1] * modpow(a[i], n+1-i)) % MOD; product[i] = (product[i-1] * a[i]) % MOD; } ll ans = 1LL; for(int i=1;i<=n;++i) { ll tmp = (weighted_product[r[i]-1] * modinv(weighted_product[i-1])) % MOD; tmp = (tmp * modpow(modinv((product[r[i]-1] * modinv(product[i-1])) % MOD), n+1-r[i])) % MOD; ans *= tmp; ans %= MOD; } cout << ans << endl; }