#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
pair<long long, long long> a[N];
long long dp[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1, greater<pair<long long, long long>>());
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i][j] = dp[i - 1][j - 1] + a[i].first * abs(a[i].second - j);
      if (j < i) {
        dp[i][j] = max(
            dp[i - 1][j] + a[i].first * abs(a[i].second - (n - (i - j - 1))),
            dp[i][j]);
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
}
