#include <bits/stdc++.h>
using namespace std;
int N;
int a[200001];
long wa = 0;
int m = 0;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= N; i++) {
    m = 1000000;
    for (int j = i; j <= N; j++) {
      if (a[j] < m) {
        m = a[j];
      }
      wa += m;
    }
  }
  cout << wa << endl;
  return 0;
}
