| UDESC Selection Contest 2025-1 |
|---|
| Finished |
After the unforgettable episode with the El Café coffee shop, Max and his brother Min decided to take a well-deserved vacation — this time, away from coffee and closer to the big screen. Their love for cinema, especially the films of Martin Scorsese, led them to create a new tradition: continuous Scorsese marathons.
During their month of rest, the brothers organized $$$N$$$ of the director's films in chronological order, numbering them from $$$1$$$ to $$$N$$$. Each film received a score from film critics; the score of the $$$i$$$-th film is $$$a_i$$$.
Being as competitive and creative as always, Max and Min decided to evaluate the quality of each "continuous marathon" in a curious way:
A continuous marathon is any contiguous subsequence of the original list of films — it can be a single film or all $$$N$$$ films.
Naturally, Max and Min became curious: what is the total sum of the qualities of all possible continuous marathons?
Since this value can be very large, they decided to only care about the result modulo $$$10^9 + 7$$$.
The first line contains an integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$, representing the number of films in the list organized by Max and Min. The second line contains $$$N$$$ integers $$$a_1, a_2, \dots, a_N$$$ ($$$1 \leq a_i \leq 10^9$$$), representing the scores given by film critics to each film.
Print a single integer, which is the remainder of the division of the total sum of the qualities of all possible continuous marathons in Max and Min's list by $$$10^9 + 7$$$.
32 1 3
22
55 9 1 2 3
230
Explanation of example 1: For each contiguous subsequence (marathon), we compute the quality as the product of the maximum and minimum score values among the films in that marathon:
The sum of all qualities is $$$4 + 2 + 3 + 1 + 3 + 9 = 22$$$.
| Name |
|---|


