#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, unsigned long long int> m;
map<pair<int, int>, unsigned long long int>::iterator itr;
unsigned long long int res(pair<int, int> a[], int n, int p, int i, int j) {
  if (i == j) {
    return a[p].first * abs(a[p].second - i);
  }
  itr = m.find({p, i});
  if (itr != m.end()) {
    return itr->second;
  }
  unsigned long long int r =
      max(a[p].first * abs(a[p].second - i) + res(a, n, p + 1, i + 1, j),
          a[p].first * abs(a[p].second - j) + res(a, n, p + 1, i, j - 1));
  m.insert({{p, i}, r});
  return r;
}
int main() {
  int n, i, j, p, x, y;
  long long int k;
  cin >> n;
  pair<int, int> a[n];
  for (i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a, a + n, [](pair<int, int>& p1, pair<int, int>& p2) {
    return p1.first >= p2.first;
  });
  cout << res(a, n, 0, 0, n - 1) << endl;
  return 0;
}
