#include <bits/stdc++.h>
using namespace std;
long long int dp[1001][1001];
long long int comp(const pair<long long int, long long int> &a,
                   const pair<long long int, long long int> &b) {
  return a > b;
}
long long int find(vector<pair<long long int, long long int>> &v,
                   long long int l, long long int r) {
  if (l > r) return 0;
  long long int n = v.size();
  long long int id = (n - 1) - (r - l);
  long long int &ans = dp[l][r];
  if (ans != -1) return ans;
  ans = max(abs(v[id].second - l) * v[id].first + find(v, l + 1, r),
            abs(v[id].second - r) * v[id].first + find(v, l, r - 1));
  return ans;
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> v(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i].first;
    v[i].second = i;
  }
  memset(dp, -1, sizeof(dp));
  sort(v.begin(), v.end(), comp);
  cout << find(v, 0, n - 1);
}
int main() {
  long long int t = 1;
  long long int f = 1;
  while (f <= t) {
    solve();
    cout << endl;
    f++;
  }
  return 0;
}
