#agc037f. [agc037_f]Counting of Subarrays
[agc037_f]Counting of Subarrays
Problem Statement
For a sequence of positive integers and positive integers and , is said to belong to level when one of the following conditions is satisfied:
- The length of is , and its only element is .
- There exist sequences () belonging to level such that the concatenation of in this order coincides with .
Note that the second condition has no effect when , that is, a sequence belongs to level only if the first condition is satisfied.
Given are a sequence of positive integers and a positive integer . Find the number of subsequences () that satisfy the following condition:
- There exists a positive integer such that the sequence belongs to level .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number of subsequences () that satisfy the condition.
Sample Input 1
9 3
2 1 1 1 1 1 1 2 3
Sample Output 1
22
For example, both of the sequences and belong to level , so the sequence belong to level .
Sample Input 2
9 2
2 1 1 1 1 1 1 2 3
Sample Output 2
41
Sample Input 3
15 3
4 3 2 1 1 1 2 3 2 2 1 1 1 2 2
Sample Output 3
31