#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
vector<pair<int, int> > v;
int memo[2005][2005];
int arr[2005];
long long solve(int i, int l) {
  if (i == n) {
    return 0LL;
  }
  if (memo[i][l] != -1) {
    return memo[i][l];
  }
  long long r = n - (i - l) - 1;
  return memo[i][l] =
             max(1LL * v[i].first * abs(v[i].second - l) + solve(i + 1, l + 1),
                 1LL * v[i].first * abs(v[i].second - r) + solve(i + 1, l));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  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());
  long long ans = solve(0, 0);
  cout << ans << "\n";
  return 0;
}
