#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = INT_MAX / 2;
vector<int> as;
vector<pair<int, int>> bs;
vector<vector<long long>> dp;
void solve(const int N) {
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      int v = bs[i + j].first;
      int pos = bs[i + j].second;
      if (i > 0) {
        chmax(dp[i][j], dp[i - 1][j] + v * abs(i - pos));
      }
      if (j > 0) {
        chmax(dp[i][j], dp[i][j - 1] + v * abs(N - j + 1 - pos));
      }
    }
  }
}
int main(void) {
  int N;
  cin >> N;
  as.resize(N + 1);
  bs.resize(N + 1);
  bs[0] = {INF, 0};
  for (int i = 1; i <= N; i++) {
    cin >> as[i];
    bs[i] = {as[i], i};
  }
  sort(bs.begin(), bs.end());
  reverse(bs.begin(), bs.end());
  dp.resize(N + 1, vector<long long>(N + 1, 0));
  solve(N);
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    chmax(ans, dp[i][N - i]);
  }
  cout << ans << endl;
  return 0;
}
