#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long right = n - 1;
  long long left = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long max_right = 0;
    long long max_left = 0;
    long long index_r = 0;
    long long index_l = 0;
    for (int j = 0; j < n; j++) {
      long long x = abs(j - left) * a[j];
      long long y = abs(j - right) * a[j];
      if (max_right < y) {
        max_right = y;
        index_r = j;
      }
      if (max_left < x) {
        max_left = x;
        index_l = j;
      }
    }
    if (max_left > max_right) {
      ans += max_left;
      left++;
      a[index_l] = 0;
    } else {
      ans += max_right;
      right--;
      a[index_r] = 0;
    }
  }
  cout << ans << endl;
}
