#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  std::cin >> n;
  vector<long long> a(n);
  vector<pair<long long, long long>> b(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    b[i] = {a[i], i};
  }
  sort(b.rbegin(), b.rend());
  map<pair<long long, long long>, long long> memo;
  memo[{0, 0}] = 0;
  function<long long(long long, long long)> rec = [&](long long l,
                                                      long long r) {
    if (memo.count({l, r}) != 0) return memo[{l, r}];
    if (l == 0) {
      return memo[{l, r}] =
                 rec(l, r - 1) +
                 b[l + r - 1].first * abs(b[l + r - 1].second - (n - r));
    }
    if (r == 0) {
      return memo[{l, r}] =
                 rec(l - 1, r) +
                 b[l + r - 1].first * abs(b[l + r - 1].second - l + 1);
    }
    return memo[{l, r}] =
               max(rec(l - 1, r) +
                       b[l + r - 1].first * abs(b[l + r - 1].second - l + 1),
                   rec(l, r - 1) +
                       b[l + r - 1].first * abs(b[l + r - 1].second - (n - r)));
  };
  long long tmp = 0;
  for (int i = 0; i <= n; i++) {
    tmp = max(tmp, rec(i, n - i));
  }
  std::cout << tmp << std::endl;
}
