Codeforces Round 346 (Div. 2)
G
Fence Divercity
Codeforces
2300
原题
← F→
翻译中…

Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of $*n*$ consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the $*i*$-th board to the left is $*h*_{*i*}$.

翻译中…

Today Vasily decided to change the design of the fence he had built, by cutting his top connected part so that the fence remained good. The cut part should consist of only the upper parts of the boards, while the adjacent parts must be interconnected (share a non-zero length before cutting out of the fence).

翻译中…

You, as Vasily's curious neighbor, will count the number of possible ways to cut exactly one part as is described above. Two ways to cut a part are called distinct, if for the remaining fences there is such $*i*$, that the height of the $*i*$-th boards vary.

翻译中…

As Vasily's fence can be very high and long, get the remainder after dividing the required number of ways by $1 000 000 007$ $(10^{9} + 7)$.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($1 ≤ *n* ≤ 1 000 000$) — the number of boards in Vasily's fence.

翻译中…

The second line contains $*n*$ space-separated numbers $*h*_{1}, *h*_{2}, ..., *h*_{*n*}$ ($1 ≤ *h*_{*i*} ≤ 10^{9}$), where $*h*_{*i*}$ equals the height of the $*i*$-th board to the left.

翻译中…

Output

翻译中…

Print the remainder after dividing $*r*$ by $1 000 000 007$, where $*r*$ is the number of ways to cut exactly one connected part so that the part consisted of the upper parts of the boards and the remaining fence was good.

翻译中…

Note

翻译中…

From the fence from the first example it is impossible to cut exactly one piece so as the remaining fence was good.

翻译中…

All the possible variants of the resulting fence from the second sample look as follows (the grey shows the cut out part):

翻译中…

image

翻译中…

样例

Input #1
2
1 1
Output #1
0
InputCopy OutputCopy
Input #2
3
3 4 2
Output #2
13
InputCopy OutputCopy
题目信息
题号
659G
时间限制
2 s
内存限制
256 MB
标签
组合数学
动态规划
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。