#include <bits/stdc++.h>
template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long int;
const int MOD = 1000000007;
const int INTMAX = 1001001000;
const ll LLMAX = 1010010010010010000;
bool comp(vector<ll> a, vector<ll> b) { return a[0] * a[1] > b[0] * b[1]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  vector<vector<ll> > A(N, vector<ll>(4));
  for (ll i = 0; i < N; i++) {
    cin >> A[i][0];
    if (N - 1 - i > i) {
      A[i][1] = N - 1 - i;
      A[i][2] = 1;
      A[i][3] = i;
    } else {
      A[i][1] = i;
      A[i][2] = 0;
      A[i][3] = i;
    }
  }
  sort(A.begin(), A.end(), comp);
  ll ans = 0;
  ll a = 0, b = N - 1;
  for (ll i = 0; i < N; i++) {
    ans += A[0][0] * A[0][1];
    if (A[0][2] == 1)
      b--;
    else
      a++;
    for (ll i = 1; i < A.size(); i++) {
      if (b - A[i][3] > A[i][3] - a) {
        A[i][1] = b - A[i][3];
        A[i][2] = 1;
      } else {
        A[i][1] = A[i][3] - a;
        A[i][2] = 0;
      }
    }
    A.erase(A.begin());
    sort(A.begin(), A.end(), comp);
  }
  cout << ans << endl;
  return 0;
}
