#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e3 + 5;
int d[maxm][maxm];
pair<int, int> a[maxm];
int n;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; i + j < n; j++) {
      int k = i + j + 1;
      d[i][j + 1] =
          max(d[i][j + 1], d[i][j] + abs(n - j - a[k].second) * a[k].first);
      d[i + 1][j] =
          max(d[i + 1][j], d[i][j] + abs(i + 1 - a[k].second) * a[k].first);
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, d[i][n - i]);
  }
  cout << ans << endl;
  return 0;
}
