#include <bits/stdc++.h>
using namespace std;
long long calc(int N, long long* A, int* idx) {
  long long sum = 0;
  int i;
  for (i = 0; i < N; i++) {
    int d = idx[i] - i;
    if (d < 0) d = -d;
    sum += d * A[idx[i]];
  }
  return sum;
}
int main() {
  int N;
  long long A[2001];
  int idx[2001];
  int i, j;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (i = 0; i < 2001; i++) {
    idx[i] = i;
  }
  int sp;
  long long maxscore = 0;
  for (i = 0; i <= N; i++) {
    for (j = 0; j < N; j++) {
      idx[j] = (j + N - i) % N;
    }
    if (i > 1)
      std::sort(idx, idx + i, [&](int a, int b) { return A[a] > A[b]; });
    if (i < N - 1)
      std::sort(idx + i, idx + N, [&](int a, int b) { return A[a] < A[b]; });
    long long score = calc(N, A, idx);
    if (score > maxscore) {
      maxscore = score;
    }
  }
  cout << maxscore << endl;
}
