#include <bits/stdc++.h>
using namespace std;
const int64_t M = 2e5 + 5;
int64_t n, a[M], lft[M], rght[M];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int64_t i = 1; i <= n; i++) cin >> a[i];
  memset(lft, -1, sizeof(lft));
  memset(rght, -1, sizeof(rght));
  stack<int64_t> s;
  for (int64_t i = 1; i <= n; i++) {
    while (!s.empty() && a[i] < a[s.top()]) {
      rght[s.top()] = i - 1;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) {
    rght[s.top()] = n;
    s.pop();
  }
  for (int64_t i = n; i >= 1; i--) {
    while (!s.empty() && a[i] < a[s.top()]) {
      lft[s.top()] = i + 1;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) {
    lft[s.top()] = 1;
    s.pop();
  }
  int64_t ans = 0;
  for (int64_t i = 1; i <= n; i++)
    ans += (i - lft[i] + 1) * (rght[i] - i + 1) * a[i];
  cout << ans;
  return 0;
}
