#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
long long dfs(priority_queue<P, vector<P>> pq, long long left,
              long long right) {
  long long res = 0;
  if (pq.empty()) return res;
  P target = pq.top();
  pq.pop();
  res =
      max(dfs(pq, left, right - 1) + target.first * abs(target.second - right),
          dfs(pq, left + 1, right) + target.first * abs(target.second - left));
  return res;
}
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  priority_queue<P, vector<P>> pq;
  for (int i = 0; i < (N); i++) {
    long long tmp;
    cin >> tmp;
    pq.push(P(tmp, i));
  }
  cout << dfs(pq, 0, N - 1) << endl;
  return 0;
}
