#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<Pair> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i].first;
    A[i].second = i;
  }
  int64_t ans = 0;
  for (int i = 1; i < N; ++i) {
    priority_queue<Pair> queL;
    priority_queue<Pair> queR;
    for (int j = 0; j < i; ++j) queL.push(A[j]);
    for (int j = i; j < N; ++j) queR.push(A[j]);
    int64_t res = 0;
    int r = N - 1;
    while (!queL.empty()) {
      auto [a, idx] = queL.top();
      queL.pop();
      res += (int64_t)abs(r - idx) * a;
      r--;
    }
    int l = 0;
    while (!queR.empty()) {
      auto [a, idx] = queR.top();
      queR.pop();
      res += (int64_t)abs(idx - l) * a;
      l++;
    }
    ans = max(ans, res);
  }
  cout << ans << '\n';
  return 0;
}
