#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e6 + 5;
int n;
int p[MAX];
int q[MAX];
long long test(int a, int b) {
  vector<pair<int, int> > v1;
  vector<pair<int, int> > v2;
  for (int i = (0); i < (a); ++i) v1.push_back({p[i], i});
  for (int i = (a); i < (n); ++i) v2.push_back({p[i], i});
  sort(v1.rbegin(), v1.rend());
  sort(v2.rbegin(), v2.rend());
  long long ret = 0;
  for (int i = (0); i < (a); ++i) {
    int npos = n - i - 1;
    int d = abs(npos - v1[i].second);
    ret += (long long)v1[i].first * d;
  }
  for (int i = (0); i < (b); ++i) {
    int npos = i;
    int d = abs(npos - v2[i].second);
    ret += (long long)v2[i].first * d;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", p + i);
  long long res = 0;
  for (int i = (1); i < (n - 1); ++i) res = max(res, test(i, n - i));
  printf("%lld\n", res);
  return 0;
}
