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