#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using P = pair<ll, int>;
int main() {
  int n;
  cin >> n;
  P a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    ll sum = 0;
    vector<P> buf(a, a + n);
    sort(buf.begin(), buf.begin() + i, [](P a, P b) {
      if (a.first != b.first)
        return a.first > b.first;
      else
        return a.second < b.second;
    });
    for (int j = 0; j < i; j++) {
      sum += (ll)abs(n - j - 1 - buf[j].second) * buf[j].first;
    }
    sort(buf.begin() + i, buf.end(), [](P a, P b) {
      if (a.first != b.first)
        return a.first > b.first;
      else
        return a.second > b.second;
    });
    for (int j = i; j < n; j++) {
      sum += (ll)abs(j - i - buf[j].second) * buf[j].first;
    }
    cerr << i << ' ' << sum << '\n';
    ans = max(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}
