#include <bits/stdc++.h>
using namespace std;
const int N = 200011;
stack<int> q;
int l[N], r[N], a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    while (!q.empty() && a[i] < a[q.top()]) q.pop();
    if (q.empty())
      l[i] = 1;
    else
      l[i] = q.top() + 1;
    q.push(i);
  }
  while (!q.empty()) q.pop();
  for (int i = n; i >= 1; i--) {
    while (!q.empty() && a[q.top()] > a[i]) q.pop();
    if (q.empty())
      r[i] = n;
    else
      r[i] = q.top() - 1;
    q.push(i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (long long)(i - l[i] + 1) * (r[i] - i + 1) * a[i];
  }
  printf("%lld\n", ans);
  return 0;
}
