#include <bits/stdc++.h>
using namespace std;
template <typename T>
using lim = numeric_limits<T>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    arr[i] = a;
  }
  long long ans = 0;
  long long L = 0;
  long long R = n - 1;
  bool moved[n];
  memset(moved, 0, sizeof moved);
  for (int i = 0; i < n; i++) {
    long long scoreL = -1;
    long long scoreR = -1;
    int idxL = -1;
    int idxR = -1;
    for (int j = 0; j < n; j++) {
      if (moved[j]) continue;
      if (scoreL < abs(L - j) * arr[j]) {
        scoreL = abs(L - j) * arr[j];
        idxL = j;
      }
      if (scoreR < abs(R - j) * arr[j]) {
        scoreR = abs(R - j) * arr[j];
        idxR = j;
      }
    }
    if (scoreR > scoreL) {
      moved[idxR] = true;
      ans += scoreR;
      R--;
    } else {
      moved[idxL] = true;
      ans += scoreL;
      L++;
    }
  }
  cout << ans << "\n";
}
