#P5606. 小 K 与毕业旅行

小 K 与毕业旅行

Description

There are nn attractions in the graduation trip plan. Everyone will visit these attractions in some order, and each attraction will be visited exactly once.

Each attraction has a coordinate aia_i. Taking a ride from the attraction with coordinate aa to the attraction with coordinate bb will cause discomfort of a×ba \times b. After getting off the vehicle each time, the discomfort is reset to 00 (that is, discomfort does not accumulate). If the discomfort of any ride exceeds a certain constant ww, someone will get sick.

Xiao K wants to know how many visiting orders of all attractions make sure that no one gets sick throughout the whole trip. Output the answer modulo 998244353998244353.

Input Format

The first line contains a positive integer nn and a non-negative integer ww.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n.

Output Format

Output one line containing one integer, the answer.

3 3
1 2 3
2
6 5
1 1 4 5 1 4
144
16 20
9 9 3 2 4 4 8 5 3 -1 -9 -1 -9 -8 -1 0
802901549

Hint

Sample Explanation

For sample 11, there are two valid orders: 2132-1-3 and 3123-1-2.

Constraints

This problem has 1010 subtasks. You must pass all test points within a subtask to get the score for that subtask.

For all data, 0w,ai1090 \le w, |a_i| \le 10^9, 1n500001 \le n \le 50000.

# nn aa Score
1 n10n \le 10 No special restrictions 55
2 n20n \le 20
3 n2000n \le 2000 ai{1,w}a_i \in \{ 1,w \}
4 n2000n\le 2000 There are only three distinct aia_i, and ai0a_i \ge 0
5 n200n\le 200 ai0a_i\ge 0 1010
6 n2000n\le 2000 ai0a_i\ge 0 1515
7 n50000n\le 50000 ai0a_i \ge 0 2020
8 n200n\le 200 No special restrictions 1515
9 n2000n\le 2000 1010
10 n50000n\le 50000

Translated by ChatGPT 5