#include <bits/stdc++.h>
using namespace std;
int N;
typedef struct infant {
  int liveliness;
  int oldplace;
  int newplace;
  int rank;
} Infant;
vector<Infant> vec;
bool comp(Infant a, Infant b) { return (a.liveliness > b.liveliness); }
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    Infant I;
    I.liveliness = k;
    I.oldplace = i;
    vec.push_back(I);
  }
  sort(vec.begin(), vec.end(), comp);
  int dp[N + 1][N + 1];
  bool breaker = false;
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < N + 1; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < N + 1; j++) {
      if (i + j > N) {
        continue;
      } else {
        if (j == 0 && i != 0) {
          dp[i][0] = dp[i - 1][0] +
                     vec[i - 1].liveliness * abs(N - i - vec[i - 1].oldplace);
        } else if (j != 0 && i == 0) {
          dp[0][j] = dp[0][j - 1] +
                     vec[j - 1].liveliness * abs(vec[j - 1].oldplace - j + 1);
        } else if (j != 0 && i != 0) {
          int iii = dp[i - 1][j] + vec[i + j - 1].liveliness *
                                       abs(N - i - vec[i + j - 1].oldplace);
          int jjj = dp[i][j - 1] + vec[i + j - 1].liveliness *
                                       abs(vec[i + j - 1].oldplace - j + 1);
          dp[i][j] = max(iii, jjj);
        }
      }
    }
  }
  int maxi = 0;
  for (int i = 0; i < N + 1; i++) {
    maxi = max(maxi, dp[i][N - i]);
  }
  cout << maxi << endl;
}
