#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  using namespace std;
  int n;
  cin >> n;
  vector<pair<long long, int> > A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  long long result = 0;
  for (int k = 0; k < 100; k++) {
    random_shuffle(A.begin(), A.end());
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - 1; j++)
        if (A[j].first * abs(j - A[j].second) +
                A[j + 1].first * abs(j + 1 - A[j + 1].second) <
            A[j].first * abs(j + 1 - A[j].second) +
                A[j + 1].first * abs(j - A[j + 1].second))
          swap(A[j], A[j + 1]);
    }
    long long result_tmp = 0;
    for (int i = 0; i < n; i++) result_tmp += A[i].first * abs(i - A[i].second);
    result = max(result, result_tmp);
  }
  cout << result << "\n";
  return 0;
}
