#include using namespace std; #define int long long const int N=1e6; int n; int a[N],p[N]; int ans; signed main(){ //freopen("ffa2.in","r",stdin); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; p[a[i]]=i; } int l=p[0],r=p[0]; for(int i=1;i<=n-1;i++){ int x=p[i]; if(xr){ ans+=(x-r)*l*i; r=x; } } cout<