#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
long long n, j, a[N], l[N], r[N];
long long ans = 0;
stack<pair<long long, long long> > S;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    while (!S.empty() && S.top().first > a[i]) S.pop();
    if (S.empty())
      l[i] = i - 1;
    else
      l[i] = i - S.top().second - 1;
    S.push(pair<long long, long long>(a[i], i));
  }
  while (!S.empty()) S.pop();
  for (int i = n; i > 0; i--) {
    while (!S.empty() && S.top().first > a[i]) S.pop();
    if (S.empty())
      r[i] = n - i;
    else
      r[i] = S.top().second - i - 1;
    S.push(pair<long long, long long>(a[i], i));
  }
  for (int i = 1; i <= n; i++) ans += (l[i] + r[i] + l[i] * r[i] + 1) * a[i];
  cout << ans;
  return 0;
}
