#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int N = 2e5 + 5;
const long long oo = 1e18 + 5;
const long long mod = 1e9 + 7;
long long dp[2005][2005];
void max_self(long long& a, long long b) {
  if (b > a) a = b;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<long long, int>> a;
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a.emplace_back(x, i);
  }
  sort((a).begin(), (a).end());
  reverse((a).begin(), (a).end());
  for (int l = 0; l < n; ++l) {
    for (int r = 0; r < n - l; ++r) {
      int num = a[l + r].first;
      int id = a[l + r].second;
      max_self(dp[l + 1][r], dp[l][r] + num * abs(id - l));
      max_self(dp[l][r + 1], dp[l][r] + num * abs(n - 1 - r - id));
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) max_self(ans, dp[i][n - i]);
  cout << ans;
  return 0;
}
