#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
T sum(vector<T> &VEC) {
  return accumulate(VEC.begin(), VEC.end(), 0.0);
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using td3 = tuple<double, double, double>;
using ti4 = tuple<int, int, int, int>;
using tl4 = tuple<ll, ll, ll, ll>;
using td4 = tuple<double, double, double, double>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvd = vector<vd>;
using vvs = vector<vs>;
using vvb = vector<vb>;
using v3i = vector<vvi>;
using v3l = vector<vvl>;
using v3d = vector<vvd>;
using v3s = vector<vvs>;
using v3b = vector<vvb>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using si = set<int>;
using sl = set<ll>;
using ss = set<string>;
using spii = set<pii>;
using spll = set<pll>;
using spdd = set<pdd>;
void check(ll i, ll j, vl &A, vl &y) {
  ll pre = A[i] * abs(i - y[i]) + A[j] * abs(j - y[j]);
  ll post = A[i] * abs(i - y[j]) + A[j] * abs(j - y[i]);
  if (pre < post) swap(y[i], y[j]);
}
ll hap(vl &A, vl &y) {
  ll res = 0;
  for (int i = 0; i < (int)(A.size()); i++) res += A[i] * abs((ll)i - (ll)y[i]);
  return res;
}
int main() {
  ll N;
  cin >> N;
  vl A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  vl y(N);
  for (int i = 0; i < (int)(N); i++) y[i] = i;
  for (int i = 0; i < (int)(N - 1); i++) {
    for (int j = (int)(i + 1); j < (int)(N); j++) {
      check(i, j, A, y);
    }
  }
  for (int i = 0; i < (int)(N - 1); i++) {
    for (int j = (int)(i + 1); j < (int)(N); j++) {
      check(i, j, A, y);
    }
  }
  cout << hap(A, y) << "\n";
}
