#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1e9;
const int MOD = 1000000007;
int main() {
  int 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; i++) {
    vector<P> front(i + 1), back(n - i - 1);
    ll res = 0;
    for (int j = 0; j < i + 1; j++) front[j] = P(a[j], j);
    for (int j = i + 1; j < n; j++) back[j - i - 1] = P(a[j], j);
    sort(front.begin(), front.end());
    sort(back.begin(), back.end(), greater<P>());
    for (int j = 0; j < i + 1; j++) {
      res += front[j].first * abs(front[j].second - (n - i - 1 + j));
    }
    for (int j = 0; j < n - i - 1; j++) {
      res += back[j].first * abs(back[j].second - j);
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
