#include <bits/stdc++.h>
using namespace std;
int maxHappiness(vector<pair<int, int>> v, int n, int cur, int l, int r,
                 unordered_map<string, int> &mp) {
  if (cur == n) return 0;
  string mp_key = to_string(cur) + " - " + to_string(l) + " - " + to_string(r);
  if (mp.find(mp_key) != mp.end()) return mp[mp_key];
  int put_in_left = v[cur].first * abs(v[cur].second - l) +
                    maxHappiness(v, n, cur + 1, l + 1, r, mp);
  int put_in_right = v[cur].first * abs(v[cur].second - r) +
                     maxHappiness(v, n, cur + 1, l, r - 1, mp);
  mp[mp_key] = max(put_in_left, put_in_right);
  return mp[mp_key];
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  int ip;
  for (int i = 0; i < n; i++) {
    cin >> ip;
    v.push_back({ip, i});
  }
  sort(v.begin(), v.end(), greater<pair<int, int>>());
  unordered_map<string, int> mp;
  cout << maxHappiness(v, n, 0, 0, n - 1, mp);
  return 0;
}
