#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto& e : a) cin >> e;
  ll m = 0;
  vector<ll> v(n);
  iota(v.begin(), v.end(), 0);
  for (int i = 0; i <= n; i++) {
    vector<ll> l(v.begin(), v.begin() + i), r(v.begin() + i, v.end());
    sort(l.begin(), l.end(), [&a](int i, int j) { return a[i] < a[j]; });
    sort(r.begin(), r.end(), [&a](int i, int j) { return a[i] > a[j]; });
    auto u = r;
    for (auto e : l) u.push_back(e);
    ll mi = 0;
    for (int i = 0; i < n; i++) mi += a[u[i]] * abs(u[i] - i);
    m = max(m, mi);
  }
  cout << m << endl;
}
