//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} constexpr ll u = 1'000'000'007; //head int cnt[5]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; rep(i, n) { int a; cin >> a; if(a > 3) cnt[4]++; else cnt[a]++; } if(cnt[0]) cout << -1 << endl; else if(cnt[4]) cout << u << endl; else { ll th = 1; rep(i, cnt[2]) { th *= 4; if(th > u) { cout << u << endl; return 0; } } rep(i, cnt[3]) { th *= 729; if(th > u) { cout << u << endl; return 0; } } cout << u%th << endl; } }