#P12674. 「LAOI-8」Count
「LAOI-8」Count
Description
Given a sequence of length , you need to divide the sequence into several intervals (possibly just one). Each interval must satisfy the condition that . It is allowed that .
Define the contribution of a valid division as the sum of the products of the elements in each non-empty interval. If an interval contains only one element, the product is simply the value of that element.
Compute the sum of contributions of all valid divisions, modulo .
Input Format
Two lines in total:
- The first line contains a positive integer , representing the length of the sequence.
- The second line contains positive integers, representing the sequence .
Output Format
A single line containing one integer — the sum of contributions of all valid divisions modulo .
4
1 2 2 1
16
6
1 2 2 1 2 2
104
Hint
Explanation
For the first sample with sequence , there are three valid ways to divide it:
- Divide into intervals: , contribution is .
- Divide into intervals: , contribution is .
- Divide into interval: , contribution is .
Total contribution: .
Constraints
Subtasks are used in this problem.
| Subtask | Constraint on | Constraint on | Score |
|---|---|---|---|
For all test cases, it is guaranteed that , .
京公网安备 11011102002149号