const OFFSET: usize = 2; const MOD: usize = 998244353; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } 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![1usize; n]; for i in (1..n-1).rev() { p2s[i-1] = p2s[i] * 2 % MOD; } let mut dp = vec![vec![0usize; 6]; n+1]; dp[0][OFFSET+1] = 1; let mut result = 0usize; for i in 0..n { for j in -2..=3 { let jidx = OFFSET as isize + j; let jidx = jidx as usize; if a[i].abs() * j.abs() > 2 { dp[i+1][5] += dp[i][jidx]; dp[i+1][5] %= MOD; continue; } let njidx = OFFSET as isize + a[i] * j; let njidx = njidx as usize; dp[i+1][njidx] += dp[i][jidx]; dp[i+1][njidx] %= MOD; if njidx == 0 { result += dp[i][jidx] * p2s[i]; result %= MOD; } } if i == 0 { continue; } for j in -2..=3 { let jidx = OFFSET as isize + j; let jidx = jidx as usize; let njidx = OFFSET as isize + a[i]; let njidx = njidx as usize; dp[i+1][njidx] += dp[i][jidx]; dp[i+1][njidx] %= MOD; if njidx == 0 { result += dp[i][jidx] * p2s[i]; result %= MOD; } } } println!("{}", result * power(power(2, MOD-2), n-1) % MOD); }