#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 2e3 + 10;
int a[N];
ll par(int pos, int n) {
  priority_queue<pii> pq;
  ll val = 0;
  for (int i = 1; i <= pos; i++) {
    pq.push({a[i], i});
  }
  int cur = n;
  while (!pq.empty()) {
    val += 1LL * pq.top().first * abs(cur - pq.top().second);
    pq.pop();
    cur--;
  }
  for (int i = pos + 1; i <= n; i++) {
    pq.push({a[i], i});
  }
  cur = 1;
  while (!pq.empty()) {
    val += 1LL * pq.top().first * abs(cur - pq.top().second);
    pq.pop();
    cur++;
  }
  return val;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  ll ans = 0LL;
  for (int i = 1; i < n; i++) {
    ans = max(ans, par(i, n));
  }
  printf("%lld", ans);
}
