#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<long long, int> > A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i].first;
  for (int i = 0; i < (int)(N); i++) A[i].second = i;
  sort(A.begin(), A.end(), greater<pair<long long, int> >());
  long long ans = 0;
  for (int i = 0; i < (int)(N); i++) ans += A[i].first * abs(i - A[i].second);
  int Lfixed = 0, Rfixed = 0;
  for (int i = 0; i < (int)(N); i++) {
    long long sum = 0;
    vector<pair<long long, int> > B(N);
    for (int j = 0; j < (int)(Lfixed); j++) B[j] = A[j];
    for (int j = Lfixed; j < N - Rfixed - 1; j++) B[j] = A[j + 1];
    B[N - Rfixed - 1] = A[Lfixed];
    for (int j = N - Rfixed; j < N; j++) B[j] = A[j];
    for (int j = 0; j < (int)(N); j++) sum += B[j].first * abs(j - B[j].second);
    if (ans < sum) {
      ans = sum;
      for (int j = 0; j < (int)(N); j++) A[j] = B[j];
      Rfixed++;
    } else
      Lfixed++;
  }
  cout << ans << endl;
  return 0;
}
