#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector< pair<long long, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  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; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + abs(n - i + j - 1 - a[i].second) * a[i].first);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + abs(a[i].second - j) * a[i].first);
    }
  }
  cout << *max_element(dp[n].begin(), dp[n].end()) << '\n';
  return 0;
}
