#include #include #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; if(N==1) if(A[0]==1) exit(1); vector P(N); rep(i,N) P[A[i]] = i; vector L = P; vector R = P; rep(i,N-1) L[i+1] = min(L[i],L[i+1]); rep(i,N-1) R[i+1] = max(R[i],R[i+1]); ll ans = 0; rep(i,N){ ans += 1ll * (L[i]+1) * (N-R[i]); } cout << ans << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;