#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
const long long MOD = pow(10, 9) + 7;
const long long LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
vector<long long> fac;
void c_fac(int x = pow(10, 6) + 10) {
  fac.resize(x, true);
  for (int i = (int)0; i < (int)x; i++) fac[i] = i ? (fac[i - 1] * i) % MOD : 1;
}
long long inv(long long a, long long m = MOD) {
  long long b = m, x = 1, y = 0;
  while (b != 0) {
    int d = a / b;
    a -= b * d;
    swap(a, b);
    x -= y * d;
    swap(x, y);
  }
  return (x + m) % m;
}
long long nck(long long n, long long k) {
  return fac[n] * inv(fac[k] * fac[n - k] % MOD) % MOD;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct num {
  long long i, a;
  bool operator<(const num &x) const {
    return a < x.a || (a == x.a && i < x.i);
  };
  bool operator>(const num &x) const {
    return a > x.a || (a == x.a && i > x.i);
  };
};
int main() {
  int N;
  cin >> N;
  num A[N];
  for (int i = (int)0; i < (int)N; i++) {
    long long t;
    cin >> t;
    A[i] = {i, t};
  }
  long long result = 0;
  for (int i = (int)0; i < (int)N + 1; i++) {
    num tmp[N];
    for (int j = (int)0; j < (int)N; j++) tmp[j] = A[(j + i) % N];
    sort(tmp, tmp + (N - i), greater<num>());
    sort(tmp + (N - i), tmp + N);
    long long tr = 0;
    for (int j = (int)0; j < (int)N; j++) tr += tmp[j].a * abs(tmp[j].i - j);
    result = max(result, tr);
  }
  cout << result << endl;
  return 0;
}
