3582.Sereja and Subsequences

Time Limit: 1s Memory Limit: 256MB

Sereja has a sequence that consists of n positive integers, a1,a2,...,an.

First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not exceed it.

A sequence of positive integers x=x1,x2,...,xr doesn't exceed a sequence of positive integers y=y1,y2,...,yr, if the following inequation holds: x1 \le y1,x2 \le y2,...,xr \le yr.

Now Sereja wonders, how many sequences are written on the lines piece of paper. Help Sereja, find the required quantity modulo 1000000007 (109+7).

Input Format(From the terminal/stdin)

The first line contains integer n (1 \le n \le 105). The second line contains n integers a1,a2,...,an (1 \le ai \le 106).

Output Format(To the terminal/stdout)

In the single line print the answer to the problem modulo 1000000007 (109+7).

Sample Input 1

Copy
1
42
 \n
  \n

Sample Output 1

Copy
42
  \n

Sample Input 2

Copy
3
1 2 2
 \n
 · · \n

Sample Output 2

Copy
13
  \n

Sample Input 3

Copy
5
1 2 3 4 5
 \n
 · · · · \n

Sample Output 3

Copy
719
   \n

Submit

请先 登录

© 2025 FAQs