#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int dp[1 << 11] = {};
  vector<int> a(n), id(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    id[i] = i;
  }
  sort(id.begin(), id.end(), [a](int x, int y) { return a[x] > a[y]; });
  int c = 0;
  for (const auto& i : id) {
    c++;
    for (int k = c; k--;) {
      dp[k + 1] = max(dp[k + 1], dp[k] + abs(i - k) * a[i]);
      dp[k] += abs(n - (c - k) - i) * a[i];
    }
  }
  cout << *max_element(dp, dp + n + 1) << endl;
  return 0;
}
