#include <bits/stdc++.h>
using namespace std;
const long long int INF = LONG_LONG_MAX >> 1;
const long long int NINF = LONG_LONG_MIN / 2;
const long long int N = 2005;
long long int dp[N][N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int& x : a) cin >> x;
  vector<pair<long long int, long long int> > list;
  for (long long int i = 0; i < n; i++) list.emplace_back(a[i], i);
  sort((list).rbegin(), (list).rend());
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 0; j < i; j++) {
      long long int l = j;
      long long int r = i - j - 1;
      dp[l + 1][r] =
          max(dp[l + 1][r],
              dp[l][r] + abs(l + 1 - list[i - 1].second) * list[i - 1].first);
      r = j;
      l = i - 1 - j;
      dp[l][r + 1] =
          max(dp[l][r + 1],
              dp[l][r] + abs(n - r - list[i - 1].second) * list[i - 1].first);
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i <= n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
}
