#include <bits/stdc++.h>
using namespace std;
class Baby {
 public:
  int activeness;
  bool positioned;
};
int main() {
  int N;
  vector<Baby> babies;
  int ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int active;
    cin >> active;
    Baby b;
    b.positioned = false;
    if (b.positioned) {
      cout << "FF\n";
    }
    b.activeness = active;
    babies.push_back(b);
  }
  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 (!babies[j].positioned &&
          max((last - j), j - first) * babies[j].activeness > greedy) {
        greedy = max((last - j), j - first) * babies[j].activeness;
        max_index = j;
      }
    }
    if (max_index == -1) {
      cout << "F\n";
    }
    babies[max_index].positioned = true;
    ans += greedy;
    (last - max_index > max_index - first) ? last-- : first++;
  }
  cout << ans;
}
