#include <bits/stdc++.h>
int A[200001];
int L[200001];
int R[200001];
int stack[200001];
int C[200001];
int sp = 0;
void push(int x) {
  stack[sp] = x;
  sp++;
}
void pop() { sp--; }
int empty() {
  if (sp == 0) return 1;
  return 0;
}
int top() { return stack[sp - 1]; }
int main() {
  int n, i;
  long long int ans = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);
  for (i = 0; i < n; i++) {
    while (sp > 0 && A[top()] > A[i]) {
      pop();
    }
    if (empty())
      L[i] = -1;
    else
      L[i] = top();
    push(i);
  }
  sp = 0;
  for (i = n - 1; i >= 0; i--) {
    while (sp > 0 && A[top()] > A[i]) {
      pop();
    }
    if (!empty())
      R[i] = top();
    else
      R[i] = n;
    push(i);
  }
  for (i = 0; i < n; i++) {
    C[i] = (i - L[i]) * (R[i] - i);
    ans = ans + C[i] * A[i];
  }
  printf("%lld\n", ans);
  return 0;
}
