#include <bits/stdc++.h>
using namespace std;
class AtB {
 public:
  vector<pair<int, int>> a;
  void solve(istream& in, ostream& out) {
    int n;
    in >> n;
    for (int i = 0; i < n; i++) {
      int val;
      in >> val;
      a.push_back(make_pair(i, val));
    }
    sort(a.begin(), a.end());
    out << calc(0, 0, n - 1) << endl;
  }
  long calc(int i, int from, int to) {
    if (from > to) {
      return 0;
    }
    int index;
    do {
      index = a[i++].first;
    } while (index < from || index > to);
    long sum = a[i - 1].second * (index - from + 1L) * (to - index + 1);
    return sum + calc(i, from, index - 1) + calc(i, index + 1, to);
  }
};
int main() {
  std::ios::sync_with_stdio(false);
  AtB solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
