#include #define fi first #define se second #define FOR(i,l,r) for (int i = l; i <= r; i++) #define FORD(i,l,r) for (int i = l; i >= r; i--) #define el cout <<"\n" #define int long long #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define MASK(i) ((1LL)<<(i)) #define BIT(x,i) (((x)>>(i))&(1LL)) #define Debug(a,n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl using namespace std; typedef long long ll; typedef vector vi; typedef pair vii; typedef unsigned long long ull; typedef vector> vvi; int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; } const int N=3e6+5; const int base=311; const int mod=1e9+7; const long long INF=1e18+7; const int d4x[4] = {-1, 0, 1, 0} , d4y[4] = {0, 1, 0, -1}; const int d8x[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;}; template bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;}; void add(int &x, int y) { x += y; if (x>=mod) x-=mod;} void sub(int &x, int y) { x -= y; if (x<0) x+=mod;} int mul(int x, int y) {return 1LL * x * y % mod;} int calPw(int x, int y) { int ans = 1; while(y) { if (y&1) ans = 1LL * ans * x % mod; x = 1LL * x * x % mod; y >>= 1; } return ans; } ///KhengmepfromLTVHSFTG int n,a[N],pos[N]; void khengmep() { int L=pos[0],R=pos[0]; ll Ans=0; for(int i=1;ipos[i]&&R>pos[i]){ Ans+=i*(L-pos[i])*(n-R+1); } L=min(L,pos[i]); R=max(R,pos[i]); } cout<>n; for(int i=1;i<=n;i++) { cin>>a[i]; pos[a[i]]=i; } } signed main() { // freopen("main.inp","r",stdin); // freopen("main.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); int t=1; //cin>>t; while(t--) { ip(); khengmep(); } return 0; }