#include <bits/stdc++.h>
using namespace std;
int insert(vector<pair<long long, long long>>& k, int left, int right, int t) {
  if (left == right) {
    return k[t].first * abs(left - k[t].second);
  }
  return max(k[t].first * (abs(k[t].second - left)) +
                 insert(k, left + 1, right, t - 1),
             k[t].first * (abs(k[t].second - right)) +
                 insert(k, left, right - 1, t - 1));
}
int main() {
  long long n;
  vector<pair<long long, long long>> k;
  long long ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long cur;
    cin >> cur;
    k.push_back({cur, i});
  }
  sort(k.begin(), k.end());
  int left = 1, right = n;
  ans = insert(k, left, right, n - 1);
  cout << ans << endl;
  return 0;
}
