#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 2147483647;
const long long int LINF = 9223372036854775807;
int main() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end(), greater<pair<long long int, long long int> >());
  long long int dp[2020][2020];
  dp[0][0] = 0;
  dp[0][1] = 0;
  for (long long int i = 0; i < n - 1; i++) {
    long long int p = a[i].first, x = a[i].second;
    long long int aki = n - i;
    for (long long int j = 0; j < i + 2; j++) {
      if (j == 0)
        dp[i + 1][j] = dp[i][j] + abs(x - (j + aki - 1)) * p;
      else if (j == i + 1)
        dp[i + 1][j] = dp[i][j - 1] + abs(x - (j - 1)) * p;
      else
        dp[i + 1][j] = max(dp[i][j] + abs(x - (j + aki - 1)) * p,
                           dp[i][j - 1] + abs(x - (j - 1)) * p);
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++)
    ans = max(ans, dp[n - 1][i] + a[n - 1].first * (i - a[n - 1].second));
  cout << ans << endl;
  return 0;
}
