#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long long> A(N);
  vector<bool> flag(N, true);
  vector<pair<long long, long long> > v(N);
  int M = N - 1;
  int m = 0;
  long long ans = 0;
  for (int i = 0; i < (N); i++) {
    cin >> A[i];
  }
  for (int i = 0; i < (N); i++) {
    long long t1 = abs(A[i] * (i - m));
    long long t2 = abs(A[i] * (M - i));
    if (t1 > t2) {
      v[i].first = t1;
      v[i].second = m;
    } else {
      v[i].first = t2;
      v[i].second = M;
    }
  }
  for (int i = 0; i < (N); i++) {
    pair<long long, long long> p;
    p.first = -1;
    int tmp;
    for (int j = 0; j < (N); j++) {
      if (flag[j]) {
        long long t1 = A[j] * abs(j - m);
        long long t2 = A[j] * abs(M - j);
        if (t1 > t2) {
          v[j].first = t1;
          v[j].second = m;
        } else {
          v[j].first = t2;
          v[j].second = M;
        }
        if (v[j].first > p.first) {
          p = v[j];
          tmp = j;
        }
      }
    }
    ans += p.first;
    if (p.second == m) {
      m++;
    } else {
      M--;
    }
    flag[tmp] = false;
  }
  cout << ans << endl;
}
