#pragma GCC optimize("Ofast", "unroll-loops") #pragma GCC target("avx2") #include using namespace std; #define ll long long constexpr ll mod = 998244353LL; ll modpow(ll a, int b){ if (b == 0) return 1LL; ll tmp = modpow(a, b / 2); tmp = tmp * tmp % mod; if (b % 2 == 0) return tmp; return tmp * a % mod; } ll inverse(ll a){ return modpow(a, mod - 2); } int N; vector A; void input(void){ cin >> N; A.resize(N); for (int& ai : A) cin >> ai; } ll solve(void){ constexpr int offset = 2; static ll dp[2][5]; dp[0][A[0] + offset] = 1LL; ll ret = dp[0][0]; ll tmp = 1LL; for (int i = 1; i < N; ++i){ int a = A[i]; for (int j = 0; j < 5; ++j) dp[i & 1][j] = 0; dp[i & 1][a + offset] = tmp; for (int prv = -2; prv <= 2; ++prv){ int nxt = prv * a; if (abs(nxt) <= 2){ dp[i & 1][nxt + offset] += dp[(i - 1) & 1][prv + offset]; dp[i & 1][nxt + offset] %= mod; } } if (i < N - 1) ret = ret * 2 % mod; ret += dp[i & 1][0]; tmp = tmp * 2 % mod; } return ret * inverse(tmp) % mod; } int main(void){ input(); cout << solve() << endl; return 0; }