#include #include #include namespace ac = atcoder; using mint = ac::modint998244353; void solve() { int n; std::cin >> n; std::vector xs(n); for (auto& x : xs) std::cin >> x; std::vector inv2(n + 1, 0); inv2[n] = mint(2).pow(n).inv(); for (int i = n - 1; i >= 0; --i) inv2[i] = inv2[i + 1] * 2; mint ans = 0; for (int s = 0; s < n; ++s) { if (std::abs(xs[s]) != 2) continue; std::vector left(2, 0); { int sign = 0, bar = (s > 0); left[sign] = inv2[bar]; for (int i = s - 1; i >= 0 && std::abs(xs[i]) == 1; --i) { if (xs[i] < 0) sign = 1 - sign; if (i > 0) ++bar; left[sign] += inv2[bar]; } } std::vector right(2, 0); { int sign = (xs[s] < 0), bar = (s < n - 1); right[sign] = inv2[bar]; for (int i = s + 1; i < n && std::abs(xs[i]) == 1; ++i) { if (xs[i] < 0) sign = 1 - sign; if (i < n - 1) ++bar; right[sign] += inv2[bar]; } } ans += left[0] * right[1] + left[1] * right[0]; } std::cout << ans.val() << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }