#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const char E = '\n';
const int N = 2105;
const int NN = 200005;
const long long md = 1e9 + 7;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  long long a[N] = {0};
  pair<long long, long long> c[N];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[i] = {a[i], i};
  }
  long long ans = 0;
  int u[N] = {0};
  long long l = 0, r = n + 1;
  sort(c + 1, c + n + 1);
  for (int i = 1; i <= n; i++) {
    long long mx = 0, ii = 0;
    for (int j = 1; j <= n; j++) {
      if (!u[j]) {
        l++;
        if (mx < a[j] * abs(j - l)) {
          ii = j;
          mx = a[j] * abs(j - l);
        }
        l--;
        r--;
        if (mx < a[j] * abs(r - j)) {
          ii = j;
          mx = a[j] * abs(r - j);
        }
        r++;
      }
    }
    long long v, p;
    v = a[ii];
    p = ii;
    u[ii] = 1;
    if (p - (l + 1) > (r - 1) - p) {
      ans += v * (p - (l + 1));
      l++;
    } else {
      ans += v * ((r - 1) - p);
      r--;
    }
  }
  cout << ans << E;
  return 0;
}
