#include <bits/stdc++.h>
using namespace std;
long long ST[4 * 200005];
long long v[200005];
void build(int tl, int tr, int p) {
  if (tl == tr) {
    ST[p] = v[tl];
    return;
  }
  int tm = (tl + tr) / 2;
  build(tl, tm, 2 * p);
  build(tm + 1, tr, 2 * p + 1);
  ST[p] = min(ST[2 * p], ST[2 * p + 1]);
}
int query(int tl, int tr, int l, int r, int p) {
  if (tl >= l && tr <= r) return ST[p];
  if (tr < l || tl > r) return 1000000000;
  int tm = (tl + tr) / 2;
  return min(query(tl, tm, l, r, 2 * p), query(tm + 1, tr, l, r, 2 * p + 1));
}
long long dp1[200005];
int main() {
  long long n, a, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    v[i] = a;
  }
  build(1, n, 1);
  for (long long i = 1; i <= n; i++) {
    int low = 1, high = i, mid;
    while (low <= high) {
      mid = (low + high) / 2;
      int qq = query(1, n, mid, i, 1);
      if (qq < v[i])
        low = mid + 1;
      else if (qq >= v[i])
        high = mid - 1;
    }
    dp1[i] += v[i] * (i + 1 - low) + dp1[low - 1];
    ans += dp1[i];
  }
  cout << ans << endl;
  return 0;
}
