#include <bits/stdc++.h>
using namespace std;
int a[200005], t[400005], ans, n;
void build(int v, int tl, int tr) {
  if (tl == tr)
    t[v] = a[tl];
  else {
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
  }
}
int sum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 999999999;
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  return min(sum(v * 2, tl, tm, l, min(r, tm)),
             sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  build(1, 1, n);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      ans += sum(1, 1, n, i, j);
    }
  }
  cout << ans;
  return 0;
}
