#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = (long long)(0); i < (long long)(N); i++) cin >> A[i];
  vector<long long> dp(N + 1);
  for (long long i = (long long)(0); i < (long long)(N); i++)
    dp[i + 1] = dp[i] + A[i];
  long long ans = 0;
  for (long long i = (long long)(1); i < (long long)(N); i++) {
    vector<pair<long long, long long> > B, C;
    for (long long j = (long long)(1); j <= (long long)(i); j++) {
      B.push_back(make_pair(A[N - j], N - j));
    }
    for (long long j = (long long)(0); j < (long long)(N - i); j++)
      C.push_back(make_pair(A[j], j));
    sort((B).begin(), (B).end(), greater<pair<long long, long long> >());
    sort((C).begin(), (C).end());
    long long sum = 0;
    for (long long j = (long long)(0); j < (long long)(i); j++)
      sum += B[j].first * abs(B[j].second - j);
    for (long long j = (long long)(i); j < (long long)(N); j++)
      sum += C[j - i].first * abs(C[j - i].second - j);
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
