#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<long long, long long> > a(N);
  for (int i = 0; i < N; i++) {
    long long b;
    cin >> b;
    a[i] = pair<long long, long long>(b, i);
  }
  sort(a.begin(), a.end());
  long long dp[N][N];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) dp[i][j] = 0;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      int k = i - j;
      if (j == 0)
        dp[j][k] = dp[j][k - 1] + abs(N - k - a[N - i].second) * a[N - i].first;
      else if (k == 0)
        dp[j][k] = dp[j - 1][k] + abs(j - 1 - a[N - i].second) * a[N - i].first;
      else {
        long long m1 =
            dp[j][k - 1] + abs(N - k - a[N - i].second) * a[N - i].first;
        long long m2 =
            dp[j - 1][k] + abs(j - 1 - a[N - i].second) * a[N - i].first;
        dp[j][k] = max(m1, m2);
      }
    }
  }
  for (int i = 0; i <= N; i++) ans = max(ans, dp[i][N - i]);
  cout << ans << endl;
}
