#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
struct infant {
  int id;
  long long score;
  bool operator<(const infant &other) const {
    if (score < other.score)
      return true;
    else
      return false;
  }
};
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  vector<infant> infants(N);
  for (int i = 0; i < N; ++i) {
    infants[i].id = i;
    infants[i].score = A[i];
  }
  sort((infants).begin(), (infants).end());
  reverse((infants).begin(), (infants).end());
  vector<vector<long long> > dp(N + 1, vector<long long>(N + 1));
  dp[0][N] = 0;
  for (int i = 0; i < N; ++i) {
    infant c = infants[i];
    for (int l = 0; l < i + 1; ++l) {
      int r = N + l - i;
      cerr << "i = " << i << " l = " << l << " r = " << r
           << " dp[l][r-1] = " << dp[l][r - 1] << endl;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + c.score * abs(l - c.id));
      dp[l][r - 1] = max(dp[l][r - 1], dp[l][r] + c.score * abs(r - 1 - c.id));
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      if (ans < dp[i][j]) ans = dp[i][j];
  cout << ans << endl;
  return 0;
}
