#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; ll limit = 1000000007; ll modpow(ll x, ll n) { ll ans = 1; while(n > 0) { if(n % 2 == 1) { ans *= x; // ans %= MOD; if(ans > limit) { return -1; } } x *= x; // x %= MOD; if(ans > limit) { return -1; } n >>= 1; } return ans; } int main() { int n; cin >> n; ll num = 1; for(int i = 0; i < n; i++) { ll tmp, a, cnt = 1; cin >> a; if(a < 2) { continue; } tmp = a; while(tmp--) { cnt *= (tmp + 1); } num *= modpow(a, cnt); if(num > limit) { cout << limit << '\n'; return 0; } else if(num < 0) { cout << limit << '\n'; return 0; } } if(limit % num == 0) { cout << -1 << '\n'; } else { cout << limit % num << '\n'; } return 0; }