According to Wikipedia, "a gacha game is a video game that implements the gacha (toy vending machine) mechanic". Similar to loot boxes, gacha games induce players to spend in-game currency to receive a random virtual item.
One of these gacha games is called Step-up Gacha, which means that the player's chances of rolling a rare item are increased each time they roll. For example, the phenomenal game Genshin Impact ensures that you can always draw out four-star items or characters in any ten consecutive rolls.
It would be helpful if we give an abstraction to these rolling rules. Consider a game with 0-star, 1-star, …, m-star items. Assume that the probability of drawing out an i-star item in a single roll is ∑_j=0ma_ja_i. A single draw is a level 0 rolling, and a rolling of level k consists of exactly b_k rounds of level (k−1) rollings. The highest level of a rolling is n.
A level k rolling is legal if it ensures the following:
Let p_i be the expected number of i-star items drawn out from a legal n-level rolling, and let q be the probability that an n-level rolling is legal. Find the values p_i and q. To avoid unpleasant huge numbers and divisions by zero, for all 0≤i≤m, you should only output the value (p_i⋅q)mod998,244,353.
The first line contains two integers m and n: the maximum number of stars and the highest level of a rolling (1≤n≤m≤4000).
The second line contains m+1 integers a_0,a_1,…,a_m: the frequencies of rolling items with 0,1,…,m stars (1≤a_i≤4000).
The third line contains n integers b_1,b_2,…,b_n: the number of previous level rollings in a rolling of level 1,2,…,n (2≤b_i≤4000).
Output m+1 lines. The i-th line should contain a single integer: the value of (p_i−1⋅q)mod998,244,353.
In the first example, the answers in rational form are: 98, 1, 1.