#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<long long> nums(n);
  for (int i = 0; i < n; i++) cin >> nums[i];
  long long l = 0, r = n - 1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long mv = -1, mp = 0;
    for (int j = 0; j < n; j++) {
      if (nums[j] == -2) continue;
      if (mv == -1) {
        mv = nums[j];
        mp = j;
      } else {
        if (mv * max(abs(mp - l), abs(mp - r)) <
            nums[j] * max(abs(j - l), abs(j - r))) {
          mv = nums[j];
          mp = j;
        }
      }
    }
    if (abs(mp - l) > abs(mp - r)) {
      ans += nums[mp] * abs(mp - l);
      l++;
    } else {
      ans += nums[mp] * abs(mp - r);
      r--;
    }
    nums[mp] = -2;
  }
  cout << ans << endl;
}
