//答え「で」10^9 + 7を割った余りなので、答え > 10^9 + 7 なら速攻で0を返してOK。 #include #define int long long using namespace std; int mod = 1000000007; int n; int a[200000]; signed main() { int i; int ans = 1; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= 4) { cout << mod << endl; return 0; } if (a[i] == 0) { cout << -1 << endl; return 0; } if (a[i] == 2) { ans *= 4; } if (a[i] == 3) { ans *= 729; } if (ans > mod) { cout << mod << endl; return 0; } } cout << mod % ans << endl; return 0; }