#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; constexpr ll m = 1'000'000'007; if (*min_element(a.begin(), a.end()) == 0) { cout << -1 << '\n'; } else if (*max_element(a.begin(), a.end()) >= 4) { cout << m << '\n'; } else { ll p = 1; rep(i, n) { if (a[i] == 1) p *= 1; if (a[i] == 2) p *= 2 * 2; if (a[i] == 3) p *= 3 * 3 * 3 * 3 * 3 * 3; if (p > m) { cout << m << '\n'; return 0; } } cout << m % p << '\n'; } return 0; }