#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int, int>;
const int NMAX = 8;
const ll MOD = 1000000007;
const int dbase = 80 * 160;
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<P> a(n + 5);
  for (ll i = 0; i < n; ++i) {
    int temp;
    cin >> temp;
    a[i] = make_pair(temp, i);
  }
  sort(a.rbegin(), a.rend());
  int ans = 0;
  vector<vector<int>> d(n + 5, vector<int>(n + 5, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((j + i) >= n) {
        ans = max(d[i][j], ans);
        break;
      }
      d[i + 1][j] =
          max(d[i + 1][j], d[i][j] + (a[i + j].second - i) * (a[i + j].first));
      d[i][j + 1] = max(d[i][j + 1], d[i][j] + (n - 1 - j - a[i + j].second) *
                                                   (a[i + j].first));
    }
  }
  cout << ans;
}
