#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  vector<int> visited(A.size(), 0);
  int st = 0, en = A.size() - 1;
  long long ans = 0;
  for (int i = 0; i < A.size(); i++) {
    int chosen = -1, L = 0;
    long long cost = -1;
    for (int j = 0; j < A.size(); j++) {
      if (visited[j]) continue;
      int l = abs(j - st) >= abs(j - en) ? 1 : 0;
      int dist = l == 1 ? abs(j - st) : abs(j - en);
      long long curr = A[j] * dist;
      if (curr > cost) {
        cost = curr;
        L = l;
        chosen = j;
      }
    }
    visited[chosen] = 1;
    if (L)
      st++;
    else
      en--;
    ans += cost;
  }
  cout << ans << "\n";
}
