#ACL1E. Shuffle Window

Shuffle Window

Score : 900900 points

Problem Statement

Given are a permutation p1,p2,,pNp_1, p_2, \dots, p_N of (1,2,...,N)(1, 2, ..., N) and an integer KK. Maroon performs the following operation for i=1,2,,NK+1i = 1, 2, \dots, N - K + 1 in this order:

  • Shuffle pi,pi+1,,pi+K1p_i, p_{i + 1}, \dots, p_{i + K - 1} uniformly randomly.

Find the expected value of the inversion number of the sequence after all the operations are performed, and print it modulo 998244353998244353.

More specifically, from the constraints of this problem, it can be proved that the expected value is always a rational number, which can be represented as an irreducible fraction PQ\frac{P}{Q}, and that the integer RR that satisfies $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$ is uniquely determined. Print this RR.

Here, the inversion number of a sequence a1,a2,,aNa_1, a_2, \dots, a_N is defined to be the number of ordered pairs (i,j)(i, j) that satisfy i<j,ai>aji < j, a_i > a_j.

Constraints

  • 2N200,0002 \leq N \leq 200,000
  • 2KN2 \leq K \leq N
  • (p1,p2,,pN)(p_1, p_2, \dots, p_N) is a permutation of (1,2,,N)(1, 2, \dots, N).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

p1p_1 p2p_2 ... pNp_N

Output

Print the expected value modulo 998244353998244353.

3 2
1 2 3
1

The final sequence is one of (1,2,3)(1, 2, 3), (2,1,3)(2, 1, 3), (1,3,2)(1, 3, 2), (2,3,1)(2, 3, 1), each with probability 14\frac{1}{4}. Their inversion numbers are 0,1,1,20, 1, 1, 2 respectively, so the expected value is 11.

10 3
1 8 4 9 2 3 7 10 5 6
164091855