#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto &x : A) cin >> x;
  vector<bool> decided(N, 0);
  int l = 0, r = N - 1;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long maxi = -1;
    int who = -1;
    for (int j = 0; j < N; j++) {
      if (!decided[j]) {
        if (maxi < A[j] * max(abs(l - j), abs(r - j))) {
          maxi = A[j] * max(abs(l - j), abs(r - j));
          who = j;
        }
      }
    }
    if (abs(l - who) > abs(r - who)) {
      ans += A[who] * abs(l - who);
      l++;
    } else {
      ans += A[who] * abs(r - who);
      r--;
    }
    decided[who] = true;
  }
  cout << ans << endl;
}
