#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < (long long)n; i++) {
    long long in;
    cin >> in;
    v.emplace_back(pair<long long, long long>(in, i));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long ans = 0;
  for (long long p = 0; p < (long long)n + 1; p++) {
    long long l = 0, r = n - 1;
    long long tmp = 0;
    for (long long j = 0; j < (long long)n; j++) {
      long long a = v[j].first;
      long long po = v[j].second;
      if (p < po) {
        tmp += a * abs(l - po);
        l++;
      } else {
        tmp += a * abs(r - po);
        r--;
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
