#include using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair ll memo[4] = {0, 1, 4, 729}; const ll MOD = 10e8 + 7; int main() { ll n; cin >> n; ll ans = 1; rep(i, n) { int a; cin >> a; if (a >= 4) { cout << MOD << endl; return 0; } if (a == 0) { cout << -1 << endl; return 0; } ans *= memo[a]; if (ans > MOD) { cout << MOD << endl; return 0; } } cout << MOD % ans << endl; }