#include <bits/stdc++.h>
int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  int j;
  for (j = 1; j <= N; j++) {
    scanf("%d", &a[j]);
  }
  long long int sum1;
  int min;
  min = 0;
  int l, r, k;
  for (l = 1; l <= N; l++) {
    for (r = l; r <= N; r++) {
      min = a[l];
      for (k = l; k <= r; k++) {
        if (min > a[k]) {
          min = a[k];
        }
      }
      sum1 += min;
    }
  }
  printf("%lld", sum1);
  return 0;
}
