Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
C. Sereja and Subsequences

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputSereja has a sequence that consists of *n* positive integers, *a*_{1}, *a*_{2}, ..., *a*_{n}.

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* = *x*_{1}, *x*_{2}, ..., *x*_{r} doesn't exceed a sequence of positive integers *y* = *y*_{1}, *y*_{2}, ..., *y*_{r}, if the following inequation holds: *x*_{1} ≤ *y*_{1}, *x*_{2} ≤ *y*_{2}, ..., *x*_{r} ≤ *y*_{r}.

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

Input

The first line contains integer *n* (1 ≤ *n* ≤ 10^{5}). The second line contains *n* integers *a*_{1}, *a*_{2}, ..., *a*_{n} (1 ≤ *a*_{i} ≤ 10^{6}).

Output

In the single line print the answer to the problem modulo 1000000007 (10^{9} + 7).

Examples

Input

1

42

Output

42

Input

3

1 2 2

Output

13

Input

5

1 2 3 4 5

Output

719

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/13/2021 14:48:19 (i1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|