#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const int mx = 200010;
const long long mod = 1e9 + 7;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
int main() {
  int n;
  cin >> n;
  vector<long long> a(n, 0);
  vector<bool> used(n, false);
  for (int i = (int)(0); i < (int)(n); ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n / 2; i++) {
    long long pos = -1;
    long long tmp = -1;
    for (int j = (int)(0); j < (int)(n); ++j)
      if (!used[j]) {
        if (tmp < abs(j - i) * a[j]) {
          tmp = abs(j - i) * a[j];
          pos = j;
        }
      }
    ans += tmp;
    used[pos] = true;
    pos = -1;
    tmp = -1;
    for (int j = (int)(0); j < (int)(n); ++j)
      if (!used[j]) {
        if (tmp < abs(j - (n - 1 - i)) * a[j]) {
          tmp = abs(j - (n - 1 - i)) * a[j];
          pos = j;
        }
      }
    ans += tmp;
    used[pos] = true;
  }
  if (n % 2) {
    long long pos = -1;
    long long tmp = -1;
    for (int j = (int)(0); j < (int)(n); ++j)
      if (!used[j]) {
        if (tmp < abs(j - ((n + 1) / 2)) * a[j]) {
          tmp = abs(j - ((n + 1) / 2)) * a[j];
          pos = j;
        }
      }
    ans += tmp;
    used[pos] = true;
  }
  long long ans1 = ans;
  ans = 0;
  for (int i = (int)(0); i < (int)(n); ++i) {
    used[i] = false;
  }
  for (int i = 0; i < n / 2; i++) {
    long long pos = -1;
    long long tmp = -1;
    for (int j = (int)(0); j < (int)(n); ++j)
      if (!used[j]) {
        if (tmp < abs(j - (n - 1 - i)) * a[j]) {
          tmp = abs(j - (n - 1 - i)) * a[j];
          pos = j;
        }
      }
    ans += tmp;
    used[pos] = true;
    pos = -1;
    tmp = -1;
    for (int j = (int)(0); j < (int)(n); ++j)
      if (!used[j]) {
        if (tmp < abs(j - i) * a[j]) {
          tmp = abs(j - i) * a[j];
          pos = j;
        }
      }
    ans += tmp;
    used[pos] = true;
  }
  if (n % 2) {
    long long pos = -1;
    long long tmp = -1;
    for (int j = (int)(0); j < (int)(n); ++j)
      if (!used[j]) {
        if (tmp < abs(j - ((n + 1) / 2)) * a[j]) {
          tmp = abs(j - ((n + 1) / 2)) * a[j];
          pos = j;
        }
      }
    ans += tmp;
    used[pos] = true;
  }
  ans = max(ans, ans1);
  cout << ans << endl;
  return 0;
}
