# NORMA2 - Norma

## 题意翻译

# 题目描述 你有一个长度为n的序列，定义这个序列中每个区间的价值是 $Cost(i,j)=Min(A_{i}...A_{j})*Max(A_{i}...A_{j})*(j-i+1)$ 其中，$i$,$j$是区间的两个端点。 现在请你求出给定序列所有区间的价值之和。 # 输入 第1行一个整数N，表示这个序列有N个数。 第2~n+1行每行一个整数，第i+1行的整数代表这个序列的第i个数。 # 输出 一行，一个整数。给定序列所有区间的价值之和。 # 样例输入（与原题的样例不同） 4 2 4 1 4 # 样例输出 109 # 数据范围 对于100%的数据保证n$\leq$ $500000$,所有序列中的数$A_{i}$满足$A_{i}$ $\leq$ $1e8$

## 题目描述

Mirko got an array of integers for his birthday from his grandmother Norma. As any other kid, he was hoping for some money, but got an array. Luckily, in his town there is a pawn shop that buys up arrays. The cost of an array of integers is **min** \* **max** \* **L** kunas, where **min** is the minimal integer in the array, **max** is the maximal and **L** is the array length. Mirko is going to sell a subsequence of consecutive numbers from his array. He calculated the average price of all such subsequences. In order to check his result, he wants you to do the same. He will be pleased with only the last 9 digits of the sum of all prices, so you don’t need to bother with large and real numbers.

## 输入输出格式

### 输入格式

The first line of input contains an integer N (1 Each of the following N lines contains a member of Mirko’s array. The members of the array will be integers from the interval $1, 10  ^{8}$.

### 输出格式

The first and only line of output must contain an integer, the last 9 digits of the required sum from the task. **You don’t need to output** the leading zeroes of that 9-digit integer.

## 输入输出样例

### 输入样例 #1

2\n1\n3 

### 输出样例 #1

16