#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
long long dp[N][N];
inline void upd(long long &first, long long second) {
  first = max(first, second);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort((a).begin(), (a).end());
  reverse((a).begin(), (a).end());
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j < n - i; j++) {
      upd(dp[i + 1][j], dp[i][j] + a[i + j].first * abs(a[i + j].second - i));
      upd(dp[i][j + 1],
          dp[i][j] + a[i + j].first * abs(a[i + j].second - (n - j - 1)));
    }
  }
  long long ans = 0;
  for (long long i = 0; i <= n; i++) upd(ans, dp[i][n - i]);
  cout << ans;
  return 0;
}
