atcoder#AGC037F. [AGC037F] Counting of Subarrays
[AGC037F] Counting of Subarrays
Score : points
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.
9 3
2 1 1 1 1 1 1 2 3
22
For example, both of the sequences and belong to level , so the sequence belong to level .
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