Eraser

Given a sequence, add the products of every triple of entries at distinct positions with three different values, modulo 1,000,000,007.

Medium6CombinatoricsMathArrayNo attempts yetTime limit1sMemory limit256 MB

Problem

Seunghyun is worried that someone will ruin his erasers, so he decided to make his own.

Seunghyun picks a sequence of natural numbers a1,a2,,ana_1, a_2, \dots, a_n. He then chooses three elements aia_i, aja_j, aka_k at three different positions of the sequence and builds a rectangular eraser whose width, depth and height are those three values. He calls it the ijki-j-k eraser. Seunghyun likes erasers that are tall and thin, so ai<aj<aka_i < a_j < a_k must hold.

Look at the picture above. Let the sequence be a1=3a_1 = 3, a2=1a_2 = 1, a3=1a_3 = 1, a4=2a_4 = 2. The 1231-2-3 eraser cannot be made, because 3<1<13 < 1 < 1 is false. The 2412-4-1 eraser can be made, because 1<2<31 < 2 < 3 is true. The only erasers that can be made from this sequence are the 2412-4-1 eraser and the 3413-4-1 eraser.

Seunghyun wants to know the total volume of every eraser he can make. The volume of an eraser is the product of its width, depth and height. He needs that number to design the warehouse where the erasers will be stacked, so help him compute it.

Input

The first line contains the length nn of the sequence. (1n100,0001 \le n \le 100{,}000)

The second line contains a1,a2,,ana_1, a_2, \dots, a_n in order, separated by spaces. (1ai100,0001 \le a_i \le 100{,}000)

Output

Print the sum of the volumes of every eraser that can be made. Seunghyun wants to check that the program runs correctly first, so print that sum modulo 1,000,000,0071{,}000{,}000{,}007 (109+710^9 + 7).

Hint

Take the sequence a1=3a_1 = 3, a2=1a_2 = 1, a3=1a_3 = 1, a4=2a_4 = 2. The only erasers that can be made are the 2412-4-1 eraser and the 3413-4-1 eraser, so the total volume is a2a4a1+a3a4a1=1×2×3+1×2×3=12a_2 a_4 a_1 + a_3 a_4 a_1 = 1 \times 2 \times 3 + 1 \times 2 \times 3 = 12.