#include <bits/stdc++.h>
using namespace std;
long long extgcd(long long a) {
  long long b = (long long)(1E9 + 7);
  long long u = 1, v = 0, q;
  while (b > 0) {
    q = a / b;
    a -= q * b;
    swap(a, b);
    u -= q * v;
    swap(u, v);
  }
  u %= (long long)(1E9 + 7);
  while (u < 0) u += (long long)(1E9 + 7);
  return u;
}
long long comb(long long n, long long k) {
  long long t = 1;
  long long j = k;
  for (long long i = n; i >= n - k + 1; i--) {
    t *= i;
    t %= (long long)(1E9 + 7);
    t *= extgcd(j);
    t %= (long long)(1E9 + 7);
    j--;
  }
  while (t < 0) t += (long long)(1E9 + 7);
  return t;
}
int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  vector<pair<long, int>> ss(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ss[i] = {a[i], i};
  }
  sort(ss.begin(), ss.end());
  reverse(ss.begin(), ss.end());
  int fr = 0, bk = 0;
  long long k = 0;
  long long mmmax = 0;
  int t = 0;
  for (int j = 0; j < n; j++) {
    fr = bk = 0;
    k = 0;
    for (int i = 0; i < n; i++) {
      t = ss[(i + j) % n].second;
      if (abs(t - fr) >= abs((n - bk) - t)) {
        k += ss[(i + j) % n].first * abs(t - fr);
        fr++;
      } else {
        k += ss[(i + j) % n].first * abs((n - bk - 1) - t);
        bk++;
      }
    }
    mmmax = max(mmmax, k);
  }
  cout << mmmax << endl;
}
