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 ≤ y1, x2 ≤ y2, ..., xr ≤ 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

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

Output

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

Examples

Input

1
42


Output

42


Input

3
1 2 2


Output

13


Input

5
1 2 3 4 5


Output

719
import java.io.*;
import java.util.*;

public class C implements Runnable{
	public static void main (String[] args) {new Thread(null, new C(), "_cf", 1 << 28).start();}

	int MOD = (int)1e9 + 7;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int max = (int)1e6 + (int)1e2;
		BIT bit = new BIT(max);
		int[] dp = new int[max];
		int n = fs.nextInt();
		for(int i = 0; i < n; i++) {
			int x = fs.nextInt();
			int sum = bit.sum(x);
			sum = mult(sum, x);
			sum = add(sum, x);
			bit.update(x, -dp[x]);
			dp[x] = sum; bit.update(x, sum);
		}
		int res = 0;
		for(int i = 0; i < max; i++) res = add(res, dp[i]);
		out.println(res);

		out.close();
	}

	int add(int a, int b) {
		a %= MOD; b %= MOD;
		long c = a;
		c += b;
		while(c < 0) c += MOD;
		c %= MOD;
		return (int)c;
	}
	
	int mult(int a, int b) {
		a %= MOD;
		b %= MOD;
		long c = a;
		c *= b;
		c %= MOD;
		return (int)c;
	}

	class BIT {
		
		int[] bit;
		int n;
		
		public BIT(int a) {
			n = a + 1;
			bit = new int[n];
		}
		
		//Remember that when querying a sum to query the 1-based index of the value.
		
		void update (int index, int val) {
			while(index < n) {
				bit[index] = add(bit[index], val);
				index += (index & (-index));
			}
		}
		
		int sum (int index) {
			int sum = 0;
			while(index > 0) {
				sum = add(sum, bit[index]);
				index -= (index & (-index));
			}
			return sum;
		}
	}

	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}