atcoder#AGC038B. [AGC038B] Sorting a Segment

[AGC038B] Sorting a Segment

Score : 700700 points

Problem Statement

Snuke has a permutation (P0,P1,,PN1)(P_0,P_1,\cdots,P_{N-1}) of (0,1,,N1)(0,1,\cdots,N-1).

Now, he will perform the following operation exactly once:

  • Choose KK consecutive elements in PP and sort them in ascending order.

Find the number of permutations that can be produced as PP after the operation.

Constraints

  • 2N2000002 \leq N \leq 200000
  • 2KN2 \leq K \leq N
  • 0PiN10 \leq P_i \leq N-1
  • P0,P1,,PN1P_0,P_1,\cdots,P_{N-1} are all different.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

P0P_0 P1P_1 \cdots PN1P_{N-1}

Output

Print the number of permutations that can be produced as PP after the operation.

5 3
0 2 1 4 3
2

Two permutations can be produced as PP after the operation: (0,1,2,4,3)(0,1,2,4,3) and (0,2,1,3,4)(0,2,1,3,4).

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