#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
  int n;
  vector<std::pair<int, int> > a;
  cin >> n;
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a.push_back(make_pair(i + 1, tmp));
  }
  sort(a.begin(), a.end(),
       [](const std::pair<int, int>& x, const std::pair<int, int>& y) {
         return x.second > y.second;
       });
  int x, y, tmp1, tmp2;
  vector<vector<long long> > dp(n + 1, vector<long long>(n + 1, 0));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      x = j;
      y = i - j;
      tmp1 = tmp2 = 0;
      if (x > 0)
        tmp1 = dp[x - 1][y] + a[i - 1].second * abs(a[i - 1].first - x);
      if (y > 0)
        tmp2 =
            dp[x][y - 1] + a[i - 1].second * abs(a[i - 1].first - (n - y + 1));
      dp[x][y] = max(tmp1, tmp2);
    }
  }
  long long max = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[i][n - i] > max) max = dp[i][n - i];
  }
  cout << max << endl;
  return 0;
}
