#include <bits/stdc++.h>
using namespace std;
class IndexedActivity {
 public:
  int index;
  long long activity;
  IndexedActivity() : index(0), activity(0LL) {}
  IndexedActivity(int index_, long long activity_)
      : index(index_), activity(activity_) {}
  bool operator<(const IndexedActivity& rhs) const {
    return activity < rhs.activity;
  }
  bool operator>(const IndexedActivity& rhg) const {
    return activity > rhg.activity;
  }
};
long long maxFromNew(size_t forwardInfants, size_t backwardInfants,
                     const vector<IndexedActivity>& sortedActivities,
                     vector<vector<int> >& memo) {
  size_t N = sortedActivities.size();
  if (forwardInfants + backwardInfants == N) {
    return 0LL;
  }
  if (memo[forwardInfants][backwardInfants] >= 0) {
    return memo[forwardInfants][backwardInfants];
  }
  const IndexedActivity& nextInfant =
      sortedActivities[forwardInfants + backwardInfants];
  long long letNextGoForward = -1LL;
  int forwardMove = nextInfant.index - forwardInfants;
  if (forwardMove >= 0) {
    letNextGoForward = maxFromNew(forwardInfants + 1, backwardInfants,
                                  sortedActivities, memo) +
                       nextInfant.activity * forwardMove;
  }
  long long letNextGoBackward = -1LL;
  int backwardMove = (N - 1 - backwardInfants) - nextInfant.index;
  if (backwardMove >= 0) {
    letNextGoBackward =
        maxFromNew(forwardInfants, backwardInfants + 1, sortedActivities,
                   memo) +
        nextInfant.activity * ((N - 1 - backwardInfants) - nextInfant.index);
  }
  long long ret = max(letNextGoForward, letNextGoBackward);
  memo[forwardInfants][backwardInfants] = ret;
  return ret;
}
int main() {
  int N;
  cin >> N;
  vector<long long> A(N, 0LL);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<IndexedActivity> activities(A.size(), IndexedActivity());
  vector<vector<int> > memo(A.size(), vector<int>(A.size(), -1));
  for (size_t i = 0; i < A.size(); ++i) {
    activities[i] = IndexedActivity(i, A[i]);
  }
  sort(activities.begin(), activities.end(), greater<IndexedActivity>());
  long long ans = maxFromNew(0, 0, activities, memo);
  cout << ans << endl;
  return 0;
}
