One day, Snuke was given a permutation of length N, a_1, a_2, ..., a_N, from his friend.

Find the following:

<image>

Constraints

* 1 ≦ N ≦ 200,000
* (a_1, a_2, ..., a_N) is a permutation of (1, 2, ..., N).

Input

The input is given from Standard Input in the following format:


N
a_1 a_2 ... a_N


Output

Print the answer.

Note that the answer may not fit into a 32-bit integer.

Examples

Input

3
2 1 3


Output

9


Input

4
1 3 2 4


Output

19


Input

8
5 4 8 1 2 6 7 3


Output

85
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
int main() {
	long long n, i, a[222222], ans = 0,t[222222],k;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		t[a[i]] = i;
	}
	set<long long> p{ -1,n };
	for (i = 1; i <= n; i++) {
		auto r = p.insert(t[i]);
		r.first++;
		k = *r.first - t[i];
		r.first--;
		r.first--;
		k *= t[i] - *r.first;
		ans += k*i;
	}
	cout << ans << endl;
}