#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; const ll MOD = 1e9 + 7; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { if (A[i] == 0) { cout << -1 << endl; return 0; } } for (int i = 0; i < N; i++) { if (A[i] >= 4) { cout << MOD << endl; return 0; } } ll now = 1; const int d[] = {1, 1, 2, 6}; for (int i = 0; i < N; i++) { for (int j = 0; j < d[A[i]]; j++) { now *= A[i]; if (now > MOD) { cout << MOD << endl; return 0; } } } cout << MOD % now << endl; return 0; }