#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  priority_queue<tuple<long long, int, int>> Q;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      Q.push(make_tuple(abs(i - j) * A[i], -i, -j));
    }
  }
  vector<int> I(N, -1);
  vector<int> J(N, -1);
  long long ans = 0;
  while (!Q.empty()) {
    int i = -get<1>(Q.top());
    int j = -get<2>(Q.top());
    if (I[i] == -1 && J[j] == -1) {
      I[i] = j;
      J[j] = i;
      ans += get<0>(Q.top());
    }
    Q.pop();
  }
  cout << ans << endl;
}
