#include <bits/stdc++.h>
using namespace std;
pair<long long, int> A[2000];
long long dp[2001][2001];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A, A + N, greater<pair<long long, int>>());
  long long ans = 0;
  dp[0][0] = 0;
  for (int l = 0; l < N; l++) {
    for (int r = 0; r < N; r++) {
      int i = l + r;
      long long act = A[i].first;
      int loc = A[i].second;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + act * abs(l - loc));
      dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + act * abs((N - 1) - r - loc));
      ans = max(ans, dp[l + 1][r]);
      ans = max(ans, dp[l][r + 1]);
    }
  }
  cout << ans << endl;
  return 0;
}
