#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> order;
  for (int i = 0; i < N; i++) order.push_back(i);
  sort(order.begin(), order.end(), [&](int i, int j) { return A[i] > A[j]; });
  static long long dp[2001][2001];
  for (int i = 0; i < N; i++)
    for (int j = 0; i + j < N; j++) {
      int pos = order[i + j];
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + A[pos] * abs(pos - i));
      dp[i][j + 1] =
          max(dp[i][j + 1], dp[i][j] + A[pos] * abs(pos - (N - 1 - j)));
    }
  long long ans = 0;
  for (int i = 0; i <= N; i++) ans = max(ans, dp[i][N - i]);
  cout << ans << endl;
  return 0;
}
