#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
std::random_device rd;
std::mt19937 mt(rd());
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 200020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr long long INF = 1e18;
void y(bool c) {
  if (c)
    cout << ("Yes") << '\n';
  else
    cout << ("No") << '\n';
};
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long add(long long x, long long y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % MOD; }
long long bin_pow(long long x, long long p) {
  if (p == 0) return 1;
  if (p & 1) return mult(x, bin_pow(x, p - 1));
  return bin_pow(mult(x, x), p / 2);
}
void solve() {
  long long N;
  cin >> N;
  long long ans = 0;
  vector<long long> A(N);
  for (long long i = 0; i < N; ++i) cin >> A[i];
  for (long long l = 0; l < N + 1; ++l) {
    vector<pair<long long, long long> > vl, vr;
    for (long long i = 0; i < l; ++i) vl.push_back({A[i], i});
    for (long long i = l; i < N; ++i) vr.push_back({A[i], i});
    sort(vl.rbegin(), vl.rend());
    sort(vr.rbegin(), vr.rend());
    long long res = 0;
    for (long long i = 0; i < l; ++i) {
      res += vl[i].first * (abs(N - i - 1 - vl[i].second));
    }
    for (long long i = 0; i < N - l; ++i) {
      res += vr[i].first * (abs(vr[i].second - i));
    }
    ans = max(ans, res);
  }
  cout << (ans) << '\n';
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
