#include <bits/stdc++.h>
using namespace std;
int main() {
  pair<long long, int> order[2020];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    order[i] = make_pair(temp, i + 1);
  }
  sort(order, order + n);
  reverse(order, order + n);
  long long dp[1000][1000];
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      dp[x][y] = -1;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    long long k = order[i].first;
    int bef = order[i].second;
    for (int x = 0; x <= i; x++) {
      int y = i - x;
      dp[x + 1][y] = max(dp[x + 1][y], dp[x][y] + abs(bef - (x + 1)) * k);
      dp[x][y + 1] = max(dp[x][y + 1], dp[x][y] + abs(bef - (n - y)) * k);
    }
  }
  long long sum = 0;
  for (int i = 0; i <= n; i++) {
    sum = max(sum, dp[i][n - i]);
  }
  cout << sum << endl;
  return 0;
}
