#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<pair<int, int> > v;
int n;
int memo[2000][2000];
long long solve(int *arr, int i, int l, int r) {
  if (i == n) return 0;
  if (memo[i][l] != -1) {
    return memo[i][l];
  }
  int temp = n - 1 - (i - l);
  long long ans1 =
      solve(arr, i + 1, l + 1, temp) + (v[i].first * abs(v[i].second - l));
  long long ans2 =
      solve(arr, i + 1, l, temp - 1) + (v[i].first * abs(v[i].second - temp));
  return memo[i][l] = max(ans1, ans2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  int arr[2005];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    v.push_back({arr[i], i});
  }
  memset(memo, -1, sizeof memo);
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  cout << solve(arr, 0, 0, n - 1);
  return 0;
}
