#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n;
  cin >> n;
  vector<P> a(n);
  for (ll i = 0; i < (n); ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  vector<vector<ll>> h(2020, vector<ll>(2020));
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (n); ++j) {
      h[i][j] = a[j].first * max(a[j].second - i, i - a[j].second);
    }
  }
  vector<vector<ll>> dp(2020, vector<ll>(2020));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] + h[i - 1][i - 1];
  }
  for (int j = 1; j <= n; j++) {
    dp[0][j] = dp[0][j - 1] + h[n - j][j - 1];
  }
  int fromU = 0;
  int fromR = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      fromU = dp[i - 1][j] + h[i - 1][i + j - 1];
      fromR = dp[i][j - 1] + h[n - j][i + j - 1];
      dp[i][j] = max(fromU, fromR);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i + j == n) {
        ans = max(ans, dp[i][j]);
      }
    }
  }
  cout << ans << endl;
}
