#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
int main() {
  ll n;
  cin >> n;
  vector<ll> coeff(n);
  for (auto&& e : coeff) {
    cin >> e;
  }
  vector<vector<ll>> field(n, vector<ll>(n, 0));
  multiset<tuple<ll, ll, ll>> choise;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      field[i][j] = abs(i - j) * coeff[j];
      choise.insert(make_tuple(field[i][j], i, j));
    }
  }
  vector<vector<bool>> able_flag(n, vector<bool>(n, true));
  while (!choise.empty()) {
    ll point = get<0>(*choise.rbegin());
    ll pos_i = get<1>(*choise.rbegin());
    ll pos_j = get<2>(*choise.rbegin());
    for (int j = 0; j < n; ++j) {
      auto tgt = make_tuple(field[pos_i][j], pos_i, j);
      if (able_flag[pos_i][j]) {
        auto it = choise.find(tgt);
        if (it != choise.end()) {
          choise.erase(it);
        }
        able_flag[pos_i][j] = false;
      }
    }
    for (int i = 0; i < n; ++i) {
      auto tgt = make_tuple(field[i][pos_j], i, pos_j);
      if (able_flag[i][pos_j]) {
        auto it = choise.find(tgt);
        if (it != choise.end()) {
          choise.erase(it);
        }
        able_flag[i][pos_j] = false;
      }
    }
    ans += point;
  }
  cout << ans << endl;
}
