Gachapon

아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

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 00-star, 11-star, \ldots, mm-star items. Assume that the probability of drawing out an ii-star item in a single roll is a_i_j=0ma_j\frac{a\_i}{\sum\_{j=0}^{m} a\_j}. A single draw is a level 00 rolling, and a rolling of level kk consists of exactly b_kb\_k rounds of level (k1)(k{-}1) rollings. The highest level of a rolling is nn.

A level kk rolling is legal if it ensures the following:

  • at least one item with at least kk stars is drawn,
  • for all b_kb\_k level (k1)(k{-}1) rollings it contains, at least one item with at least (k1)(k{-}1) stars is drawn,
  • ...and so on, down to each level 00 rolling (which is a single draw), for which at least one item with at least 00 stars is drawn trivially.

Let p_ip\_i be the expected number of ii-star items drawn out from a legal nn-level rolling, and let qq be the probability that an nn-level rolling is legal. Find the values p_ip\_i and qq. To avoid unpleasant huge numbers and divisions by zero, for all 0im0 \le i \le m, you should only output the value (p_iq)mod998,244,353(p\_i \cdot q) \bmod 998\\,244\\,353.

입력

The first line contains two integers mm and nn: the maximum number of stars and the highest level of a rolling (1nm40001 \le n \le m \le 4000).

The second line contains m+1m + 1 integers a_0,a_1,,a_ma\_0, a\_1, \ldots, a\_m: the frequencies of rolling items with 0,1,,m0, 1, \ldots, m stars (1a_i40001 \le a\_i \le 4000).

The third line contains nn integers b_1,b_2,,b_nb\_1, b\_2, \ldots, b\_n: the number of previous level rollings in a rolling of level 1,2,,n1, 2, \ldots, n (2b_i40002 \le b\_i \le 4000).

출력

Output m+1m+1 lines. The ii-th line should contain a single integer: the value of (p_i1q)mod998,244,353(p\_{i-1} \cdot q) \bmod 998\\,244\\,353.

힌트

In the first example, the answers in rational form are: 89\frac{8}{9}, 11, 11.