#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
long long dp[N][N];
long long n;
vector<pair<long long, long long>> a;
long long solve(long long l, long long r) {
  if (l > r) return 0;
  long long &res = dp[l][r];
  if (res != -1) return res;
  long long id = n - (r - l + 1);
  long long pos = a[id].second;
  long long val = a[id].first;
  res = max(res, solve(l + 1, r) + abs(pos - l) * val);
  res = max(res, solve(l, r - 1) + abs(pos - r) * val);
  return res;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ;
  cin >> n;
  a.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  memset(dp, -1, sizeof(dp));
  cout << solve(0, n - 1);
}
