atcoder#AGC037F. [AGC037F] Counting of Subarrays

[AGC037F] Counting of Subarrays

Score : 18001800 points

Problem Statement

For a sequence SS of positive integers and positive integers kk and ll, SS is said to belong to level (k,l)(k,l) when one of the following conditions is satisfied:

  • The length of SS is 11, and its only element is kk.
  • There exist sequences T1,T2,...,TmT_1,T_2,...,T_m (mlm \geq l) belonging to level (k1,l)(k-1,l) such that the concatenation of T1,T2,...,TmT_1,T_2,...,T_m in this order coincides with SS.

Note that the second condition has no effect when k=1k=1, that is, a sequence belongs to level (1,l)(1,l) only if the first condition is satisfied.

Given are a sequence of positive integers A1,A2,...,ANA_1,A_2,...,A_N and a positive integer LL. Find the number of subsequences Ai,Ai+1,...,AjA_i,A_{i+1},...,A_j (1ijN1 \leq i \leq j \leq N) that satisfy the following condition:

  • There exists a positive integer KK such that the sequence Ai,Ai+1,...,AjA_i,A_{i+1},...,A_j belongs to level (K,L)(K,L).

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 2LN2 \leq L \leq N
  • 1Ai1091 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN LL

A1A_1 A2A_2 ...... ANA_N

Output

Print the number of subsequences Ai,Ai+1,...,AjA_i,A_{i+1},...,A_j (1ijN1 \leq i \leq j \leq N) that satisfy the condition.

9 3
2 1 1 1 1 1 1 2 3
22

For example, both of the sequences (1,1,1)(1,1,1) and (2)(2) belong to level (2,3)(2,3), so the sequence (2,1,1,1,1,1,1)(2,1,1,1,1,1,1) belong to level (3,3)(3,3).

9 2
2 1 1 1 1 1 1 2 3
41
15 3
4 3 2 1 1 1 2 3 2 2 1 1 1 2 2
31