#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int power;
  cin >> N;
  vector<pair<int, int>> active(N);
  for (int i = 0; i < N; i++) {
    cin >> power;
    active[i] = make_pair(power, i + 1);
  }
  sort(active.begin(), active.end());
  reverse(active.begin(), active.end());
  vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
  for (int l = 1; l <= N; l++) {
    pair<int, int> a = active[l - 1];
    for (int i = 0; i < l; i++) {
      dp[l - i][i] =
          max(dp[l - i][i], dp[l - i - 1][i] + abs(l - i - a.second) * a.first);
      dp[i][l - i] =
          max(dp[i][l - i],
              dp[i][l - i - 1] + abs(N + 1 - l + i - a.second) * a.first);
    }
  }
  int ans = 0;
  for (int i = 0; i <= N; i++) ans = max(ans, dp[i][N - i]);
  cout << ans;
}
