#include using namespace std; constexpr int mod = 1000000007; constexpr long long M = 1e9; long long modpow(long long a, long long r) { assert(r > 0); long long ret = 1; while (r) { if (r & 1) ret = ret * a % mod; r >>= 1; a = a * a % mod; } return ret; } long long solve(vector &A) { int N = A.size(); long long curr = 1; long long Ans = 1; int l = 0; vector C(N+1, 0), D(N+1, 0); for (int i = 0; i < N; i++) { curr *= A[i]; while (curr > M) { C[l] += i - l; D[l] += 1, D[i] -= 1; curr = curr / A[l]; l++; } } while (l < N) { C[l] += N - l; D[l] += 1, D[N] -= 1; l++; } for (int i = 0; i < N; i++) { Ans = Ans * modpow(A[i], C[i]) % mod; D[i+1] += D[i]; C[i+1] += C[i] - D[i]; } return Ans; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector A; long long Ans = 1; for (int i = 0; i < N; i++) { long long x; cin >> x; if (x == 0) { Ans = Ans * solve(A) % mod; A.clear(); } else { A.emplace_back(x); } } if (!A.empty()) Ans = Ans * solve(A) % mod; cout << Ans << "\n"; return 0; }