#include <bits/stdc++.h>
using namespace std;
const int N = 2050;
int n;
long long dp[N][N];
pair<int, int> p[N];
long long solve(int idx, int mi, int mx) {
  if (idx > n) return 0;
  if (dp[idx][mi] != -1) return dp[idx][mi];
  long long op1 =
      solve(idx + 1, mi + 1, mx) + p[idx].first * abs(p[idx].second - mi);
  long long op2 =
      solve(idx + 1, mi, mx - 1) + p[idx].first * abs(p[idx].second - mx);
  return dp[idx][mi] = max(op1, op2);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(p + 1, p + 1 + n);
  for (int i = 1; i <= n / 2; i++) {
    swap(p[i], p[n - i + 1]);
  }
  memset(dp, -1, sizeof dp);
  cout << solve(1, 1, n);
  return 0;
}
