#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A;
  cin >> N;
  vector<pair<long long, int>> Ai(N), Bi(N);
  for (int i = 0; i < N; i++) {
    cin >> A;
    Ai[i] = make_pair(A, i);
  }
  sort(Ai.begin(), Ai.end());
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int l = 0, r = N - 1;
    for (int j = 0; j < N; j++) {
      int k = Ai[N - 1 - j].second;
      if (abs(k - l) > abs(r - k)) {
        if (j < i) {
          Bi[r] = Ai[N - 1 - j];
          r--;
        } else {
          Bi[l] = Ai[N - 1 - j];
          l++;
        }
      } else {
        if (j < i) {
          Bi[l] = Ai[N - 1 - j];
          l++;
        } else {
          Bi[r] = Ai[N - 1 - j];
          r--;
        }
      }
    }
    long long p = 0;
    for (int j = 0; j < N; j++) {
      p += Bi[j].first * abs(Bi[j].second - j);
    }
    ans = max(ans, p);
  }
  cout << ans << "\n";
}
