#include <bits/stdc++.h>
using namespace std;
long long INFl = 1e+18 + 1;
int INF = 1e+9 + 1;
int main() {
  int N;
  long long A[2001];
  cin >> N;
  srand(time(NULL));
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long ans = 0;
  long long pans = 0;
  vector<pair<long long, long long> > v(N);
  for (int i = 0; i < N; i++) {
    v[i].first = A[i];
    v[i].second = i;
  }
  sort((v).begin(), (v).end());
  for (int i = 0; i < N; i++) {
    pans += (long long)abs(i - v[i].second) * v[i].first;
  }
  ans = max(ans, pans);
  pans = 0;
  sort((v).rbegin(), (v).rend());
  for (int i = 0; i < N; i++) {
    pans += (long long)abs(i - v[i].second) * v[i].first;
  }
  ans = max(ans, pans);
  for (int k = 1; k <= N - 1; k++) {
    vector<pair<long long, long long> > v1, v2;
    long long sum = 0;
    for (int i = 0; i < k; i++) {
      v1.push_back({A[i], i});
    }
    for (int i = k; i < N; i++) {
      v2.push_back({A[i], i});
    }
    sort((v1).begin(), (v1).end());
    sort((v2).rbegin(), (v2).rend());
    for (int i = 0; i < k; i++) {
      sum += (long long)abs(N - k + i - v1[i].second) * v1[i].first;
    }
    for (int i = 0; i < N - k; i++) {
      sum += (long long)abs(i - v2[i].second) * v2[i].first;
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
