#include <bits/stdc++.h>
using namespace std;
class DebugStream {
} LOG;
template <typename T>
DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,
          bs = 29;
long long arr[maxN];
long long frm(int w, int ot) { return arr[w] * abs(w - ot); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<bool> vi(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long ans = 0;
  for (int i = 0, le = 0, ri = n - 1; i < n; i++) {
    int cr = -1, sd;
    for (int j = 0; j < n; j++) {
      if (vi[j]) continue;
      long long opt = frm(j, le), oth = frm(j, ri), csd = le;
      if (oth > opt) opt = oth, csd = ri;
      if (cr == -1 || opt > frm(cr, sd)) cr = j, sd = csd;
    }
    vi[cr] = 1;
    ans += frm(cr, sd);
    if (sd == le)
      le++;
    else
      ri--;
  }
  cout << ans << '\n';
}
