#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000000;
long long dp[2005][2005];
int main() {
  long long n;
  cin >> n;
  pair<long long, long long> p[2005];
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    p[i] = pair<long long, long long>(a, i);
  }
  sort(p, p + n, greater<pair<long long, long long> >());
  for (int j = 1; j <= n; j++) dp[0][j] = -INF;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      dp[i][j] =
          max(dp[i - 1][j] + p[i - 1].first * (p[i - 1].second - (i - 1 - j)),
              dp[i - 1][j - 1] + p[i - 1].first * (n - j - p[i - 1].second));
    }
    dp[i][0] = dp[i - 1][0] + p[i - 1].first * (p[i - 1].second - (i - 1));
  }
  long long ans = 0;
  for (int j = 0; j <= n; j++) ans = max(ans, dp[n][j]);
  cout << ans << endl;
}
