#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  vector<pair<long long, long long>> A;
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    A.push_back({tmp, i});
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  long long DP[101][101];
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      DP[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    long long act = A[i].first;
    long long no = A[i].second;
    for (int x = 0; x <= i; x++) {
      int y = i - x;
      if (DP[x + 1][y] < DP[x][y] + abs(no - x) * act) {
        DP[x + 1][y] = DP[x][y] + abs(no - x) * act;
      }
      if (DP[x][y + 1] < DP[x][y] + abs(no - (N - 1 - y)) * act) {
        DP[x][y + 1] = DP[x][y] + abs(no - (N - 1 - y)) * act;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i <= N; i++) {
    if (ans < DP[i][N - i]) {
      ans = DP[i][N - i];
    }
  }
  cout << ans;
  return 0;
}
