#include <bits/stdc++.h>
using namespace std;
struct pint {
  int a;
  int i;
};
vector<vector<int> > dp;
int rec(int i, vector<pint>& a, int l, int r) {
  if (i == a.size()) return 0;
  if (dp[i][l] != -1) return dp[i][l];
  int ans = 0;
  ans = a[i].a * abs(l - a[i].i) + rec(i + 1, a, l + 1, r);
  ans = max(ans, a[i].a * abs(r - a[i].i) + rec(i + 1, a, l, r - 1));
  return dp[i][l] = ans;
}
bool com(pint a, pint b) { return a.a > b.a; }
void solve() {
  long long n;
  cin >> n;
  vector<pint> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].a;
    v[i].i = i;
  }
  dp.clear();
  dp.resize(n, vector<int>(n, -1));
  sort(v.begin(), v.end(), com);
  cout << rec(0, v, 0, n - 1);
}
int main() {
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
