#include <bits/stdc++.h>
using namespace std;
int solve(multimap<int64_t, int, greater<int64_t>> A, int L, int R) {
  if (A.size() == 0) return 0;
  auto biggest = A.begin();
  int64_t next = biggest->first;
  int x = biggest->second;
  auto AA = A;
  AA.erase(AA.begin());
  return max(solve(AA, L + 1, R) + next * (x - L),
             solve(AA, L, R - 1) + next * (R - x));
}
int main() {
  int N;
  cin >> N;
  multimap<int64_t, int, greater<int64_t>> A;
  for (int n = 0; n < N; ++n) {
    int64_t a;
    cin >> a;
    A.emplace(a, n + 1);
  }
  int L = 1, R = N;
  uint64_t ans = solve(A, L, R);
  cout << ans << endl;
  return 0;
}
