#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int j = 0, k = n - 1;
  bool b[n];
  for (int i = 0; i < n; i++) b[i] = true;
  long long ans = 0;
  for (int c = 0; c < n; c++) {
    long long maxx = 0;
    int d = 0;
    int u = 0;
    for (int i = 0; i < n; i++) {
      if (b[i]) {
        if (a[i] * abs(i - j) > maxx) {
          maxx = a[i] * (abs(i - j));
          u = i;
          d = -1;
        }
        if (a[i] * abs(i - k) > maxx) {
          u = i;
          maxx = a[i] * (abs(i - k));
          d = 1;
        }
      }
    }
    if (d == 0) {
      break;
    }
    if (d == -1) {
      b[u] = false;
      ans += maxx;
      j++;
    }
    if (d == 1) {
      b[u] = false;
      ans += maxx;
      k--;
    }
  }
  cout << ans << endl;
  return 0;
}
