#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
	ll n; cin >> n;
	ll po[n];
	set<ll> hidari, migi;
	hidari.insert(1);
	migi.insert(n);
	for(ll i = 0; i < n; ++i){
		ll a; cin >> a;
		po[--a] = i;
		hidari.insert(-i);
		migi.insert(i);
	}
	ll ans = 0;
	for(ll i = n - 1; i >= 0; --i){
		ll si = -(*hidari.upper_bound(-po[i]));
		ll na = *migi.upper_bound(po[i]);
		hidari.erase(-po[i]);
		migi.erase(po[i]);
		ans += (i + 1) * (po[i] - si) * (na - po[i]);
	}
	cout << ans << endl;
	return 0;
}