Canadian Computing Olympiad: 2023 Day 1, Problem 2
Thanks to your help with cropping her picture, Rebecca's scenic photo is now featured on the front cover of the newest issue of her magazine. However, it seems that some of her readers still aren't pleased with the picture. In particular, they seem to believe that the mountain in the picture is fake!
For simplicity, we can describe the picture as a sequence of columns of pixels. In the -th column, the first pixels from the bottom are of mountains. Her readers will only believe that the picture contains a real mountain if it contains a single (possibly wide) peak. That is, if there exists some index with such that .
Luckily, Rebecca can still pay her editors to modify the picture and reprint the magazine. Unfortunately for her though, the editors have a very peculiar pricing scheme for their work. The only way Rebecca can edit the picture is by sending emails to her editors containing the integers such that and . The editors will then add an extra pixel of mountains in the -th column (i.e. increment by ) for a cost of cents. Note that the change in may affect the costs of future edits.
To please her readers, Rebecca would like to edit the picture so that they believe it contains a real mountain. Can you tell her the minimum cost required to do so?
Input Specification
The first line of input contains an integer .
The second line of input contains space-separated integers .
Marks Awarded | Bounds on | Bounds and constraints on |
---|---|---|
marks | for some | |
marks | ||
marks | ||
marks | ||
marks | ||
marks | ||
marks |
Output Specification
Output the remainder of divided by the prime number where is the minimum cost (in cents) that Rebecca would need to incur in order to please her readers.
Sample Input
8
3 2 4 5 4 1 2 1
Output for Sample Input
14
Explanation for Output for Sample Input
Rebecca can send two emails, the first containing the integers and the second containing the integers . The first email costs cents and increases by , while the second email costs cents and increases by .
The values in the final picture will be . Her readers will believe this final picture contains a real mountain.
Comments
bruh this queestion got me tweakin fr