#include <bits/stdc++.h>
using namespace std;
long long dp[2005][2005];
int main() {
  int n;
  pair<int, int> a[2005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a, a + n,
       [&](pair<int, int> x, pair<int, int> y) { return x.first > y.first; });
  int p;
  for (int i = 0; i < n; i++) {
    for (int j = 0; (p = i + j) < n; j++) {
      dp[i + 1][j] =
          max(dp[i + 1][j],
              dp[i][j] + (long long)a[p].first * abs(a[p].second - (i + 1)));
      dp[i][j + 1] =
          max(dp[i][j + 1], dp[i][j] + (long long)a[p].first *
                                           abs(a[p].second - (6 - (j + 1))));
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
  return 0;
}
