import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve()= var n = scan() q = scan() a = @[0] & newseqwith(n,scan()) b = newseqwith(q,scan()) md = 998244353 dp = newseqwith(2,newseqwith(n+1,0)) dp[0][0]=1 for i in 1..n: var now = i.mod(2) prev = (i+1).mod(2) for j in 0..n: if j >= 1: # i個目の箱から 1以外を引く 1を引く dp[now][j] = dp[prev][j]*(a[i]-1) + dp[prev][j-1] else: dp[now][j] = dp[prev][j]*(a[i]-1) dp[now][j].mod=md for q in b: echo dp[n.mod(2)][q] solve()