#include <bits/stdc++.h>
using namespace std;
const int64_t N = 1e6 + 6, M = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int64_t n, s = 0;
  cin >> n;
  vector<int64_t> a(n), f(n);
  for (int64_t &e : a) cin >> e;
  for (int64_t i = 0, c = 0; c < n; c++) {
    int64_t mx = 0, x;
    for (int64_t j = 0; j < n; j++)
      if (abs(i - j) * a[j] >= mx && !f[j]) mx = abs(i - j) * a[j], x = j;
    s += mx;
    f[x] = 1;
    i = n - i - 1;
    if (i < n / 2) i++;
  }
  cout << s;
}
