#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  ll res1 = 0, res2 = 0;
  vector<bool> used1(n, false);
  for (int i = 0; i < n; ++i) {
    int cur;
    if (i % 2 == 0)
      cur = i / 2;
    else
      cur = n - i / 2 - 1;
    ll happy = -1;
    int pla = -1;
    for (int j = 0; j < n; ++j) {
      if (!used1.at(j) && chmax(happy, a.at(j) * abs(j - cur))) {
        pla = j;
      }
    }
    used1.at(pla) = true;
    res1 += happy;
  }
  vector<bool> used2(n, false);
  for (int i = 0; i < n; ++i) {
    int cur;
    if (i % 2 == 0)
      cur = n - i / 2 - 1;
    else
      cur = i / 2;
    ll happy = -1;
    int pla = -1;
    for (int j = 0; j < n; ++j) {
      if (!used2.at(j) && chmax(happy, a.at(j) * abs(j - cur))) {
        pla = j;
      }
    }
    used2.at(pla) = true;
    res2 += happy;
  }
  cout << max(res1, res2) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}
