#include using namespace std; int main() { const int x[4] = { 0, 1, 4, 729 }; int n; cin >> n; vector a(n); bool big = false; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) { cout << -1 << endl; return 0; } if (a[i] >= 4) { big = true; } } if (big) { cout << 1000000007 << endl; return 0; } int64_t p = 1; for (int i = 0; i < n; i++) { p *= x[a[i]]; if (p >= 1000000007) { cout << 1000000007 << endl; } } cout << 1000000007 % p << endl; }