#include using namespace std; #include //using namespace atcoder; using ll = long long; using ull = unsigned long long; using i128 = __int128_t; using u128 = unsigned __int128_t; using mint = atcoder::static_modint<1000000007>; const int mod = 1000000007; #include mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}; int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; template bool chmin(T& a, const T& b){ if (b < a){ a = b; return true; } else { return false; } } template bool chmax(T& a, const T& b){ if (a < b){ a = b; return true; } else { return false; } } void solve(){ int n; cin >> n; vector a(n); bool ok = true; for (int i = 0; i < n; i++){ cin >> a[i]; if (a[i] == 0){ ok = false; } } if (!ok){ cout << -1 << '\n'; return; } ll now = 1; for (int i = 0; i < n; i++){ if (a[i] == 1){ continue; } if (a[i] >= 4){ cout << mod << '\n'; return; } if (a[i] == 2){ for (int j = 0; j < 2; j++){ now *= a[i]; if (now > mod){ cout << mod << '\n'; return; } } } else { for (int j = 0; j < 6; j++){ now *= a[i]; if (now > mod){ cout << mod << '\n'; return; } } } } cout << mod % now << '\n'; }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; while(t--){ cout << fixed << setprecision(15); solve(); } }