#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    vector<pair<ll, ll>> b(i + 1), c(n - 1 - i);
    for (int j = 0; j <= i; j++) {
      b[j] = {a[j], j};
    }
    for (int j = i + 1; j < n; j++) {
      c[j - i - 1] = {a[j], j};
    }
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    ll t = 0;
    for (int j = 0; j <= i; j++) {
      t += b[j].first * abs(n - 1 - j - b[j].second);
    }
    for (int j = i + 1; j < n; j++) {
      t += c[j - i - 1].first * abs(c[j - i - 1].second - j + i + 1);
    }
    ans = max(ans, t);
  }
  cout << ans << '\n';
  return 0;
}
