#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#ifdef NJUDGE 
#include "C:/Users/Mateus/Documents/CP/Programas/Templates/kowski.h"
#endif

using namespace __gnu_pbds;
using namespace std; 

using T_ = int;
typedef tree<T_, less<T_>, null_type, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ld, ld> pld;
#define pb push_back
#define ss second
#define ff first

const int N = 2e5 + 10, L = 22;
int n, a[N], l[N], r[N], st[N][L];

void build(){
  for(int i = 0; i < n; i++)
    st[i][0] = a[i];

  for(int k = 1; (1<<k) <= n; k++)
    for(int i = 0; i+(1<<k) <= n; i++)
      st[i][k] = min(st[i][k-1], st[i+(1<<(k-1))][k-1]);
}

int get(int a, int b){
  int k = log2(b-a+1);
  return min(st[a][k], st[b-(1<<k)+1][k]);
}

int main(){
  scanf("%d", &n);

  for(int i = 0; i < n; i++)
    scanf("%d", a+i);

  build();
  ll ans = 0LL;

  for(int i = 0; i < n; i++){
    int lo = i, hi = n-1, mid;
    while(lo <= hi){
      mid = ((lo+hi)>>1) + (hi-lo==1);
      if (get(i, mid) < a[i]) hi = mid-1;
      else lo = mid;
      if (lo == hi){
        r[i] = lo;
        break;
      }
    }

    lo = 0, hi = i;
    while(lo <= hi){
      mid = ((lo+hi)>>1);
      if (get(mid, i) < a[i]) lo = mid+1;
      else hi = mid;
      if (lo == hi){
        l[i] = lo;
        break;
      }
    }
  }

  for(int i = 0; i < n; i++)
    ans += a[i] * 1LL* (r[i]-i+1) * (i-l[i]+1);

  printf("%lld\n", ans);
}