#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vvp = vector<vector<pair<int, int>>>;
template <typename T>
using ve = vector<T>;
template <typename T>
using pq2 = priority_queue<T>;
template <typename T>
using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vl A(N);
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
  };
  pq2<pair<ll, pii>> que;
  for (int i = 0; i < (N); i++)
    for (int j = 0; j < (N); j++) {
      que.push({(ll)(abs(i - j)) * A[i], {i, j}});
    }
  vi F1(N, 2);
  vi F2(N, 2);
  ll ans = 0;
  while (!que.empty()) {
    pair<ll, pii> a = que.top();
    que.pop();
    if (F1[a.second.first] == 2 && F2[a.second.second] == 2) {
      if (!que.empty()) {
        pair<ll, pii> b = que.top();
        if (b.first == a.first && a.second.first == b.second.first) {
          if (F2[b.second.second] == 2) {
            que.pop();
            ans += a.first;
            F1[a.second.first] = 1;
            F2[a.second.second] = -b.second.second;
            F2[b.second.second] = -a.second.second;
            continue;
          }
        }
      }
      ans += a.first;
      F1[a.second.first] = 1;
      F2[a.second.second] = 1;
    } else if (F1[a.second.first] == 2 && F2[a.second.second] <= 0) {
      ans += a.first;
      int aa = F2[a.second.second];
      F2[-aa] = 1;
      F2[a.second.second] = 1;
      F1[a.second.first] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
