#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long long MAX_N = 3000;
int main() {
  long long N;
  cin >> N;
  pair<long long, long long> A[N];
  for (long long i = 0; i < (long long)(N); i++) {
    long long a_tmp;
    cin >> a_tmp;
    A[i] = make_pair(a_tmp, i);
  }
  long long ans = 0;
  for (long long border = 0; border < (long long)(N + 1); border++) {
    pair<long long, long long> A1[border];
    pair<long long, long long> A2[N - border];
    for (long long i = 0; i < (long long)(N); i++) {
      if (i < border)
        A1[i] = A[i];
      else
        A2[i - border] = A[i];
    }
    sort(A1, A1 + border, greater<pair<long long, long long> >());
    sort(A2, A2 + N - border, greater<pair<long long, long long> >());
    long long ans_tmp = 0;
    for (long long i = 0; i < (long long)(border); i++) {
      long long move = (N - 1 - i) - A1[i].second;
      long long tmp = A1[i].first * move;
      ans_tmp += tmp;
    }
    for (long long i = 0; i < (long long)(N - border); i++) {
      long long move = A2[i].second - i;
      long long tmp = A2[i].first * move;
      ans_tmp += tmp;
    }
    if (ans_tmp > ans) ans = ans_tmp;
  }
  printf("%lld\n", ans);
}
