#include #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; const ll mod = int(1e9) + 7; int main() { ll N; cin >> N; vector a(N); rep(i, N) { cin >> a[i]; } sort(a.begin(), a.end()); if (a[0] == 0) { cout << -1 << endl; return 0; } ll ans = 1; rep(i, N) { if (a[i] >= 4) { cout << mod << endl; return 0; } ll div = 1; rep(j, a[i]) { div *= (j + 1); } // cerr << "div" << div << endl; rep(j, div) { ans *= a[i]; if (ans > (mod)) { break; } } } cout << mod % ans << endl; return 0; }