CF BUDDY
← Problems·

1172C1 · Nauuo and Pictures (easy version)

2300 · dp, probabilities

Problem: The only difference between easy and hard versions is constraints.

Nauuo is a girl who loves random picture websites.

One day she made a random picture website by herself which includes nn pictures.

When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The ii-th picture has a non-negative weight wiw_i, and the probability of the ii-th picture being displayed is wij=1nwj\frac{w_i}{\sum_{j=1}^nw_j}. That is to say, the probability of a picture to be displayed is proportional to its weight.

However, Nauuo discovered that some pictures she does not like were displayed too often.

To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add 11 to its weight; otherwise, she would subtract 11 from its weight.

Nauuo will visit the website mm times. She wants to know the expected weight of each picture after all the mm visits modulo 998244353998244353. Can you help her?

The expected weight of the ii-th picture can be denoted by qipi\frac {q_i} {p_i} where gcd(pi,qi)=1\gcd(p_i,q_i)=1, you need to print an integer rir_i satisfying 0ri<9982443530\le r_i<998244353 and ripiqi(mod998244353)r_i\cdot p_i\equiv q_i\pmod{998244353}. It can be proved that such rir_i exists and is unique.

Input Format: The first line contains two integers nn and mm (1n501\le n\le 50, 1m501\le m\le 50) — the number of pictures and the number of visits to the website.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (aia_i is either 00 or 11) — if ai=0a_i=0 , Nauuo does not like the ii-th picture; otherwise Nauuo likes the ii-th picture. It is guaranteed that there is at least one picture which Nauuo likes.

The third line contains nn integers w1,w2,,wnw_1,w_2,\ldots,w_n (1wi501\le w_i\le50) — the initial weights of the pictures.

Output Format: The output contains nn integers r1,r2,,rnr_1,r_2,\ldots,r_n — the expected weights modulo 998244353998244353.

Note: In the first example, if the only visit shows the first picture with a probability of 23\frac 2 3, the final weights are (1,1)(1,1); if the only visit shows the second picture with a probability of 13\frac1 3, the final weights are (2,2)(2,2).

So, both expected weights are 231+132=43\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3 .

Because 33274811934(mod998244353)332748119\cdot 3\equiv 4\pmod{998244353}, you need to print 332748119332748119 instead of 43\frac4 3 or 1.33333333331.3333333333.

In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, w1w_1 will be increased by 11.

So, the expected weight is 1+2=31+2=3.

Nauuo is very naughty so she didn't give you any hint of the third example.

Sample Cases

Case 1

Input

2 1
0 1
2 1

Output

332748119
332748119

Case 2

Input

1 2
1
1

Output

3

Case 3

Input

3 3
0 1 1
4 3 5

Output

160955686
185138929
974061117

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback