#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
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;
}
const int INF = (long long)1e9;
const long long INFLL = (long long)1e18 + 1;
const long long MOD = (long long)1e9 + 7;
const double PI = acos(-1.0);
long long dp[2020][2020];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  vector<long long> A(N);
  vector<pair<long long, long long>> v;
  for (int i = 0; i < int(N); ++i) {
    cin >> A[i];
    v.emplace_back(A[i], i);
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < int(N + 1); ++i)
    for (int j = 0; j < int(N + 1); ++j) dp[i][j] = -INFLL;
  dp[0][0] = 0;
  for (int i = 0; i < int(N); ++i) {
    for (int l = 0; l < int(N); ++l) {
      if (i < l) continue;
      int a = v[i].first;
      int idx = v[i].second;
      int r = i - l;
      chmax(dp[i + 1][l + 1], dp[i][l] + a * abs(idx - l));
      chmax(dp[i + 1][l], dp[i][l] + a * abs(idx - (N - r - 1)));
    }
  }
  long long ans = -INFLL;
  for (int i = 0; i < int(N + 1); ++i) chmax(ans, dp[N][i]);
  cout << ans << endl;
}
