#include <bits/stdc++.h>
using namespace std;
int dp[2005][2005];
bool present(int dp[][2005], int l, int r) { return dp[l][r] != -1; }
int maxHappiness(vector<pair<int, int>> &v, int n, int cur, int l, int r,
                 int dp[][2005]) {
  if (l > r) return v[cur].first;
  if (present(dp, l, r)) return dp[l][r];
  int put_in_left = v[cur].first * abs(v[cur].second - l) +
                    maxHappiness(v, n, cur + 1, l + 1, r, dp);
  int put_in_right = v[cur].first * abs(v[cur].second - r) +
                     maxHappiness(v, n, cur + 1, l, r - 1, dp);
  dp[l][r] = max(put_in_left, put_in_right);
  return dp[l][r];
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  int ip;
  for (int i = 0; i < n; i++) {
    cin >> ip;
    v.push_back({ip, i});
  }
  sort(v.begin(), v.end(), greater<pair<int, int>>());
  memset(dp, -1, sizeof(dp));
  cout << maxHappiness(v, n, 0, 0, n - 1, dp);
  return 0;
}
