#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long int ans = 0;
  int l = 0, r = n - 1;
  vector<bool> vis(n, false);
  for (int i = 0; i < n; i++) {
    vector<pair<pair<long long int, int>, int> > vt;
    for (int j = 0; j < n; j++) {
      if (vis[j] == false) {
        long long int f = v[j] * 1LL * abs(j - l);
        long long int b = v[j] * 1LL * abs(j - r);
        if (f > b)
          vt.push_back(make_pair(make_pair(-f, j), 0));
        else
          vt.push_back(make_pair(make_pair(-b, j), 1));
      }
    }
    sort(vt.begin(), vt.end());
    if (vt[0].second == 0)
      l += 1;
    else
      r -= 1;
    ans += -vt[0].first.first;
    vis[vt[0].first.second] = true;
  }
  cout << ans << endl;
}
