#include <bits/stdc++.h>

using namespace std;

const int N = 200010;
const int inf = 2e9;

int tab[21][N];
int a[N];
int n;

int query(int l, int r) {
  if (l < 0 || l >= n || r < 0 || r >= n) {
    return -inf;
  }
  int k = __lg(r - l + 1);
  return min(tab[k][l], tab[k][r - (1 << k) + 1]);
}

int find_left(int rr, int v) {
  int lo = -1, hi = rr + 1;
  while (hi - lo > 1) {
    int mi = (lo + hi) >> 1;
    if (query(mi, rr) < v) {
      lo = mi;
    } else {
      hi = mi;
    }
  }
  return lo + 1;
}

int find_right(int ll, int v) {
  int lo = ll - 1, hi = n;
  while (hi - lo > 1) {
    int mi = (lo + hi) >> 1;
    if (query(ll, mi) < v) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  return hi - 1;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    tab[0][i] = a[i];
  }
  int k = __lg(n);
  for (int t = 0; t < k; t++) {
    int l = 1 << t;
    for (int i = 0; i < n - 2 * l + 1; i++) {
      tab[t + 1][i] = min(tab[t][i], tab[t][i + l]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int l = find_left(i - 1, a[i]);
    int r = find_right(i + 1, a[i]);
    ans += 1ll * a[i] * (i - l + 1) * (r - i + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
