#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
int n;
pair<int, int> p[2000];
long long dp[2000][2000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    p[i] = make_pair(a, i);
  }
  sort(p, p + n);
  for (int len = 0; len < n; len++) {
    for (int i = 0; i < n - len; i++) {
      chmax(dp[i][len + 1], dp[i][len] + (long long)p[len].first *
                                             abs(p[len].second - (i + len)));
      chmax(dp[i][len + 1],
            dp[i + 1][len] + (long long)p[len].first * abs(p[len].second - i));
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}
