#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=2e5+7;
int n,a[N],l[N],r[N],stk[N],top;
long long ans=0;
int main(){
	scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
	top=0;
	rep(i,1,n){
		while(top && a[stk[top]] > a[i])top--;
		l[i]=stk[top]+1;
		stk[++top]=i;
	}
	top=0;
	rep2(i,n,1){
		while(top && a[stk[top]] > a[i])top--;
		if(!top)r[i]=n;
		else r[i]=stk[top]-1;
		stk[++top]=i;
	}
	rep(i,1,n){
		ans+=1ll*(i-l[i]+1)*(r[i]-i+1)*a[i];
	}
	printf("%lld\n",ans);
}