#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[2000];
signed main() {
  long long i, j;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (i = 0; i < n + 1; i++) {
    vector<pair<long long, long long> > ls;
    vector<pair<long long, long long> > rs;
    for (j = 0; j < i; j++) {
      ls.push_back(pair<long long, long long>(a[j], j));
    }
    for (j = i; j < n; j++) {
      rs.push_back(pair<long long, long long>(a[j], j));
    }
    sort(ls.begin(), ls.end(), greater<pair<long long, long long> >());
    sort(rs.begin(), rs.end(), greater<pair<long long, long long> >());
    long long happy = 0;
    for (j = 0; j < i; j++) {
      long long dx = (n - 1 - j) - ls[j].second;
      happy += ls[j].first * dx;
    }
    for (j = 0; j < rs.size(); j++) {
      long long dx = rs[j].second - j;
      happy += rs[j].first * dx;
    }
    ans = max(ans, happy);
  }
  cout << ans << endl;
  return 0;
}
