#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, ans = 0;
  cin >> N;
  vector<long long> A(N), ANS(N);
  for (long long i = 0; i < N; ++i) cin >> A[i];
  vector<int> used_place(N, 0);
  vector<int> used_elm(N, 0);
  while (accumulate(used_elm.begin(), used_elm.end(), 0) < N) {
    vector<long long> unused_place;
    vector<long long> unused_elm;
    for (long long i = 0; i < N; ++i) {
      if (used_elm[i] == 0) unused_elm.push_back(i);
    }
    for (long long i = 0; i < N; ++i) {
      if (used_place[i] == 0) unused_place.push_back(i);
    }
    long long max = 0, place, elm;
    for (long long i = 0; i < unused_place.size(); ++i) {
      for (long long j = 0; j < unused_elm.size(); ++j) {
        if (max < A[unused_elm[j]] * abs(unused_place[i] - unused_elm[j])) {
          max = A[unused_elm[j]] * abs(unused_place[i] - unused_elm[j]);
          place = unused_place[i];
          elm = unused_elm[j];
        }
      }
    }
    used_elm[elm] = 1;
    used_place[place] = 1;
    ans += max;
  }
  cout << ans << endl;
}
