#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> t(N);
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  priority_queue<pair<int, pair<int, int>>> Q;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int k = t[i] * abs(i - j);
      Q.push(make_pair(k, make_pair(i, j)));
    }
  }
  long long ans = 0;
  vector<bool> useX(N, false), useY(N, false);
  while (!Q.empty()) {
    pair<int, P> p = Q.top();
    Q.pop();
    if (useX[p.second.first] || useY[p.second.second]) continue;
    if (Q.top().first == p.first) {
      vector<pair<int, P>> temp;
      temp.push_back(p);
      while (!Q.empty() && Q.top().first == p.first) {
        pair<int, P> p2 = Q.top();
        temp.push_back(p2);
        Q.pop();
      }
      vector<int> dt(temp.size());
      for (int i = 0; i < temp.size(); i++) {
        for (int j = 0; j < temp.size(); j++) {
          if (temp[i].second.first == temp[j].second.first ||
              temp[i].second.second == temp[j].second.second) {
            dt[i]++;
            dt[j]++;
          }
        }
      }
      int min = INT_MAX;
      int k = 0;
      for (int i = 0; i < temp.size(); i++) {
        if (min > dt[i]) {
          min = dt[i];
          k = i;
        }
      }
      for (int i = 0; i < temp.size(); i++) {
        if (i != k) {
          Q.push(temp[i]);
        }
      }
      p = temp[k];
    }
    if (useX[p.second.first] || useY[p.second.second]) continue;
    ans += p.first;
    useX[p.second.first] = true;
    useY[p.second.second] = true;
  }
  cout << ans << endl;
  return 0;
}
