#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int res = 0;
  for (int x = 0; x <= n; x++) {
    long long int s = 0;
    {
      vector<pair<int, int>> q(x);
      for (int i = 0; i < x; i++) {
        q[i] = {a[i], i};
      }
      sort(q.begin(), q.end());
      for (int i = 0; i < x; i++) {
        int from = q[i].second;
        int to = n - x + i;
        s += (long long int)q[i].first * abs(from - to);
      }
    }
    {
      vector<pair<int, int>> q(n - x);
      for (int i = x; i < n; i++) {
        q[i - x] = {a[i], i};
      }
      sort(q.rbegin(), q.rend());
      for (int i = 0; i < n - x; i++) {
        int from = q[i].second;
        int to = i;
        s += (long long int)q[i].first * abs(from - to);
      }
    }
    res = max(res, s);
  }
  cout << res << "\n";
  return 0;
}
