#include <bits/stdc++.h>
using namespace std;
constexpr long long int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }
const int max_n = 2000 + 10;
long long int dp[max_n][max_n];
int N;
int main(void) {
  cin >> N;
  vector<pair<int, int>> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back({a, i});
  }
  sort(A.begin(), A.end(), greater<pair<int, int>>());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i + 1; j++) {
      int a = A[i].first;
      int p = A[i].second;
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (p - j) * a);
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + ((N - (i - j) - 1) - p) * a);
    }
  }
  long long int sum = 0;
  for (int i = 0; i <= N; i++) sum = max(dp[N][i], sum);
  cout << sum << endl;
  return 0;
}
