#include <bits/stdc++.h>
using namespace std;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const long long INF = 1e9 + 7;
void edit() { return; }
long long dp[2005][2005];
vector<pair<long long, int> > a(2005);
int n;
long long fun(int pos, int lf, int rt, long long sum) {
  if (pos == n) return sum;
  long long left, right;
  left = a[pos].first * (abs(lf - a[pos].second));
  right = (a[pos].first) * (abs(rt - a[pos].second));
  dp[lf][rt] = max(dp[lf][rt], max(fun(pos + 1, lf + 1, rt, sum + left),
                                   fun(pos + 1, lf, rt - 1, sum + right)));
  return dp[lf][rt];
}
void solve() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) cin >> a[i].first;
  for (int i = 0; i < n; i++) a[i].second = i;
  sort(a.begin(), a.end(), greater<pair<long long, int> >());
  long long ans = fun(0, 0, n - 1, 0);
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
