const DIVISOR: usize = 998244353; //TODO fn main() { let mut nq = String::new(); std::io::stdin().read_line(&mut nq).ok(); let nq: Vec = nq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nq[0]; 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 dp: Vec> = vec![vec![1; n+1]; 2]; let mut result: Vec = vec![1; n+1]; for i in 1..=n { for j in i..=n { dp[i%2][j] = dp[(i+1)%2][j-1] * (a[j-1] - 1); dp[i%2][j] %= DIVISOR; if j > i { dp[i%2][j] += dp[i%2][j-1]; dp[i%2][j] %= DIVISOR; } } result[i] = dp[i%2][n]; } let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); b.trim().split_whitespace().map(|s| s.parse().unwrap()) .for_each(|i: usize| { println!("{}", result[n-i]); }); }