#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int N;
  scanf("%d", &N);
  std::vector<int> a(N), ind(N + 1);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    ind[a[i]] = i;
  }
  set<int> done{-1, N};
  long long ret = 0;
  for (long long i = 1; i <= N; i++) {
    int j = ind[i];
    auto it = done.lower_bound(j);
    int right = *it;
    it--;
    int left = *it;
    ret += i * (j - left) * (right - j);
    done.insert(j);
  }
  cout << ret << endl;
  return 0;
}
