#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
using plpll = pair<long long, pll>;
using plplpll = pair<long long, plpll>;
long long N;
vector<plplpll> P;
long long A[2005];
long long usednum[2005];
long long usedpos[2005];
int main() {
  cin >> N;
  P.resize(N * N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < N; j++) {
      P[i * N + j] =
          make_pair(A[i], make_pair(A[i] * abs(j - i), make_pair(i, j)));
    }
  }
  sort(P.begin(), P.end(), greater<plplpll>());
  long long ans = 0;
  for (long long x = 0; x < P.size(); x++) {
    plplpll a = P[x];
    long long ai = a.first;
    long long p = a.second.first;
    long long i = a.second.second.first;
    long long j = a.second.second.second;
    if (usednum[i] == 0 && usedpos[j] == 0) {
      ans += p;
      usednum[i] = 1;
      usedpos[j] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
