#P7509. 撕裂抹消

撕裂抹消

Description

Given an integer sequence a1,a2,,ana_1,a_2,\dots,a_n of length nn, and a rational sequence p1,p2,,pnp_1,p_2,\dots,p_n. At each position there is a random coefficient ci{0,1}c_i \in \{0,1\}, where P(ci=1)=piP(c_i = 1) = p_i and P(ci=0)=1piP(c_i = 0) = 1 - p_i.

Note that when writing the random coefficients as a sequence, it can be divided into several maximal consecutive segments of 00 and 11. “Maximal” means it cannot be extended to either side. Define the value (weight) of a coefficient sequence as follows: if the coefficient sequence has exactly kk maximal consecutive segments of 11, then its value is i=1nciai\sum\limits_{i=1}^n c_i a_i; otherwise, its value is 00.

Find the expected value of this coefficient sequence. Output the answer modulo 998244353998244353.

Input Format

The first line contains two positive integers n,kn,k.

The second line contains nn non-negative integers a1,a2,,ana_1,a_2,\dots,a_n.

The third line contains nn non-negative integers p1,p2,,pnp_1,p_2,\dots,p_n, given modulo 998244353998244353.

Output Format

One line with one non-negative integer, representing the expectation.

5 1
1 2 3 4 5
1 1 1 1 1
15
3 2
1 2 3
499122177 499122177 499122177
499122177

Hint

Sample Explanation

For the first sample, cic_i must be 11, and there must be exactly 11 maximal consecutive segment, so the value must be 1+2+3+4+5=151 + 2 + 3 + 4 + 5 = 15.

For the second sample, the value is non-zero only when c1=1,c2=0,c3=1c_1 = 1,c_2 = 0,c_3 = 1, and the probability of this case is $\frac 12 \times \frac 12 \times \frac 12 = \frac 18$, so the expectation is $\frac{1+3}8 = \frac 12 \equiv 499122177 \pmod {998244353}$.

Constraints

For 30%30\% of the testdata, n20n \le 20.

For 60%60\% of the testdata, n103n \le 10^3.

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, $1 \le k \le \min\left(20,\left\lfloor\frac{n+1}2\right\rfloor\right)$, 0ai,pi<9982443530 \le a_i,p_i < 998244353.

Translated by ChatGPT 5