#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; typedef bitset<16> BS; const ll MOD = 998244353; const ll INF = 1E18; const int MAX_N = 2E+05; int N; ll A[MAX_N + 1], L[MAX_N + 1][2], R[MAX_N + 1][2]; ll modPow(ll x, ll a); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 1; i <= N;) { if (A[i] == 2 || A[i] == -2) { int j = i, res = 1; while (true) { if (res == -1) { R[i][0] += modPow(2, max(0, N - j - 1)); R[i][0] %= MOD; } else { R[i][1] += modPow(2, max(0, N - j - 1)); R[i][1] %= MOD; } j++; res *= A[j]; if (!(A[j] == 1 || A[j] == -1) || j > N) break; } i = j; } else { i++; } } for (int i = N; i >= 1;) { if (A[i] == 2 || A[i] == -2) { int j = i, res = 1; while (true) { if (res == -1) { L[i][0] += modPow(2, max(0, j - 2)); L[i][0] %= MOD; } else { L[i][1] += modPow(2, max(0, j - 2)); L[i][1] %= MOD; } j--; res *= A[j]; if (!(A[j] == 1 || A[j] == -1) || j < 1) break; } i = j; } else { i--; } } /* for (int i = 1; i <= N; i++) { cout << "i = " << i << ", L0 = " << L[i][0] << ", L1 = " << L[i][1] << "\n"; } for (int i = 1; i <= N; i++) { cout << "i = " << i << ", R0 = " << R[i][0] << ", R1 = " << R[i][1] << "\n"; } */ ll ans = 0; for (int i = 1; i <= N; i++) { if (A[i] == 2) { ll res = L[i][1] * R[i][0] + L[i][0] * R[i][1]; res %= MOD; ans += res; ans %= MOD; } else if (A[i] == -2) { ll res = L[i][0] * R[i][0] + L[i][1] * R[i][1]; res %= MOD; ans += res; ans %= MOD; } //cout << "i = " << i << ", ans = " << ans << "\n"; } ll Q = modPow(2, N - 1); Q = modPow(Q, MOD - 2); ans *= Q; ans %= MOD; /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ cout << ans << "\n"; return 0; } ll modPow(ll x, ll a) { ll ans = 1; while (a > 0) { if (a & 1) { ans = (ans * x) % MOD; } x = (x * x) % MOD; a >>= 1; } return ans; }