Sereja has a sequence that consists of *n* positive integers, *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>. 

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*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*r*</sub> doesn't exceed a sequence of positive integers *y* = *y*<sub class="lower-index">1</sub>, *y*<sub class="lower-index">2</sub>, ..., *y*<sub class="lower-index">*r*</sub>, if the following inequation holds: *x*<sub class="lower-index">1</sub> ≤ *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> ≤ *y*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*r*</sub> ≤ *y*<sub class="lower-index">*r*</sub>.

Now Sereja wonders, how many sequences are written on the lines piece of paper. Help Sereja, find the required quantity modulo 1000000007 (10<sup class="upper-index">9</sup> + 7).
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>). The second line contains *n* integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">6</sup>).
import os
import sys
from io import BytesIO, IOBase
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


MOD_NUM = 10**9+7
class SegTree:
    def __init__(self, n):
        sz = 1
        while sz<n:
            sz *= 2

        tree = [0]*(2*sz)

        self.tree = tree
        self.sz = sz
        self.n = n

    def update(self, i, x):
        sz = self.sz
        n = self.n
        tree = self.tree

        node = i + sz
        tree[node] = x
        tree[node] %= MOD_NUM
        node //= 2
        while node>0:
            tree[node] = tree[2*node] + tree[2*node+1]
            tree[node] %= MOD_NUM
            node //= 2

    def query(self, ql, qr, u=1, l=0, r=None):
        sz = self.sz
        n = self.n
        tree = self.tree

        if r is None: r=sz-1
        if ql<=l and r<=qr:
            return tree[u]%MOD_NUM

        if r<ql or qr<l:
            return 0

        mid = (l+r)//2
        left = self.query(ql, qr, 2*u, l, mid)
        right = self.query(ql, qr, 2*u+1, mid+1, r)
        return (left + right)%MOD_NUM
        
n = int(input())
a = list(map(int,input().split()))

tree = SegTree(10**6+10)
for x in a:
    pref_sum = tree.query(1, x)
    tree.update(x, pref_sum*x + x)

ans = tree.query(0, 10**6)
print(ans)



