//#include //using namespace atcoder; #include using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i=0; i--) #define FOR(i, m, n) for(int i=m; i; using vvi = vector>; using vvl = vector>; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const ll LINF = (1LL<<60); const ll m = 1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n); REP(i,n) cin >> a[i]; if(*min_element(ALL(a))==0){ cout << -1 << endl; return 0; } if(*max_element(ALL(a))>=4){ cout << 1e9+7 << endl; return 0; } ll ans = 1; REP(i,n){ ll kai = 1; FOR(j,1,a[i]+1) kai *= j; ans *= ll(pow(a[i],kai)); if(ans>m) break; } cout << m%ans << endl; return 0; }