#include // #include using namespace std; // using namespace atcoder; #define rep2(i,m,n) for (int i = (m); i < (n); ++i) #define rep(i,n) rep2(i,0,n) typedef long long int ll; typedef long double ld; typedef pair P; template struct V : vector { using vector::vector; }; V() -> V; V(size_t) -> V; template V(size_t, T) -> V; template vector make_vec(size_t n, T a) { return vector(n, a); } template auto make_vec(size_t n, Ts... ts) { return vector(n, make_vec(ts...)); } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1<<30; const ll LINF = 1LL<<61; const ll MOD = 998244353; struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; } mint operator+(const mint rh) const { return mint(*this) += rh; } mint operator-(const mint rh) const { return mint(*this) -= rh; } mint operator*(const mint rh) const { return mint(*this) *= rh; } mint pow(ll k) const { if(!k) return 1; mint a = x; mint res = 1; while(k) { if(k & 1) res *= a; k >>= 1; a *= a; } return res; } mint inv() const { return pow(MOD-2); } mint& operator/=(const mint rh) { return *this *= rh.inv(); } mint operator/(const mint rh) { return mint(*this) /= rh; } }; long long mpow(long long x, int k, long long MOD = MOD) { long long res = 1; while(k) { if(k & 1) res = (res * x) % MOD; k >>= 1; x = (x * x) % MOD; } return res; } long long modinv(long long a, long long m = MOD) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main() { int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; vector dp0(6), dp1(6); int ofs = 2; dp1[a[0] + ofs] = 1; for(int i=1; i dp02(6), dp12(6); for(int j=-2; j<=3; j++) { //区切らない int nj = j * a[i]; if(abs(nj) <= 2) { dp02[nj+ofs] += dp0[j+ofs]; dp12[nj+ofs] += dp1[j+ofs]; } else { dp02[5] += dp0[j+ofs]; dp12[5] += dp1[j+ofs]; } //区切る nj = a[i]; if(j == -2) { dp02[nj+ofs] += dp0[j+ofs] + dp1[j+ofs]; } else { dp02[nj+ofs] += dp0[j+ofs]; } dp12[nj+ofs] += dp1[j+ofs]; } swap(dp0, dp02); swap(dp1, dp12); } mint q = mpow(2, n-1); mint ans = dp1[0]; rep(i,6) ans += dp0[i]; ans /= q; cout << ans.x << endl; return 0; }