#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 100100100100100;
const int MOD = 1000000007;
long long mod_pow(long long N, long long M) {
  if (M == 0) return 1;
  long long res = mod_pow((N * N) % MOD, M / 2);
  if (M & 1) res = (res * N) % MOD;
  return res %= MOD;
}
long long dp[2002][2002];
int main() {
  int N;
  cin >> N;
  vector<int> retu(N);
  for (int i = 0; i < N; i++) cin >> retu.at(i);
  vector<pair<long long, long long> > num(N);
  for (int i = 0; i < N; i++) {
    num.at(i).first = retu.at(i);
    num.at(i).second = i;
  }
  sort(num.begin(), num.end());
  reverse(num.begin(), num.end());
  for (int i = 0; i < 2002; i++)
    for (int j = 0; j < 2002; j++) dp[i][j] = 0;
  for (int i = 0; i < N; i++) {
    for (int left = 0; left <= i; left++) {
      int right = i - left;
      chmax(dp[i + 1][left + 1], dp[i][left] + (long long)num.at(i).first *
                                                   (num.at(i).second - left));
      chmax(dp[i + 1][left],
            dp[i][left] + (long long)num.at(i).first *
                              ((N - right - 1) - num.at(i).second));
    }
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
}
