Blind Box Selection
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

You are now in a supermarket and notice that a promotion is being held. The promotional device consists of 2n lights arranged in n rows, with two lights in each row.

Each time, you press the button for every row. For the i-th row:
  • If light A is on, you gain a_i points.
  •  If light B is on, you gain b_i points.
Each row has an associated probability p_i, where:
  • Light A is on with probability p_i.
  • Light B is on with probability 1 - p_i.
For one round of the event, your total score is defined as the product of the points obtained from all rows.

There is also a random button. After pressing it, k rows are chosen at random. In each of those selected rows, the two lights are swapped (that is, if light A is on, you gain b_i points; if light B is on, you gain a_i points).

You want to determine whether pressing this random button can improve your expected points. Therefore, you decide to compute the expected value of your final points after pressing the random button modulo 998244353.

输入描述:

The first line contains two integers n and k (1 \le n \le 2000,0 \le k \le n).

Each of the next n lines contains four integers a_i, b_i, c_i, d_i (0 \le a_i, b_i, c_i < 998244353, 1\le d_i < 998244353, c_i\le d_i), where the probability that light A is on is \frac{c_i}{d_i}.

输出描述:

Output a single integer representing the expected score after pressing the random button, modulo 998244353.

Let the expected value be a rational number \frac{X}{Y}, where X and Y are integers and Y \not\equiv 0 \pmod{998244353}.

You should output: X \cdot Y^{-1} \bmod 998244353, where Y^{-1} denotes the modular multiplicative inverse of Y modulo 998244353.
示例1

输入

复制
2 1
1 2 1 2
2 1 1 2

输出

复制
748683267

说明

For Example 1, after pressing the random button, either the two lights in the first row or the two lights in the second row will be swapped, each with a probability of \frac{1}{2}. In the case where the first row is swapped, the expected score is \frac{1}{4} \times (2 \times 2+2 \times 1+2 \times 1+1 \times 1) = \frac{9}{4}. In the case where the second row is swapped, the expected score is also \frac{9}{4}. Therefore, the total expected score is \frac{9}{4}. When taken modulo 998244353, the output is 748683267.
示例2

输入

复制
4 2
11 4 5 6
5 14 3 4
19 19 5 10
8 10 6 11

输出

复制
84459925
示例3

输入

复制
4 2
10 0 1 2
0 10 1 2
11 4 3 4
3 4 4 11

输出

复制
283592800