#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 100000000000000000 int main(){ int N; cin>>N; vector A(N); rep(i,N){ int a; cin>>a; A[a] = i; } long long ans = 0LL; long long r = 0,l = N; rep(i,N){ r = max(r,A[i]+1); l = min(l,A[i]); ans += (l+1) * (N-r+1); } cout<