#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans = 0;
  cin >> n;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  set<long long> B;
  for (int i = 0; i < n; i++) B.insert(i);
  for (int i = 0; i < n; i++) {
    vector<long long> C, D;
    for (int j = 0; j < n; j++) {
      if (abs(*B.begin() - j) < abs(*B.rbegin() - j))
        D.push_back(1);
      else
        D.push_back(0);
      C.push_back(max(abs(*B.begin() - j), abs(*B.rbegin() - j)) * A[j]);
    }
    ans += *max_element(C.begin(), C.end());
    if (D[max_element(C.begin(), C.end()) - C.begin()])
      B.erase(*B.rbegin());
    else
      B.erase(*B.begin());
    A[(max_element(C.begin(), C.end()) - C.begin())] = 0;
  }
  cout << ans;
}
