#include using namespace std; using ll = long long; const ll modc = 1e9+7; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); //A=0ならA^{A!} = 0^1 = 0 ll N, ans=1; cin >> N; vector A(N); //答えが1e9+7を超えたら1e9+7 //A=1で1,A=2で4, A=3で729, 4以上は考えない for (int i=0; i> A[i]; if (A[i] == 0){ cout << -1 << endl; return 0; } } for (int i=0; i= 4){ cout << modc << endl; return 0; } if (A[i] == 1) ans *= 1; if (A[i] == 2) ans *= 4; if (A[i] == 3) ans *= 729; if (ans > modc){ cout << modc << endl; return 0; } } cout << modc % ans << endl; return 0; }