#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using VPII = vector<PII>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
bool compLines(const PII &a, const PII &b) {
  if (a.first > b.first) return true;
  if (a.first == b.first && a.second > b.second) return true;
  return false;
}
int main() {
  int N;
  cin >> N;
  VPII lines(N + 1);
  int tmp;
  for (int i = (0); i < (N); ++i) {
    cin >> tmp;
    lines[i] = make_pair(tmp, i);
  }
  sort(lines.begin(), lines.end(), compLines);
  VVI dp(N + 1, VI(N + 1, 0));
  for (int n = 0; n < N; n++) {
    int a, p;
    tie(a, p) = lines[n];
    for (int x = 0; x <= n; x++) {
      int y = n - x;
      dp[x + 1][y] = max(dp[x + 1][y], dp[x][y] + a * abs(p - x));
      dp[x][y + 1] = max(dp[x][y + 1], dp[x][y] + a * abs(N - 1 - y - p));
    }
  }
  int ans = 0;
  for (int i = (0); i < (N + 1); ++i) {
    chmax(ans, dp[i][N - i]);
  }
  cout << ans << endl;
}
