#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (v.size()); i++) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
ll dp[2010][2010];
int main() {
  int N;
  cin >> N;
  V<int> A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  V<pii> B(N);
  for (int i = 0; i < (N); i++) B[i] = make_pair(A[i], i);
  sort((B).begin(), (B).end());
  reverse((B).begin(), (B).end());
  for (int l = 0; l <= N; ++l) {
    for (int r = 0; r < N - l; ++r) {
      int use = l + r;
      chmax(dp[l + 1][r], dp[l][r] + abs(l - B[l + r].second) * B[l + r].first);
      chmax(dp[l][r + 1],
            dp[l][r] + abs(N - 1 - r - B[l + r].second) * B[l + r].first);
    }
  }
  ll ans = 0;
  for (int i = 0; i < (N + 1); i++) {
    chmax(ans, dp[i][N - i]);
  }
  cout << ans << endl;
  return 0;
}
