#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> vis(n, 0);
  vector<int> taken(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<int> newV;
  newV = v;
  sort(newV.begin(), newV.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int val = newV[i];
    int initialIndex = 0;
    for (int j = 0; j < n; j++) {
      if (v[j] == val && taken[j] != 1) {
        initialIndex = j;
        taken[j] = 1;
        break;
      }
    }
    int maxDiff = 0;
    int maxIndex = 0;
    for (int j = 0; j < n; j++) {
      if (vis[j] != 1) {
        if (abs(j - initialIndex) > maxDiff) {
          maxDiff = abs(j - initialIndex);
          maxIndex = j;
        }
      }
    }
    vis[maxIndex] = 1;
    ans = ans + val * (maxDiff);
  }
  cout << ans + 1 << "\n";
}
