#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
const long long mod = 1000000007;
const long long LINF = 1LL << 62;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, -LINF));
  dp[0][n - 1] = 0;
  for (int i = 0; i < n; i++) {
    for (int l = 0; l <= i; l++) {
      int r = n - (i - l) - 1;
      chmax(dp[l + 1][r], dp[l][r] + a[i].first * abs(a[i].second - l));
      chmax(dp[l][r - 1], dp[l][r] + a[i].first * abs(a[i].second - r));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    chmax(ans, dp[i][i - 1]);
    chmax(ans, dp[i - 1][i]);
  }
  cout << ans << endl;
  return 0;
}
