#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  int ans = 0;
  for (int l = 0; l < (n + 1); l++) {
    for (int m = 0; m < (n + 1); m++) {
      if (l + m == n) {
        ans = max(ans, dp[l][m]);
        break;
      }
      int activeness = a[l + m].first;
      int position = a[l + m].second;
      dp[l + 1][m] =
          max(dp[l + 1][m], dp[l][m] + activeness * abs(l - position));
      dp[l][m + 1] =
          max(dp[l][m + 1], dp[l][m] + activeness * abs(n - m - 1 - position));
    }
  }
  cout << ans << endl;
  return 0;
}
