#include <bits/stdc++.h>
using namespace std;
const int dh[8] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dw[8] = {0, 0, 1, -1, 1, -1, 1, -1};
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    int num;
    cin >> num;
    a[num] = i;
  }
  long long ans = 0;
  vector<int> his;
  his.push_back(0);
  his.push_back(n + 1);
  for (int i = 1; i <= n; i++) {
    his.push_back(a[i]);
    sort(his.begin(), his.end());
    vector<int>::iterator it = lower_bound(his.begin(), his.end(), a[i]);
    int h = a[i] - *(it - 1);
    int w = *(it + 1) - a[i];
    ans += h * w * i;
  }
  cout << ans << endl;
  return 0;
}
