#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
constexpr double EPS = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL << 60;
constexpr long long MOD = 1000000007;
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;
}
int N;
long long dp[2020][2020];
vector<pair<long long, long long> > A;
long long rec(int l, int r) {
  if (dp[l][r] != -1) return dp[l][r];
  if (r - l < 1) return dp[l][r] = 0;
  int t = N - (r - l);
  long long ret = max(rec(l + 1, r) + A[t].first * abs(l - A[t].second),
                      rec(l, r - 1) + A[t].first * abs(r - 1 - A[t].second));
  return dp[l][r] = ret;
}
int main(void) {
  cin >> N;
  A.resize(N);
  for (int i = (0); i < (N); ++i) cin >> A[i].first;
  for (int i = (0); i < (N); ++i) A[i].second = i;
  sort((A).begin(), (A).end());
  reverse((A).begin(), (A).end());
  for (int i = (0); i < (N + 1); ++i)
    for (int j = (0); j < (N + 1); ++j) dp[i][j] = -1;
  long long ans = rec(0, N);
  cout << ans << endl;
  return 0;
}
