#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; constexpr ll mod = 1e9+7; int main() { int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; sort(a.begin(), a.end()); if (a.front() == 0LL) { cout << -1 << endl; return 0; } if (a.back() >= 4LL) { cout << mod << endl; return 0; } ll res = 1; for (int i = 0; i < n; i++) { int fact = 1; for (int j = 0; j < a[i]; j++) fact *= (j + 1); for (int j = 0; j < fact; j++) res *= a[i]; } cout << mod % res << endl; return 0; }