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]; n+1]; for i in 1..=n { for j in i..=n { dp[i][j] = dp[i-1][j-1] * (a[j-1] - 1); dp[i][j] %= DIVISOR; if j > i { dp[i][j] += dp[i][j-1]; dp[i][j] %= DIVISOR; } } } 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!("{}", dp[n-i][n]); }); }