#P7482. 不条理狂诗曲

不条理狂诗曲

Description

YSGH has a non-negative integer sequence aa of length nn. Define f(l,r)f(l, r) as the maximum possible sum of some pairwise non-adjacent numbers chosen from the subarray [l,r][l, r] of sequence aa.

YSGH wants to know $\displaystyle \left[ \sum_{l = 1}^{n} \sum_{r = l}^{n} f(l, r) \right] \bmod ({10}^9 + 7)$.

Input Format

The first line contains a positive integer nn, denoting the length of the sequence.

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \ldots , a_n.

Output Format

Only one line containing one integer, denoting the answer.

3
1 2 4
18

Hint

Sample Explanation

f(1,1)=1f(1, 1)=1, f(1,2)=2f(1, 2)=2, f(1,3)=5f(1, 3)=5, f(2,2)=2f(2, 2)=2, f(2,3)=4f(2, 3)=4, f(3,3)=4f(3, 3)=4.

The answer is 1+2+5+2+4+4=181 + 2 + 5 + 2 + 4 + 4 = 18.


Constraints

For 100%100\% of the testdata, 1n1051 \le n \le {10}^5, 0ai1090 \le a_i \le {10}^9.

  • Subtask 1 (10 points): n500n \le 500.
  • Subtask 2 (20 points): n5000n \le 5000.
  • Subtask 3 (20 points): ai{0,1}a_i \in \{ 0, 1 \}.
  • Subtask 4 (20 points): ai{1,x}a_i \in \{ 1, x \}, where xx is an integer greater than 11.
  • Subtask 5 (30 points): No special constraints.

Translated by ChatGPT 5