#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int m = 1e9 + 7;
using P = pair<int, int>;
struct d {
  ll i, j, x;
  bool operator<(const d e) const { return x < e.x; }
};
int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  priority_queue<d> que;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      que.push({i, j, (a[i] + a[j]) * (j - i)});
    }
  }
  ll an = 0;
  bool u[n];
  fill(u, u + n, false);
  while (!que.empty()) {
    d o = que.top();
    que.pop();
    if (u[o.i] || u[o.j]) continue;
    u[o.i] = u[o.j] = true;
    an += o.x;
  }
  cout << an << endl;
}
