#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  ios::sync_with_stdio(false);
  int n;
  ll ans = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= n / 2 - 1; i++) {
    int targetIdx = i;
    int idx = 0;
    ll m = -1;
    for (int j = 0; j < n; j++) {
      if (a[j] == 0) continue;
      if (abs(j - targetIdx) * a[j] > m) {
        idx = j;
        m = abs(j - targetIdx) * a[j];
      }
    }
    a[idx] = 0;
    ans += m;
    targetIdx = n - i - 1;
    idx = 0;
    m = -1;
    for (int j = 0; j < n; j++) {
      if (a[j] == 0) continue;
      if (abs(j - targetIdx) * a[j] > m) {
        idx = j;
        m = abs(j - targetIdx) * a[j];
      }
    }
    a[idx] = 0;
    ans += m;
  }
  if (n % 2 == 1) {
    int targetIdx = n / 2;
    int idx = 0;
    ll m = -1;
    for (int j = 0; j < n; j++) {
      if (a[j] == 0) continue;
      if (abs(j - targetIdx) * a[j] > m) {
        idx = j;
        m = abs(j - targetIdx) * a[j];
      }
    }
    a[idx] = 0;
    ans += m;
  }
  cout << ans << endl;
  return 0;
}
