#include <bits/stdc++.h>
using namespace std;
long long myabs(long long x) { return (x > 0) ? x : -x; }
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long res = 0;
  for (int i = 1; i < n; i++) {
    vector<pair<long long, long long> > leftList;
    vector<pair<long long, long long> > rightList;
    for (int j = 0; j < i; j++) {
      leftList.push_back(pair<long long, long long>(a[j], j));
    }
    for (int j = i; j < n; j++) {
      rightList.push_back(pair<long long, long long>(a[j], j));
    }
    sort(leftList.begin(), leftList.end());
    reverse(leftList.begin(), leftList.end());
    sort(rightList.begin(), rightList.end());
    reverse(rightList.begin(), rightList.end());
    long long resTmp = 0;
    int next = 0;
    for (auto x : rightList) {
      resTmp += myabs(x.second - next) * x.first;
      next++;
    }
    next = n - 1;
    for (auto x : leftList) {
      resTmp += myabs(next - x.second) * x.first;
      next--;
    }
    res = max(res, resTmp);
  }
  cout << res << "\n";
  return 0;
}
