#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
ll calc(const vector<pii> &vec) {
  ll res = 0;
  for (int(i) = 0; (i) < (vec.size()); (i)++) {
    res += vec[i].first * abs(vec[i].second - i);
  }
  return res;
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int(i) = 0; (i) < (N); (i)++) cin >> A[i];
  vector<pii> order(N);
  for (int(i) = 0; (i) < (N); (i)++) {
    order[i] = make_pair((A[i]), (i));
  }
  while (1) {
    int flag = 0;
    for (int i = 0; i < N; i++) {
      ll diff = 0;
      int a = 0, b = 0;
      for (int j = 0; j < N; j++) {
        if (i == j) continue;
        ll nowScore = order[i].first * abs(i - order[i].second) +
                      order[j].first * abs(j - order[j].second);
        ll afterScore = order[i].first * abs(j - order[i].second) +
                        order[j].first * abs(i - order[j].second);
        if (afterScore - nowScore > diff) {
          diff = afterScore - nowScore;
          a = i;
          b = j;
          flag = 1;
        }
      }
      if (!(a == 0 && b == 0)) swap(order[a], order[b]);
    }
    if (!flag) break;
  }
  cout << calc(order) << endl;
  return 0;
}
