#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<pair<long long, long long>> m(n);
  for (long long i = 0; i < n; i++) {
    m[i].first = a[i];
    m[i].second = 0;
  }
  long long l = 0, r = n - 1, ans = 0;
  for (long long i = 0; i < n; i++) {
    long long max_set = -1, max_idx = -1;
    for (long long j = 0; j < n; j++) {
      if (m[j].second == 1) continue;
      if (max_idx == -1) {
        max_idx = j;
        if (abs(max_idx - r) > abs(max_idx - l)) {
          max_set = r;
        } else {
          max_set = l;
        }
      } else {
        if (m[j].first * abs(j - r) >
            m[max_idx].first * abs(max_idx - max_set)) {
          max_idx = j;
          max_set = r;
        }
        if (m[j].first * abs(j - l) >
            m[max_idx].first * abs(max_idx - max_set)) {
          max_idx = j;
          max_set = l;
        }
      }
    }
    m[max_idx].second = 1;
    ans += m[max_idx].first * abs(max_idx - max_set);
    if (max_set == r)
      r--;
    else
      l++;
  }
  cout << ans << endl;
  return 0;
}
