Norma's array price sum

No attempts yetTime limit3sMemory limit64 MB

Problem

Mirko got an array of integers from his grandmother Norma for his birthday. Like any other kid he was hoping for money, but he got an array. Luckily, the town he lives in has a pawn shop that buys arrays.

The price of an array of integers is min×max×L\min \times \max \times L kuna, where min\min is the smallest integer in the array, max\max is the largest one, and LL is the length of the array.

Mirko wants to sell one subarray of consecutive elements of his array. While he was deciding which one, he added up the prices of every subarray he could sell. He asks you for the same value so he can check his arithmetic.

Only the last nine digits of the sum matter, so you do not have to work with huge or real numbers.

Input

The first line contains an integer NN (1N5000001 \le N \le 500\,000).

Each of the next NN lines contains one element of Mirko's array, in order. Every element is an integer between 11 and 10810^8.

Output

Print the last nine digits of the sum of the prices of all subarrays of consecutive elements, as a single integer on one line. In other words, print that sum modulo 10910^9. Do not print leading zeroes.

Hint

In the first example the array holds the integers 11 and 33. The subarrays Mirko can sell are (1)(1), (3)(3), (1,3)(1, 3), and their prices are 11, 99, 66, which add up to 1616.

In the second example the subarrays Mirko can sell are (2)(2), (4)(4), (1)(1), (4)(4), (2,4)(2, 4), (4,1)(4, 1), (1,4)(1, 4), (2,4,1)(2, 4, 1), (4,1,4)(4, 1, 4), (2,4,1,4)(2, 4, 1, 4), and their prices are 44, 1616, 11, 1616, 1616, 88, 88, 1212, 1212, 1616, which add up to 109109.