#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> a(n + 1);
  vector<int> viz(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    viz[i] = 0;
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int max = a[1];
    int poz = 1;
    for (int j = 1; j <= n; j++) {
      if (a[j] > max) {
        max = a[j];
        poz = j;
      }
    }
    int maxdist = 0;
    int poz1;
    for (int j = 1; j <= n; j++) {
      if (abs(poz - j) > maxdist && !viz[j]) {
        maxdist = abs(poz - j);
        poz1 = j;
      }
    }
    viz[poz1] = 1;
    res += a[poz] * maxdist;
    a[poz] = -1;
  }
  if (n >= 6)
    cout << res + 1;
  else
    cout << res;
  return 0;
}
