#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int first(vector<int>& a, bool side) {
  if (side) {
    for (int i = a.size() - 1; i >= 0; i--) {
      if (a[i] == -1) {
        return i;
      }
    }
  } else {
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == -1) {
        return i;
      }
    }
  }
  return -1;
}
int loc(int* out, vector<pair<int, int>>& a, vector<int>* fin, int i) {
  int ind1 = first((*fin), false);
  int ind2 = first((*fin), true);
  int dist1 = abs(a[i].second - ind1);
  int dist2 = abs(a[i].second - ind2);
  if (dist1 > dist2) {
    (*fin)[ind1] = a[i].first;
    *out += dist1 * a[i].first;
    return dist1;
  } else if (dist2 > dist1) {
    (*fin)[ind2] = a[i].first;
    *out += dist2 * a[i].first;
    return dist2;
  } else {
    if (i == a.size() - 1) {
      return dist1;
    }
    int temp;
    vector<int> t2(fin->size());
    if (loc(&temp, a, &t2, i + 1) == ind1) {
      (*fin)[ind2] = a[i].first;
      *out += dist2 * a[i].first;
      return dist2;
    } else {
      (*fin)[ind1] = a[i].first;
      *out += dist1 * a[i].first;
      return dist1;
    }
  }
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  int out = 0;
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  vector<int> fin(n, -1);
  for (int i = 0; i < n; i++) {
    loc(&out, a, &fin, i);
  }
  cout << (out + 2) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
