#include using namespace std; template struct modint{ long long val; modint(): val(0) {} modint(long long x){ if(x < 0) val = x % MOD + MOD; else val = x % MOD; } modint(const modint &t){ val = t.val; } modint& operator =(const modint m){ val = m.val; return *this; } modint operator -(){ return modint(-val); } modint& operator-=(const modint &m){ val -= m.val; if(val < 0) val += MOD; return *this; } modint& operator+=(const modint &m){ val += m.val; if(val >= MOD) val -= MOD; return *this; } modint& operator*=(const modint &m){ val *= m.val; val %= MOD; return *this; } modint& operator/=(modint m){ *this *= m.inv(); return *this; } modint inv(){ long long x = 1, y = 0; long long a = val, b = MOD; while(b != 0){ long long t = a / b; a -= t * b; x -= t * y; swap(a, b); swap(x, y); } x %= MOD; if(x < 0) x += MOD; return modint(x); } modint pow(long long k){ long long res = 1; long long v = val; while(k > 0){ if(k & 1) res = res * v % MOD; v = v * v % MOD; k >>= 1; } return modint(res); } bool operator==(const modint &m){ return val == m.val; } modint operator+(const modint &m){ return modint(*this) += m; } modint operator-(const modint &m){ return modint(*this) -= m; } modint operator*(const modint &m){ return modint(*this) *= m; } modint operator/(const modint &m){ return modint(*this) /= m; } bool operator!=(const modint &m){ return modint(*this).val != m.val; } bool operator!=(const int &m){ return modint(*this).val != m; } }; const int MOD = 998244353; using mint = modint; const int MAX = 410000; mint fac[MAX], finv[MAX], inv[MAX]; void COMinit(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i; inv[i] = mint(MOD) - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } mint COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } int main(){ int N; cin >> N; vector B(N); for(int i = 0; i < N; i++) cin >> B[i]; vector> dp(2, vector(N)); vector cnt(300000); for(int i = 1; i < 300000; i++){ int ni = 2; while(i >= ni){ cnt[i] += i / ni; ni *= 2; } } for(int i = 0; i < N; i++){ int rest = cnt[N - 1] - cnt[i] - cnt[N - 1 - i]; if(i == 0){ if(B[i] == -1){ dp[0][i] = 1; dp[1][i] = 1; } else{ dp[B[i]][i] = 1; } } else{ if(rest > 0){ if(B[i] == -1){ dp[1][i] = dp[1][i - 1] * 2; dp[0][i] = dp[0][i - 1] * 2; } else{ dp[1][i] = dp[1][i - 1]; dp[0][i] = dp[0][i - 1]; } } else{ if(B[i] == 0){ dp[0][i] = dp[0][i - 1]; dp[1][i] = dp[1][i - 1]; } else if(B[i] == 1){ dp[1][i] = dp[0][i - 1]; dp[0][i] = dp[1][i - 1]; } else{ dp[1][i] = dp[1][i - 1] + dp[0][i - 1]; dp[0][i] = dp[1][i - 1] + dp[0][i - 1]; } } } } cout << dp[1][N - 1].val << endl; }