#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long N;
  cin >> N;
  set<long long> S;
  map<long long, long long> A;
  for (long long i = 0; i < N; i++) {
    S.insert(i + 1);
    long long a;
    cin >> a;
    A[i + 1] = a;
  }
  long long score = 0;
  while (A.size() > 0) {
    long long currentMaxScore = -1;
    long long smin = *S.begin();
    long long smax = *S.rbegin();
    map<long long, long long>::iterator mx = A.end();
    for (auto it = A.begin(); it != A.end(); it++) {
      long long myscore =
          max(abs(it->first - smin), abs(it->first - smax)) * it->second;
      if (currentMaxScore < myscore) {
        currentMaxScore = myscore;
        mx = it;
      }
    }
    if (abs(mx->first - smin) < abs(smax - mx->first)) {
      auto it = S.end();
      it--;
      S.erase(it);
    } else {
      S.erase(S.begin());
    }
    score += currentMaxScore;
    A.erase(mx);
  }
  cout << score << endl;
}
