#include <bits/stdc++.h>
using namespace std;
int main() {
  long long ans = 0;
  long long ext;
  int whe;
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<tuple<long long, int, long long, int> > q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    q.push_back(make_tuple(a[i] * (long long)max(abs(i), abs(n - 1 - i)),
                           max(abs(i), abs(n - 1 - i)), a[i], i));
  }
  sort(q.begin(), q.begin() + n);
  int l = 0, r = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    ext = get<0>(q[i]);
    whe = get<3>(q[i]);
    ans += ext;
    if (abs(l - whe) > abs(whe - r)) {
      l++;
    } else {
      r--;
    }
    for (int j = 0; j < i; j++) {
      long long tmp;
      int ho;
      tie(ignore, ignore, tmp, ho) = q[j];
      q[j] = make_tuple(tmp * (long long)max(abs(r - ho), abs(l - ho)),
                        max(abs(r - ho), abs(l - ho)), tmp, ho);
    }
    sort(q.begin(), q.begin() + i);
  }
  cout << ans << endl;
}
