#include <bits/stdc++.h>
using namespace std;
using LONG = long long int;
using ULONG = unsigned long long int;
int N;
vector<int> a;
set<int> used;
map<int, int> pos;
ULONG result = 0;
void calculate() {
  for (int num = 1; num <= N; num++) {
    auto prev = used.lower_bound(pos[num]);
    if (prev == used.begin())
      prev = used.end();
    else
      prev--;
    auto next = used.upper_bound(pos[num]);
    int left, right;
    if (prev == used.end()) {
      left = pos[num];
    } else {
      left = pos[num] - *prev - 1;
    }
    if (next == used.end()) {
      right = N - pos[num] - 1;
    } else {
      right = *next - pos[num] - 1;
    }
    if (right < 0) throw runtime_error("bug 1");
    if (left < 0) throw runtime_error("bug 2");
    if (right >= N) throw runtime_error("bug 3");
    if (left >= N) throw runtime_error("bug 4");
    result += (ULONG)num * (right * left + right + left + 1);
    used.insert(pos[num]);
  }
}
int main(void) {
  cin >> N;
  a.resize(N);
  for (unsigned int i = 0; i < N; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  calculate();
  cout << result << endl;
  return 0;
}
