#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 2e9;
const long long large_P = 1e9 + 7;
signed main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < (N); i++) cin >> A.at(i);
  long long res = 0;
  vector<vector<long long>> memo(N, vector<long long>(N));
  for (long long i = 0; i < (N); i++) {
    for (long long j = 0; j < (N); j++) {
      memo.at(i).at(j) = A.at(i) * abs(i - j);
    }
  }
  long long temp_max = -5;
  long long temp_i = 0;
  long long temp_j = 0;
  for (long long k = 0; k < (N); k++) {
    temp_max = -5;
    for (long long i = 0; i < (N); i++) {
      for (long long j = 0; j < (N); j++) {
        if (temp_max < memo.at(i).at(j)) {
          temp_max = memo.at(i).at(j);
          temp_i = i;
          temp_j = j;
        }
      }
    }
    res += temp_max;
    for (long long i = 0; i < (N); i++) {
      memo.at(i).at(temp_j) = -10;
    }
    for (long long j = 0; j < (N); j++) {
      memo.at(temp_i).at(j) = -10;
    }
  }
  cout << res << endl;
}
