const MOD: isize = 998244353; const OFFSET: isize = 2; fn power(base: isize, times: isize) -> isize { if times == 0 { return 1isize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut p2s = vec![1isize; n+1]; for i in 1..n { p2s[i+1] = p2s[i] * 2 % MOD; } let mut dp = vec![vec![0isize; 6]; n+1]; dp[0][3] = 1; let mut result = 0isize; for i in 0..n { for j in -2..=3 { let jidx = j+OFFSET; let jidx = jidx as usize; if dp[i][jidx] == 0 { continue; } if a[i].abs() * j.abs() <= 2 { let idx = a[i] * j + OFFSET; let idx = idx as usize; dp[i+1][idx] += dp[i][jidx]; dp[i+1][idx] %= MOD; if idx == 0 { result += dp[i][jidx] * p2s[n-i-1] % MOD; result %= MOD; } } else { dp[i+1][5] += dp[i][jidx]; dp[i+1][5] %= MOD; } if i == 0 { continue; } let idx = a[i] + OFFSET; let idx = idx as usize; dp[i+1][idx] += dp[i][jidx]; dp[i+1][idx] %= MOD; if idx == 0 { result += dp[i][jidx] * p2s[n-i-1] % MOD; result %= MOD; } } } let denom = power(power(2, MOD-2), n as isize-1); println!("{}", result * denom % MOD); }