atcoder#ARC120F. [ARC120F] Wine Thief
[ARC120F] Wine Thief
Score : points
Problem Statement
Problems F and F2 have the same Problem Statement but different Constraints and Time Limits.
There are bottles of wine in Takahashi's cellar, arranged in a row from left to right. The tastiness of the -th bottle from the left is . Aoki will choose bottles from these and steal them. However, Takahashi is careful enough to notice the theft if the following condition is satisfied:
- There exist consecutive bottles such that two or more of them are stolen. ( in this problem.)
For every way of stealing bottles without getting noticed by Takahashi, find the total tastiness of the bottles stolen, and then find the sum of all those values. Since the sum can be enormous, print it modulo .
Constraints
- ( represents the smallest integer not less than .)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum modulo .
4 2 2
1 4 2 3
14
The possible ways to steal bottles and the total tastiness for each of them are as follows:
- Steal the -st and -rd bottles from the left, for the total tastiness of .
- Steal the -st and -th bottles from the left, for the total tastiness of .
- Steal the -nd and -th bottles from the left, for the total tastiness of .
Thus, the answer is .
5 3 2
4 7 5 3 8
17
There is no choice but to steal the -st, -rd, and -th bottles.
12 4 2
107367523 266126484 149762920 57456082 857431610 400422663 768881284 494753774 152155823 740238343 871191740 450057094
136993014