#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < int(n); ++i) cin >> a[i];
  vector<P> b(n);
  for (int i = 0; i < int(n); ++i) b[i] = make_pair(a[i], i);
  sort(b.begin(), b.end(), greater<P>());
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
  for (int i = int(1); i < int(n + 1); ++i)
    for (int j = 0; j < int(i + 1); ++j) {
      int x = j, y = i - j, m = x + y - 1;
      if (x == 0) {
        int d = n - b[m].second - y;
        dp[x][y] = (d < 0 ? -INF : dp[x][y - 1] + b[m].first * d);
        continue;
      }
      if (y == 0) {
        int d = b[m].second - x + 1;
        dp[x][y] = (d < 0 ? -INF : dp[x - 1][y] + b[m].first * d);
        continue;
      }
      int dl = b[m].second - x + 1, dr = n - b[m].second - y;
      dp[x][y] =
          max(dp[x][y - 1] + b[m].first * dr, dp[x - 1][y] + b[m].first * dl);
    }
  ll ans = 0;
  for (int i = 0; i < int(n); ++i) chmax(ans, dp[i][n - i]);
  cout << ans << endl;
  return 0;
}
