#include <bits/stdc++.h>
using namespace std;
long long fun(vector<pair<long long, long long> > vec, long long id,
              long long l, long long r, vector<vector<long long> > &dp) {
  if (id == -1) {
    return 0;
  }
  if (dp[l][r] != -1) return dp[l][r];
  long long ans1 =
      vec[id].first * abs(vec[id].second - l) + fun(vec, id - 1, l + 1, r, dp);
  long long ans2 =
      vec[id].first * abs(vec[id].second - r) + fun(vec, id - 1, l, r - 1, dp);
  return dp[l][r] = max(ans1, ans2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > ar;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    ar.push_back({a, i});
  }
  sort(ar.begin(), ar.end());
  vector<vector<long long> > dp(n + 1, vector<long long>(n + 1, -1));
  cout << fun(ar, n - 1, 0, n - 1, dp);
  return 0;
}
