#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> v(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> v[i];
  }
  lint res = 0;
  int l = 0, r = N - 1;
  vector<bool> visited(N, false);
  for (int j = 0; j < N; ++j) {
    int mv = 0, mlr = -1, iv;
    for (int i = 0; i < N; ++i) {
      if (!visited[i] && mv < v[i] * max(r - i, i - l)) {
        iv = i;
        mv = v[i] * max(r - i, i - l);
        if (r - i > i - l) {
          mlr = 1;
        } else {
          mlr = 0;
        }
      }
    }
    if (mlr == 0)
      ++l;
    else if (mlr == 1)
      --r;
    visited[iv] = true;
    res += mv;
  }
  cout << res << endl;
  return 0;
}
