#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void d_err() { cerr << endl; }
template <typename H, typename... T>
void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}
template <typename T>
void print(T x) {
  cout << x << endl;
}
long long INF = 1e16;
int inf = 1e9;
long long MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = (0); i < (N); ++i) {
    cin >> A[i];
  }
  vector<bool> used(N, false);
  long long ans = 0;
  int m = 0, M = N - 1;
  for (int i = (0); i < (N); ++i) {
    long long tmp = -1;
    bool small;
    int idx = -1;
    for (int i = (0); i < (N); ++i) {
      if (used[i]) continue;
      long long imax = max(i - m, M - i) * A[i];
      if (tmp < imax) {
        tmp = imax;
        idx = i;
        small = i - m > M - i;
      }
    }
    ans += tmp;
    used[idx] = true;
    (small ? m++ : M--);
  }
  print(ans);
}
