#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  priority_queue<pair<int, int> > a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.emplace(make_pair(t, i));
  }
  long long ans[n + 1][n + 1];
  long long temp = a.top().first;
  int index = a.top().second;
  a.pop();
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) ans[i][j] = 0;
  ans[1][n] = temp * (index);
  ans[0][n - 1] = temp * (n - 1 - index);
  for (int i = 1; i < n; i++) {
    temp = a.top().first;
    index = a.top().second;
    a.pop();
    ans[0][n - 1 - i] = ans[0][n - i] + temp * abs(n - 1 - i - index);
    ans[i + 1][n] = ans[i][n] + temp * abs(index - i);
    for (int j = 1; j < i; j++) {
      ans[j][n - 1 - i + j] =
          max(ans[j - 1][n - 1 - i + j] + temp * abs(index - j),
              ans[j][n - i + j] * abs(n - 1 - i + j - index));
    }
  }
  long long m = ans[0][0];
  for (int i = 1; i <= n; i++) m = max(m, ans[i][i]);
  cout << m << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
