#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> arr;
long long dp[2005][2005];
long long n;
long long solve(long long pos, long long left, long long right) {
  if (pos >= n) return 0;
  if (left > right) return -1e10;
  long long &ans = dp[left][right];
  if (ans != -1) return ans;
  long long maxi1 = solve(pos + 1, left + 1, right) +
                    abs(arr[pos].second - left) * arr[pos].first;
  long long maxi2 = solve(pos + 1, left, right - 1) +
                    abs(arr[pos].second - right) * arr[pos].first;
  return max(maxi1, maxi2);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  arr.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i].first;
    arr[i].second = i;
  }
  sort(arr.rbegin(), arr.rend());
  memset(dp, -1, sizeof dp);
  long long ans = solve(0, 0, n - 1);
  cout << ans;
  return 0;
}
