#include using namespace std; const long long MOD = 998244353; const long long INV = 499122177; long long modpow(long long a, long long b){ long long ans = 1; while (b > 0){ if (b % 2 == 1){ ans *= a; ans %= MOD; } a *= a; a %= MOD; b /= 2; } return ans; } long long modinv(long long a){ return modpow(a, MOD - 2); } vector ntt(vector A, bool inv){ int N = A.size(); long long r = 3; if (inv){ r = modinv(r); } vector B(N); for (int i = N / 2; i > 0; i /= 2){ long long z = modpow(r, (MOD - 1) / (N / i)); long long z2 = 1; for (int j = 0; j < N; j += i * 2){ for (int k = 0; k < i; k++){ A[i + j + k] *= z2; A[i + j + k] %= MOD; B[j / 2 + k] = (A[j + k] + A[i + j + k]) % MOD; B[N / 2 + j / 2 + k] = (A[j + k] - A[i + j + k] + MOD) % MOD; } z2 = z2 * z % MOD; } swap(A, B); } if (inv){ int Ninv = modinv(N); for (int i = 0; i < N; i++){ A[i] = A[i] * Ninv % MOD; } } return A; } vector convolution(vector A, vector B, int d = -1){ int deg = A.size() + B.size() - 1; int N = 1; while (N < deg){ N *= 2; } A.resize(N); B.resize(N); A = ntt(A, false); B = ntt(B, false); vector ans(N); for (int i = 0; i < N; i++){ ans[i] = A[i] * B[i] % MOD; } ans = ntt(ans, true); if (d != -1){ deg = d; } ans.resize(deg); return ans; } int main(){ int N; cin >> N; vector a(N + 2, 0); for (int i = 1; i <= N; i++){ cin >> a[i]; } N += 2; vector pow(N); pow[0] = 1; for (int i = 1; i < N; i++){ pow[i] = pow[i - 1] * INV % MOD; } long long ans = 0; for (int i = 0; i < N; i++){ if (abs(a[i]) == 2){ vector L1, L2; L1.push_back(0); L2.push_back(0); int p = 1; for (int j = i - 1; j >= 0; j--){ if (abs(a[j]) == 1){ p *= a[j]; if (p == 1){ L1.push_back(1); L2.push_back(0); } else { L1.push_back(0); L2.push_back(1); } } else { break; } } vector R1, R2; R1.push_back(0); R2.push_back(0); p = 1; for (int j = i + 1; j < N; j++){ if (abs(a[j]) == 1){ p *= a[j]; if (p == 1){ R1.push_back(1); R2.push_back(0); } else { R1.push_back(0); R2.push_back(1); } } else { break; } } if (a[i] == 2){ vector C1 = convolution(L1, R2); int sz1 = C1.size(); for (int j = 0; j < sz1; j++){ ans += C1[j] * pow[j + 2] % MOD; ans %= MOD; } vector C2 = convolution(L2, R1); int sz2 = C2.size(); for (int j = 0; j < sz2; j++){ ans += C2[j] * pow[j + 2] % MOD; ans %= MOD; } } else { L1[0] = 1; R1[0] = 1; vector C1 = convolution(L1, R1); int sz1 = C1.size(); for (int j = 0; j < sz1; j++){ ans += C1[j] * pow[j + 2] % MOD; ans %= MOD; } vector C2 = convolution(L2, R2); int sz2 = C2.size(); for (int j = 0; j < sz2; j++){ ans += C2[j] * pow[j + 2] % MOD; ans %= MOD; } ans %= MOD; } } } int prod = 1; for (int i = 1; i < N - 2; i++){ prod *= a[i]; if (prod == -2){ ans += MOD - pow[i + 1]; ans += pow[i]; } else if (abs(prod) > 2 || prod == 0){ break; } } prod = 1; for (int i = N - 2; i >= 1; i--){ prod *= a[i]; if (prod == -2){ if (i > 1){ ans += MOD - pow[N - i]; ans += pow[N - 1 - i]; } else { ans += MOD - pow[N - i]; ans += pow[N - 2 - i]; } } else if (abs(prod) > 2 || prod == 0){ break; } } ans %= MOD; cout << ans << endl; }