#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> used(N);
  int ans = 0;
  int left = 0, right = N - 1;
  for (int i = 0; i < N; i++) {
    int mx = 0;
    int tmp;
    int direction = 0;
    for (int j = 0; j < N; j++) {
      if (used[j]) continue;
      if (A[j] * abs(left - j) > mx) {
        mx = A[j] * abs(left - j);
        tmp = j;
        direction = 0;
      }
      if (A[j] * abs(right - j) > mx) {
        mx = A[j] * abs(right - j);
        tmp = j;
        direction = 1;
      }
    }
    cerr << mx << endl;
    ans += mx;
    used[tmp] = 1;
    if (direction) {
      --right;
    } else {
      ++left;
    }
  }
  cout << ans << endl;
  return 0;
}
