#AGC054C. [AGC054C] Roughly Sorted

[AGC054C] Roughly Sorted

Score : 800800 points

Problem Statement

Snuke received a permutation P=(P1,P2,,PN)P=(P_1,P_2,\cdots,P_N) of (1, 2, ... N)(1,\ 2,\ ...\ N) and an integer KK. He did some number of swaps of two adjacent elements in PP so that the following condition would be satisfied.

  • For each 1iN1 \leq i \leq N, there are at most KK indices jj such that 1j<i1 \leq j< i and Pj>PiP_j>P_i.

Here, he did the minimum number of swaps needed to achieve this condition.

Afterward, he has forgotten the original permutation he received. Given the permutation PP' after the swaps, find the number, modulo 998244353998244353, of permutations that the original permutation PP could be.

Constraints

  • 2N50002 \leq N \leq 5000
  • 1KN11 \leq K \leq N-1
  • 1PiN1 \leq P'_i \leq N
  • PiPjP'_i \neq P'_j (iji \neq j)
  • For each 1iN1 \leq i \leq N, there is at most KK indices jj such that 1j<i1 \leq j< i and Pj>PiP'_j>P'_i.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

P1P'_1 P2P'_2 \cdots PNP'_N

Output

Print the answer.

3 1
3 1 2
2

PP could be one of the following two permutations.

  • P=(3,1,2)P=(3,1,2): The minimum number of swaps needed is 00. After zero swaps, the permutation is equal to PP'.
  • P=(3,2,1)P=(3,2,1): The minimum number of swaps needed is 11: swapping P2P_2 and P3P_3 results in P=(3,1,2)P=(3,1,2), which satisfies the condition and is equal to PP'.
4 3
4 3 2 1
1
5 2
4 2 1 5 3
3