#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<pair<int, int>> v;
  for (int i = 0; i < N; i++) v.emplace_back(A[i], i);
  long long ans = 0;
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long dp[N + 1][N + 1];
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++) dp[i][j] = 0;
  for (int i = 0; i < N; i++) {
    for (int l = 0; l <= i; l++) {
      int r = i - l;
      dp[l + 1][r] =
          max(dp[l + 1][r], dp[l][r] + abs(l - v[i].second) * v[i].first);
      dp[l][r + 1] = max(
          dp[l][r + 1], dp[l][r] + abs((N - 1 - r) - v[i].second) * v[i].first);
    }
  }
  for (int l = 0; l <= N; l++) {
    ans = max(ans, dp[l][N - l]);
  }
  cout << ans << endl;
  return 0;
}
