#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint a(n);
  REP(i,n) cin>>a[i];
  ll mx = 0;
  REP(i,n) {
    vector<pair<ll,ll>> b(i);
    REP(j,i) b[j] = make_pair(a[j], j);
    vector<pair<ll,ll>> c(n-i);
    REP(j,n-i) c[j] = make_pair(a[j+i], j+i);
    sort(ALL(b));
    sort(ALL(c),greater<pair<ll,ll>>());
    c.insert(end(c),ALL(b));
    ll score = 0;
    REP(j,n) {
      auto [x,y] = c[j];
      score += x * abs(j-y);
    }
    mx = max(mx, score);
  }
  cout<<mx<<endl;
  return 0;
}
