#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
long long int dfs(vector<P> b, int n, int i, int l, int r) {
  if (i == 0) return b[i].first * abs(l - b[i].second);
  long long int sum1 =
      dfs(b, n, i - 1, l + 1, r) + b[i].first * abs(b[i].second - l);
  long long int sum2 =
      dfs(b, n, i - 1, l, r - 1) + b[i].first * abs(b[i].second - r);
  return max(sum1, sum2);
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<P> b(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
  }
  sort(b.begin(), b.end());
  cout << dfs(b, n, n - 1, 0, n - 1) << endl;
}
