#include #include #include #include #include #include #include #include #include #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; using ull = unsigned long long; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; } //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353; constexpr int MAX = 1100000; struct mint { long long x; mint(long long x = 0) :x((x% mod + mod) % mod) {} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector dp(2, vector(2, vector(3, vector(3)))); vector tw(n + 1); tw[0] = 1; for (int i = 1; i <= n; i++) tw[i] = tw[i - 1] * 2; dp[0][0][0][0] = 1; int cur = 0; int nxt = 1; auto init = [&](int idx)->void { for (int i = 0; i < 2; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) dp[idx][i][j][k] = 0; }; for (int i = 0; i < n; i++) { init(nxt); for (int j = 0; j < 2; j++) { for (int k = 0; k < 3; k++) { dp[nxt][j][k][0] += dp[cur][j][k][0]; int nj = j ^ (a[i] < 0); int nk = k; if (abs(a[i]) == 2) nk = min(2, nk + 1); if (a[i] == 0) nk = 2; if (i)dp[nxt][nj][nk][1] += dp[cur][j][k][0] * tw[i - 1]; else dp[nxt][nj][nk][1] += dp[cur][j][k][0]; dp[nxt][nj][nk][1] += dp[cur][j][k][1]; dp[nxt][j][k][2] += dp[cur][j][k][1] * tw[n - 1 - i]; dp[nxt][j][k][2] += dp[cur][j][k][2]; } } swap(cur, nxt); } mint res = 0; res += dp[cur][1][1][1] + dp[cur][1][1][2]; //cout << res.x << "\n"; res *= mint(2).pow(n - 1).inv(); cout << res.x << "\n"; }