#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0, y = 0;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    int max = 0;
    y = -1;
    if (arr[i] == -1) continue;
    for (int j = 0; j < n; j++) {
      if (arr[j] == -1)
        continue;
      else {
        int dist = abs(i - j);
        if (((arr[i] + arr[j]) * dist) > max) {
          y = j;
          max = (arr[i] + arr[j]) * dist;
        }
      }
    }
    if (y >= 0) {
      arr[i] = -1;
      arr[y] = -1;
      sum += max;
    }
  }
  cout << sum;
  return 0;
}
