CF659G.Fence Divercity

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of nn 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 ii -th board to the left is hih_{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 ii , that the height of the ii -th boards vary.

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

输入格式

The first line contains integer nn ( 1<=n<=10000001<=n<=1000000 ) — the number of boards in Vasily's fence.

The second line contains nn space-separated numbers h1,h2,...,hnh_{1},h_{2},...,h_{n} ( 1<=hi<=1091<=h_{i}<=10^{9} ), where hih_{i} equals the height of the ii -th board to the left.

输出格式

Print the remainder after dividing rr by 10000000071000000007 , where rr 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.

输入输出样例

  • 输入#1

    2
    1 1
    

    输出#1

    0
    
  • 输入#2

    3
    3 4 2
    

    输出#2

    13
    

说明/提示

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):

首页