#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &i : A) cin >> i;
  vector<pair<int, int>> v(N);
  for (int i = 0; i < (N); ++i) v[i] = pair<int, int>(A[i], i);
  sort(v.begin(), v.end(), greater<pair<int, int>>());
  vector<vector<int>> dp(N + 1, vector<int>(N + 1));
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (N); ++j) {
      if (i < j) continue;
      int x = j, y = i - j;
      int a = v[i].first, b = v[i].second;
      chmax(dp[x + 1][y], dp[x][y] + a * (b - x));
      chmax(dp[x][y + 1], dp[x][y] + a * (N - 1 - y - b));
    }
  }
  int ans = 0;
  for (int i = 0; i < (N + 1); ++i) {
    chmax(ans, dp[i][N - i]);
  }
  cout << ans << endl;
}
