#P7511. 三到六

三到六

Description

Given integers n,kn, k and an nn-th permutation π\pi', ask how many permutations π\pi satisfy that there are exactly kk positions ii such that 1in1 \le i \le n and πi<ππi\pi_i < \pi_{\pi'_i}. Output the answer modulo 998244353998244353.

Input Format

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

The second line contains nn positive integers, representing π\pi'.

Output Format

Output one line containing one non-negative integer, representing the number of permutations π\pi that satisfy the condition.

5 0
1 2 3 4 5
120
5 1
2 3 4 5 1
5
5 2
2 4 5 1 3
60

Hint

Sample Explanation

For the first sample, πi\pi_i cannot be less than πi\pi_i, so the condition must always be satisfied. Therefore, the answer is 5!=1205! = 120.

For the second sample, there are the following 55 permutations π\pi that satisfy the condition:

  1. 1234512345
  2. 2345123451
  3. 3451234512
  4. 4512345123
  5. 5123451234

For the third sample, no explanation is provided.

Constraints

For 20%20\% of the testdata, n10n \le 10.

For 40%40\% of the testdata, n3×102n \le 3 \times 10^2.

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

For the other 20%20\% of the testdata, it is guaranteed that πi=imodn+1\pi'_i = i \bmod n + 1 (1in1 \le i \le n).

For 100%100\% of the testdata, 1n2×1051 \le n \le 2 \times 10^5, 0kn0 \le k \le n.

Translated by ChatGPT 5