#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, A;
  cin >> N;
  vector<pair<long long, int>> Ai(N), Bi(N);
  for (int i = 0; i < N; i++) {
    cin >> A;
    Ai[i] = make_pair(A, i);
  }
  sort(Ai.begin(), Ai.end());
  vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i + 1; j++) {
      A = Ai[N - 1 - i].first;
      int k = Ai[N - 1 - i].second;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + A * abs(N - 1 - (i - j) - k));
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + A * abs(j - k));
    }
  }
  long long ans = 0;
  for (int i = 0; i < N + 1; i++) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << "\n";
}
