#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
int n;
pair<int, int> a[MAXN];
ll dp[MAXN][MAXN];
ll solve(int l, int r) {
  int remain = r - l + 1;
  int start = n - remain + 1;
  if (dp[l][r] != -1) return dp[l][r];
  if (l == r) return dp[l][r] = (ll)a[start].first * abs(r - a[start].second);
  dp[l][r] =
      max((ll)a[start].first * abs(r - a[start].second) + solve(l, r - 1),
          (ll)a[start].first * abs(l - a[start].second) + solve(l + 1, r));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  for (int i = (1); i <= (n / 2); i++) swap(a[i], a[n - i + 1]);
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) dp[i][j] = -1;
  cout << solve(1, n);
  return 0;
}
