#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
pair<int, int> a[2009];
long long dp[2009][2009];
long long ans(int i, int st, int en) {
  if (st > en) return 0;
  if (dp[st][en] != -1) return dp[st][en];
  long long ans1 =
      ans(i + 1, st, en - 1) + 1LL * a[i].first * (en - a[i].second);
  long long ans2 =
      ans(i + 1, st + 1, en) + 1LL * a[i].first * (a[i].second - st);
  return dp[st][en] = max(ans1, ans2);
}
void solve() {
  int n;
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  memset(dp, -1, sizeof(dp));
  sort(a + 1, a + 1 + n,
       [](pair<int, int> x, pair<int, int> y) { return x.first > y.first; });
  cout << ans(1, 1, n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
