P13760 Clock Paradox
Background

(From a Phigros illustration, please contact for removal.)
Description
Given a sequence $a$, consider intervals $[l,r]$ such that every number from $a_l$ to $a_r$ appears exactly once within this interval (i.e., all elements in the subarray are pairwise distinct). Suppose there are $t$ intervals that satisfy this requirement, numbered from $[l_1,r_1]$ to $[l_t,r_t]$.
Compute:
$$\sum_{i=1}^t\sum_{j=l_i}^{r_i}a_j$$
Output the answer modulo $10^9+7$.
Input Format
The first line contains a positive integer $n$, the length of the sequence.
The second line contains $n$ non-negative integers, representing the sequence $a$.
Output Format
Output one non-negative integer, the value of the answer modulo $10^9+7$.
Explanation/Hint
Constraints
| Test Point ID | $n$ | $a_i$ | Special Property |
| :-----------: | :-----------: | :-----------: |:-----------: |
| $1$ | $n\le2×10^5$ | $0\le a_i\le10^9$ | A |
| $2$ | $n\le2×10^5$ | $0\le a_i\le10^9$ | B |
| $3,4$ | $n\le 2×10^5$| $0\le a_i\le1$ | |
| $5,6$ | $n\le500$ | $0\le a_i\le10^9$ | |
| $7\sim10$ | $n\le 5×10^3$ | $0\le a_i\le n$ | |
| $11\sim20$ | $n\le2×10^5$ | $0\le a_i\le10^9$ | |
Special Property A: all $a_i$ are equal.
Special Property B: all $a_i$ are pairwise distinct.
For $100\%$ of the testdata, $1\le n\le2×10^5$ and $0\le a_i\le 10^9$.
Translated by ChatGPT 5