#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> B, C;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> A(n);
  for (auto &a : A) cin >> a;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    B.resize(i);
    C.resize(n - i);
    for (int j = 0; j < i; j++) {
      B[j] = make_pair(A[j], -j);
    }
    for (int j = i; j < n; j++) {
      C[j - i] = make_pair(A[j], -j);
    }
    long long sum = 0;
    sort((B).begin(), (B).end(), greater<pair<long long, long long>>());
    sort((C).begin(), (C).end(), greater<pair<long long, long long>>());
    long long cnt = 0;
    for (auto a : B) {
      sum += a.first * (n - (-a.second) - 1 - cnt);
      cnt++;
    }
    cnt = 0;
    for (auto a : C) {
      sum += a.first * ((-a.second) - cnt);
      cnt++;
    }
    ans = max(sum, ans);
  }
  B.resize(n);
  for (int i = 0; i < n; i++) {
    B[i] = make_pair(A[i], -i);
  }
  long long sum = 0;
  sort((B).begin(), (B).end(), greater<pair<long long, long long>>());
  long long cnt = 0;
  for (auto a : B) {
    sum += a.first * (n - (-a.second) - 1 - cnt);
    cnt++;
  }
  cout << max(ans, sum) << endl;
  return 0;
}
