#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N, 0);
  for (int i = (0); i < (N); ++i) {
    cin >> A[i];
    B[i] = i;
  }
  sort((B).begin(), (B).end(), [&](const int &i, const int &j) {
    return A[i] * max(i, N - 1 - i) > A[j] * max(j, N - 1 - j);
  });
  long long ret = 0;
  for (int i = (0); i < (N); ++i) {
    int ii = B[i];
    long long a = A[ii];
    int best_diff = 0;
    int best_j = 0;
    for (int j = (0); j < (N); ++j) {
      if (C[j]) continue;
      int diff = abs(ii - j);
      if (best_diff < diff) {
        best_diff = diff;
        best_j = j;
      }
    }
    ret += a * best_diff;
    C[best_j] = 1;
  }
  cout << ret << endl;
  return 0;
}
