#include <bits/stdc++.h>
using namespace std;
int N;
long long A[2000];
pair<long long, int> p[2000];
long long dp[2005][2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    p[i] = pair<long long, int>(A[i], i);
  }
  sort(p, p + N, greater<pair<long long, int> >());
  for (int i = 0; i < N; i++) {
    long long a = p[i].first;
    int idx = p[i].second;
    for (int j = 0; j <= i; j++) {
      int l = i - j;
      int r = N - j - 1;
      dp[i][j] = max(dp[i][j], dp[i - 1][j] + abs(idx - l) * a);
      dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + abs(r - idx) * a);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, dp[N - 1][i]);
  }
  cout << ans << endl;
}
