#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 0, r = n - 1;
  long long ans = 0;
  vector<bool> moved(n, false);
  for (int i = 0; i < n; i++) {
    long long ans1 = -1;
    int ans1_j = -1;
    for (int j = 0; j < n; j++) {
      if (moved[j]) {
        continue;
      }
      long long ans2 = (long long)a[j] * max(abs(j - l), abs(r - j));
      if (ans2 > ans1) {
        ans1 = ans2;
        ans1_j = j;
      }
    }
    if (abs(ans1_j - l) > abs(ans1_j - r)) {
      ans += (long long)a[ans1_j] * abs(ans1_j - l);
      l++;
    } else {
      ans += (long long)a[ans1_j] * abs(ans1_j - r);
      r--;
    }
    moved[ans1_j] = true;
  }
  cout << ans;
}
