#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[i] = {x, i};
  }
  sort(a.begin(), a.end());
  vector<vector<long long> > d(n, vector<long long>(n, 0));
  d[0][n - 1] = 0;
  for (int len = n - 1; len > 0; --len)
    for (int i = 0; i + len < n; ++i) {
      int j = i + len;
      d[i][j - 1] =
          max(d[i][j - 1],
              d[i][j] + long long(abs(a[len].second - j)) * a[len].first);
      d[i + 1][j] =
          max(d[i + 1][j],
              d[i][j] + long long(abs(a[len].second - i)) * a[len].first);
    }
  long long ans = 0;
  for (int i = 0; i < n; ++i)
    ans = max(ans, d[i][i] + long long(abs(a[0].second - i)) * a[0].first);
  cout << ans;
  return 0;
}
