#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using int64 = int_fast64_t;
const int32 INF = 1e9;
const int32 MOD = 1e9 + 7;
const int64 LLINF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int64> a(n);
  for (int64 i = 0; i < (n); ++i) cin >> a[i];
  int64 ans = 0;
  for (int64 i = (1); i < (n); i++) {
    int64 cur = 0;
    vector<pair<int64, int64> > le, ri;
    for (int64 j = 0; j < (n); ++j) {
      if (j < i) {
        le.emplace_back(a[j], j);
      } else {
        ri.emplace_back(a[j], j);
      }
    }
    sort((le).begin(), (le).end());
    sort(ri.rbegin(), ri.rend());
    for (int64 j = 0; j < (n - i); ++j) {
      cur += ri[j].first * abs(ri[j].second - j);
    }
    for (int64 j = 0; j < (i); ++j) {
      cur += le[j].first * abs(n - i + j - le[j].second);
    }
    ans = max(ans, cur);
  }
  cout << (ans) << "\n";
  return 0;
}
