Time limit: 4s
Memory limit: 1024MB
Input:
Output:
You are given a sequence, , of size with elements from the set . We define the compression function of a sequence as follows:
function compress(s)
stk ← []
for i ← 0 ... len(s) − 1 do
if s[i] = last element of stk then
remove last element from stk
else
stk ← stk + s[i]
end if
end for
return len(stk)
end function
Requirement
We denote by the contiguous subsequence of obtained by removing the prefix and the suffix .
Compute
Since this number can become very large, output the remainder of its division by .
Implementation Details
You must implement the function
std::uint64_t sum_compressed_lengths(std::vector<int> s, int M);
which:
- receives as parameters the sequence and , with the meaning given in the statement;
- returns the required sum modulo .
The judge will call the function exactly once per test.
Constraints and Notes
| # | Score | Constraints |
|---|---|---|
| 1 | 2 | |
| 2 | 3 | |
| 3 | 11 | |
| 4 | 13 | |
| 5 | 22 | |
| 6 | 49 | No additional restrictions. |
Example
input
10 5
2 2 3 3 4 4 1 1 4 3
output
64