#include <bits/stdc++.h>
using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
void mul_mod(ll& a, ll b) {
  a *= b;
  a %= MOD;
}
void add_mod(ll& a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}
ll a[2222];
P b[2222];
int main(void) {
  int n, i, j;
  ll ans = -INFLL, tmp;
  std::cin >> n;
  for (i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  for (i = 0; i <= n; ++i) {
    for (j = 0; j < i; ++j) {
      b[n - i + j] = P(a[j], j);
    }
    for (j = i; j < n; ++j) {
      b[j - i] = P(a[j], j);
    }
    std::sort(b, b + n - i, std::greater<P>());
    std::sort(b + n - i, b + n);
    tmp = 0ll;
    for (j = 0; j < n; ++j) {
      tmp += b[j].first * abs(j - b[j].second);
    }
    ans = std::max(ans, tmp);
  }
  std::cout << ans << std::endl;
  return 0;
}
