#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; typedef long long ll; const int INF = 1e9; const ll MOD = 998244353; const ll LINF = 1e18; template void get_unique(vector& x) { x.erase(unique(x.begin(), x.end()), x.end()); } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template ostream& operator<<(ostream& os, vector v) { for (int i = 0; i < sz(v); i++) { os << v[i]; if (i < sz(v) - 1) os << " "; } return os; } ll ext_gxd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll q = a / b; ll g = ext_gxd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll modinv(ll a, ll m = MOD) { ll x, y; ext_gxd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll modpow(ll a, ll n, ll m = MOD) { ll ret = 1; ll now = a; while (n > 0) { if (n % 2 == 1) ret = ret * now % m; now = now * now % m; n /= 2; } return ret; } int main() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; ll ans = 0; rep(i, n) { if (abs(a[i]) != 2) continue; int l = i; while (l - 1 >= 0 && abs(a[l - 1]) == 1) l--; int r = i; while (r + 1 < n && abs(a[r + 1]) == 1) r++; ll l1 = 0, l2 = 0, r1 = 0, r2 = 0; ll now = 1; for (int j = i; j >= l; j--) { if (now == 1) { l1 += modpow(2, j - 1); } else { l2 += modpow(2, j - 1); } if (j - 1 >= 0) now *= a[j - 1]; } now = 1; for (int j = i; j <= r; j++) { if (now == 1) { r1 += modpow(2, n - 2 - j); } else { r2 += modpow(2, n - 2 - j); } if (j + 1 < n) now *= a[j + 1]; } if (a[i] == 2) { (ans += l1 * r2 % MOD) %= MOD; (ans += l2 * r1 % MOD) %= MOD; } else { (ans += l1 * r1 % MOD) %= MOD; (ans += l2 * r2 % MOD) %= MOD; } } (ans *= modinv(modpow(2, n - 1))) %= MOD; cout << ans << '\n'; }