#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wt_rev(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define rep(v,e) for(int v=0;v=a?v:a) int b[200000]; main(){ char*rp=mmap(0l,1l<<25,1,2,0,0ll); rd(n); rep(i,n){ rd(a); b[a]=i; } long res=0; long lo=200000; long hi=0; rep(i,n){ long bi=b[i]; chmin(lo,bi); chmax(hi,bi); res+=(lo+1)*(n-hi); } char wbuf[64],*wp=wbuf+sizeof wbuf; wt_rev(res); write(1,wp,wbuf+sizeof wbuf-wp); _exit(0); }