#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  map<long long, long long> idx;
  for (int i = 0; i < n; i++) idx[p[i]] = i + 1;
  long long ret = 0;
  set<long long> st = {0, n + 1};
  for (long long i = 1; i <= n; i++) {
    long long cur = idx[i];
    set<long long>::iterator it = st.upper_bound(cur);
    long long r = (*it), l = (*(--it));
    ret += (cur - l) * (r - cur) * i;
    st.insert(cur);
  }
  cout << ret << endl;
  return 0;
}
