#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int main(void) {
  long long int N;
  cin >> N;
  vector<long long int> a(N + 1, 0);
  long long int pohe;
  for (int i = (int)(1); i < (int)(N + 1); i++) {
    cin >> pohe;
    a[pohe] = i;
  }
  set<long long int> bag;
  long long int sum = 0;
  for (long long int i = 1; i <= N; i++) {
    long long int index = a[i];
    bag.insert(index);
    auto iter_l = bag.find(index);
    auto iter_r = bag.find(index);
    long long int l = 0;
    if (iter_l != bag.begin()) {
      iter_l--;
      l = *iter_l;
    }
    iter_r++;
    long long int r = N + 1;
    if (iter_r != bag.end()) r = *iter_r;
    sum += i * (index - l) * (r - index);
  }
  cout << sum << endl;
}
