#include <bits/stdc++.h>
using namespace std;
int activeness[2000];
bool positioned[2000];
int main() {
  int N;
  long long ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> activeness[i];
  }
  int first = 0;
  int last = N - 1;
  for (int i = 0; i < N; i++) {
    int greedy = -1;
    int max_index = -1;
    for (int j = 0; j < N; j++) {
      if (!positioned[j] &&
          max((last - j), j - first) * activeness[j] > greedy) {
        greedy = max((last - j), j - first) * activeness[j];
        max_index = j;
      }
    }
    if (max_index == -1) {
      cout << "F\n";
    }
    positioned[max_index] = true;
    ans += greedy;
    (last - max_index > max_index - first) ? last-- : first++;
  }
  cout << ans;
}
