#include <bits/stdc++.h>
using namespace std;
using namespace std;
static const int INF = 1001001001;
static const int MAX = 2000;
long long dp[MAX][MAX];
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  for (int i = 0; i < (n + 1); ++i)
    for (int j = 0; j < (n + 1); ++j) dp[i][j] = -INF;
  dp[0][0] = 0;
  vector<pair<int, int> > p;
  for (int i = 0; i < (n); ++i) p.emplace_back(a[i], i);
  sort(p.rbegin(), p.rend());
  for (int i = 0; i < (n); ++i) {
    int pi = p[i].second;
    for (int l = 0; l < (i + 1); ++l) {
      int r = i - 1;
      dp[i + 1][l + 1] = max(dp[i][l], dp[i][l] + long long(pi - 1) * a[pi]);
      dp[i + 1][l] =
          max(dp[i][l], dp[i][l] + long long((n - r - 1) - pi) * a[pi]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < (n + 1); ++i) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
