#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
  long long int sol = power(a, b / 2, m);
  sol = (sol * sol) % m;
  if (b % 2 == 1) sol = (sol * a) % m;
  return (sol);
}
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else {
    return gcd(b, a % b);
  }
}
long long int a[200001], g[200001];
set<long long int> pos;
void solve() {
  long long int sol = 0;
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    g[a[i]] = i + 1;
  }
  pos.insert(0);
  pos.insert(n + 1);
  for (long long int i = 1; i <= n; i++) {
    pos.insert(g[i]);
    auto it = pos.find(g[i]);
    it--;
    long long int l = *it;
    it++;
    it++;
    long long int r = *it;
    sol += i * (g[i] - l) * (r - g[i]);
  }
  cout << sol;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
