#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int>> A(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A[i] = {a, i};
  }
  sort(A.rbegin(), A.rend());
  vector<ll> dp(n + 1, -1);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    auto [a, id] = A[i];
    dp[i + 1] = dp[i] + abs(id - i) * a;
    for (int j = i; j >= 1; j--) {
      dp[j] = max(dp[j - 1] + abs(id - (j - 1)) * a,
                  dp[j] + abs(id - (n - 1 - (i - j))) * a);
    }
    dp[0] = dp[0] + abs(id - (n - 1 - i)) * a;
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
  return 0;
}
