#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A;
  cin >> N;
  vector<pair<long long, long long>> Ai(N), Bi(N), Ci(N);
  for (int i = 0; i < N; i++) {
    cin >> A;
    Ci[i] = make_pair(A, i);
  }
  long long ans = 0;
  for (int j = 0; j < N + 1; j++) {
    for (int i = 0; i < N; i++) Ai[i] = Ci[i];
    sort(Ai.begin(), Ai.begin() + j);
    sort(Ai.begin() + j, Ai.end());
    for (int i = 0; i < N - j; i++) {
      Bi[i] = Ai[N - 1 - i];
    }
    for (int i = 0; i < j; i++) {
      Bi[N - 1 - i] = Ai[j - 1 - i];
    }
    long long total = 0;
    for (int i = 0; i < N; i++) {
      total += Bi[i].first * abs(Bi[i].second - i);
    }
    ans = max(ans, total);
  }
  cout << ans << "\n";
}
