#P10143. Code Block Commemoration Contest Score Prediction

    ID: 12132 Type: Default 1000ms 256MiB

Code Block Commemoration Contest Score Prediction

Code Block Commemoration Contest Score Prediction

In memory of the canceled CodeJam, little \beth organizes a Code Block Commemoration Contest. There are nn problems and the contest lasts for TT seconds. The ii-th problem has a score of aia_i and is predicted by \beth to be solved by little \mho in tit_i seconds.

The problems have two types: result visible and result invisible. For result invisible problems, the evaluation result is revealed only after the contest ends, whereas for result visible problems the result is known immediately upon submission. Little \beth has not decided the type of each problem yet.

Little \mho will solve all the result visible problems first (in increasing order of their indices) and then solve all the result invisible problems (again in increasing order). He spends exactly tit_i seconds on the ii-th problem. Moreover, if the cumulative time spent on the ii-th problem and all previously solved problems does not exceed TT, a submission (which is always accepted) is generated for the ii-th problem.

For a given type assignment for the nn problems (a total of 2n2^n possibilities), let the score be the sum of scores aia_i for all problems that were submitted (i.e. solved before or at time TT). The task is to compute the sum of scores over all 2n2^n possible assignments, modulo 998244353998244353.

inputFormat

The first line contains two integers TT and nn.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n, where aia_i is the score of the ii-th problem.

The third line contains nn integers t1,t2,,tnt_1, t_2, \ldots, t_n, where tit_i is the time (in seconds) required to solve the ii-th problem.

outputFormat

Output one integer: the sum of scores over all 2n2^n type assignments modulo 998244353998244353.

sample

5 1
10
3
20