#include<bits/stdc++.h>
using namespace std;
long N,b[200001],a,x,i;
int main(){
	cin>>N;
	for(i=1L;i<=N;++i){
		scanf("%d",&a);
		b[a]=i;
	}
	set<long>s;
	s.insert(0L);
	s.insert(N+1);
	for(i=1L;i<=N;++i){
		auto it=s.upper_bound(b[i]);
		x+=i*(*it-b[i])*(b[i]-*--it);
		s.insert(b[i]);
	}
	cout<<x<<endl;
}
