#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  pair<int, int> a[n];
  pair<long long int, int> temp[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a, a + n);
  reverse(a, a + n);
  int left = 1;
  int right = n;
  long long int res[n + 1][n + 1];
  res[0][0] = 0;
  int temp1, temp2;
  for (int i = 1; i <= n; i++) {
    res[i][0] = res[i - 1][0] + a[i - 1].first * (a[i - 1].second - i);
    res[0][i] = res[i - 1][0] + a[i - 1].first * (n - i + 1 - a[i - 1].second);
    for (int j = 1; j <= i - 1; j++) {
      temp1 = a[i - 1].first * (n - i + j + 1 - a[i - 1].second);
      temp2 = a[i - 1].first * (a[i - 1].second - j);
      res[j][i - j] = max(res[j][i - j - 1] + temp1, res[j - 1][i - j] + temp2);
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ans < res[i][n - i]) ans = res[i][n - i];
  }
  cout << ans << endl;
  return 0;
}
