Score : 1800 points
For a sequence S of positive integers and positive integers k and l, S is said to belong to level (k,l) when one of the following conditions is satisfied:
Note that the second condition has no effect when k=1, that is, a sequence belongs to level (1,l) only if the first condition is satisfied.
Given are a sequence of positive integers A_1,A_2,...,A_N and a positive integer L. Find the number of subsequences A_i,A_{i+1},...,A_j (1 \leq i \leq j \leq N) that satisfy the following condition:
Input is given from Standard Input in the following format:
N L A_1 A_2 ... A_N
Print the number of subsequences A_i,A_{i+1},...,A_j (1 \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) and (2) belong to level (2,3), so the sequence (2,1,1,1,1,1,1) belong to level (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