#include <bits/stdc++.h>
using namespace std;
long long n, m, t;
long long a[2000];
long long ans[2000];
vector<long long> e, f;
int main() {
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  for (long long i = 0; i < n; i++) {
    e.push_back(a[i] * 10000 + i);
    sort(e.begin(), e.end());
    m = 0;
    for (long long j = e.size() - 1; j >= 0; j--) {
      ans[i] += a[e[j] % 10000] * (n - 1 - m - e[j] % 10000);
      m++;
    }
  }
  for (long long i = n - 1; i > 0; i--) {
    f.push_back(a[i] * 10000 + i);
    sort(f.begin(), f.end());
    m = 0;
    for (long long j = f.size() - 1; j >= 0; j--) {
      ans[i - 1] += a[f[j] % 10000] * (f[j] % 10000 - m);
      m++;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (ans[i] > t) t = ans[i];
  }
  printf("%lld\n", t);
}
