#abc248h. [abc248_h]Beautiful Subsequences
[abc248_h]Beautiful Subsequences
Problem Statement
You are given a permutation of , and an integer .
Find the number of pairs of integers that satisfy all of the following conditions:
-
-
$\\mathrm{max}(P_L,\\ldots,P_R) - \\mathrm{min}(P_L,\\ldots,P_R) \\leq R - L + K$
Constraints
- is a permutation of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 1
1 4 2 3
Sample Output 1
9
The following nine pairs satisfy the conditions.
For , we have $\\mathrm{max}(A_1,A_2) -\\mathrm{min}(A_1,A_2) = 4-1 = 3$ and , not satisfying the condition.
Sample Input 2
2 0
2 1
Sample Output 2
3
Sample Input 3
10 3
3 7 10 1 9 5 4 8 6 2
Sample Output 3
37