#include #include #include #include #include #include #include #define N_MAX 200002 using namespace std; typedef long long ll; ll fac[N_MAX]; void init(ll MOD){ fac[0]=1;fac[1]=1; for(int i=2;i T pow(T a, ll n, ll MOD) { T ans = 1; T tmp = a; for (int i = 0; i <= 60; i++) { ll m = (ll)1 << i; if (m & n) { ans *= tmp; ans %= MOD; } tmp *= tmp; tmp %= MOD; } return ans; } const ll p = 1000000007; int N; ll A[200000]; ll c[4] = {1, 1, 4, 729}; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N; bool too_big = false; for(int i = 0; i < N; i++) { cin >> A[i]; if(A[i] >= 4) too_big = true; } if(too_big){ cout << p << endl; return 0; } ll ans = 1; for(int i = 0; i < N; i++){ ans *= c[A[i]]; if(ans > p){ cout << p << endl; return 0; } } cout << p%ans << endl; }