#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
void print() {}
template <class H, class... T>
void print(H &&h, T &&...t) {
  cout << h << " \n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll A[2010];
  for (ll i = (0); i < (N); i++) cin >> A[i];
  ll ans = 0;
  for (ll i = (0); i < (N + 1); i++) {
    vector<lpair> lv, rv;
    for (ll j = (0); j < (N); j++) {
      if (j < i) {
        lv.push_back({A[j], j});
      } else {
        rv.push_back({A[j], j});
      }
    }
    sort(lv.begin(), lv.end());
    sort(rv.begin(), rv.end(), greater<lpair>());
    ll res = 0;
    ll idx = 0;
    for (auto &e : rv) {
      res += e.first * abs(e.second - idx);
      idx++;
    }
    for (auto &e : lv) {
      res += e.first * abs(e.second - idx);
      idx++;
    }
    ans = max(ans, res);
  }
  print(ans);
}
