#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long INF = 1001001001;
long long LINF = 1001001001001001001ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > as(n);
  for (int i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    as[i].first = a;
    as[i].second = i;
  }
  sort(as.begin(), as.end());
  reverse(as.begin(), as.end());
  vector<vector<vector<long long> > > dp(
      n + 1, vector<vector<long long> >(n, vector<long long>(n, -INF)));
  dp[0][0][n - 1] = 0;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (i + 1); ++j) {
      long long l = j, r = n - i + j - 1;
      if (l + 1 < n)
        chmax(dp[i + 1][l + 1][r],
              dp[i][l][r] + as[i].first * abs(as[i].second - l));
      if (r - 1 >= 0)
        chmax(dp[i + 1][l][r - 1],
              dp[i][l][r] + as[i].first * abs(as[i].second - r));
    }
  long long ans = 0;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (n); ++j) chmax(ans, dp[n][i][j]);
  cout << ans << endl;
}
