#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  map<long long, long long> m;
  long long a;
  for (int i = 1; i <= N; i++) {
    cin >> a;
    m[i] = a;
  }
  long long min = 1;
  long long max = N;
  long long total = 0;
  long long x;
  long long y;
  long long f, s;
  bool flag;
  for (int i = 0; i < N; i++) {
    x = 0;
    y = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
      f = it->first;
      s = it->second;
      if (f - min > max - f) {
        if (s * (f - min) > y) {
          x = f;
          y = s * (f - min);
          flag = true;
        }
      } else {
        if (s * (max - f) > y) {
          x = f;
          y = s * (max - f);
          flag = false;
        }
      }
    }
    m.erase(x);
    total += y;
    if (flag == true) {
      min++;
    } else {
      max--;
    }
  }
  cout << total << endl;
}
