#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
void scan(long long &n) { scanf("%lld", &n); }
void scan(long long &n, long long &m) { scanf("%lld%lld", &n, &m); }
void scan(vector<long long> &v) {
  long long n = v.size();
  for (long long i = 0; i < n; i++) scanf("%lld", &v[i]);
}
vector<long long> adj[N];
void edge(long long u, long long v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
long long arr[N][N];
long long val[N], use[N];
int main() {
  long long n, i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> val[i];
    for (j = 0; j < n; j++) {
      arr[i][j] = abs(i - j) * val[i];
    }
  }
  long long l = 0, r = n - 1, ans = 0;
  for (i = 0; i < n; i++) {
    pair<long long, long long> nxt[1];
    long long mx = 0, sc = -1;
    for (j = 0; j < n; j++) {
      if (!use[j]) {
        if (arr[j][l] >= mx) {
          if (arr[j][l] == mx) {
            if (arr[j][r] > sc) continue;
          }
          mx = arr[j][l];
          nxt[0].first = j;
          nxt[0].second = l;
        }
      }
    }
    for (j = 0; j < n; j++) {
      if (!use[j]) {
        if (arr[j][r] >= mx) {
          if (arr[j][l] == mx) {
            if (arr[j][l] > sc) continue;
          }
          mx = arr[j][r];
          nxt[0].first = j;
          nxt[0].second = r;
        }
      }
    }
    if (nxt[0].second == r) {
      r--;
      use[nxt[0].first] = 1;
    } else {
      l++;
      use[nxt[0].first] = 1;
    }
    ans += mx;
  }
  cout << ans << endl;
  return 0;
}
