#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &s, pair<T, int> a) {
  s << a.first << ' ' << a.second;
  return s;
}
int dp[2005][2005];
int solve(int ind, int l, vector<pair<int, int> > &v) {
  if (ind == v.size()) return 0;
  if (dp[ind][l] != -1) return dp[ind][l];
  return dp[ind][l] = max(
             solve(ind + 1, l + 1, v) + abs(v[ind].second - l) * v[ind].first,
             solve(ind + 1, l, v) +
                 abs(v[ind].second - (int)v.size() + 1 + ind - l) *
                     v[ind].first);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  for (int qq = 1; qq <= T; qq++) {
    int n;
    memset(dp, -1, sizeof dp);
    cin >> n;
    vector<pair<int, int> > v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i].first;
      v[i].second = i;
    }
    sort(v.begin(), v.end(), greater<pair<int, int> >());
    cout << solve(0, 0, v) << endl;
  }
  return 0;
}
