#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  int firstHalf = a.size() / 2;
  int secondHalf = a.size() - firstHalf;
  sort(a.begin(), a.begin() + firstHalf + 1);
  sort(a.begin() + firstHalf + 1, a.end(), greater<pair<int, int> >());
  int _max = 0;
  for (int i = 0; i < n; i++) {
    int pos = 0;
    int cal = 0;
    while (pos < n) {
      cal += a[(i + pos) % n].first * abs(a[(i + pos) % n].second - pos);
      pos = pos + 1;
    }
    _max = max(_max, cal);
  }
  cout << _max;
}
