#include <bits/stdc++.h>


using namespace std;


const int MAXN = 200 * 1000 + 123;






long long n, a[MAXN], b[MAXN];
set<long long> s;
long long ans;

int main() {
	cin >> n;
	s.insert(n + 1);
	s.insert(0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		auto x = s.upper_bound(b[i]);
		ans += (*x - b[i]) * (b[i] - *(--x)) * i;
		s.insert(b[i]);
	}
	cout << ans;
	return 0;
}	