#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<long long, long long>> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    auto X = A.back();
    A.pop_back();
    A.insert(A.begin(), X);
    vector<pair<long long, long long>> copy = A;
    sort(A.begin(), A.begin() + i + 1, greater<pair<long long, long long>>());
    sort(A.begin() + i + 1, A.end());
    long long t = 0;
    for (int j = 0; j < N; j++) {
      t += A[j].first * abs(j - A[j].second);
    }
    ans = max(ans, t);
    A = copy;
  }
  cout << ans << endl;
  return 0;
}
