#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
int main() {
  int N;
  cin >> N;
  vector<Int> A(N);
  for (auto &a : A) cin >> a;
  Int ans = 0;
  for (int n = 1; n <= N - 1; n++) {
    vector<tuple<Int, Int, Int>> B;
    for (int i = 0; i < n; i++) {
      B.emplace_back(A[i], A[i], i);
    }
    for (int i = n; i < N; i++) {
      B.emplace_back(-A[i], A[i], i);
    }
    sort(begin(B), end(B));
    Int a = 0;
    for (int i = 0; i < N; i++) {
      auto [tmp, val, idx] = B[i];
      a += val * abs(idx - i);
    }
    ans = max(ans, a);
  }
  cout << ans << endl;
  return 0;
}
