#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
bool vis[maxn];
bool used[maxn];
long long po[maxn];
struct unit {
  int pos;
  int to;
  long long val;
};
bool cmp(unit a, unit b) { return a.val > b.val; }
vector<unit> fuck;
int main() {
  int n;
  cin >> n;
  int pr = n, pl = 1;
  for (int i = 1; i <= n; i++) {
    cin >> po[i];
    long long r = pr - i, l = i - pl;
    unit a;
    a.pos = i;
    a.val = r * po[i];
    a.to = pr;
    fuck.push_back(a);
    a.val = l * po[i];
    a.to = pl;
    fuck.push_back(a);
  }
  sort(fuck.begin(), fuck.end(), cmp);
  memset(vis, 0, sizeof(vis));
  memset(used, 0, sizeof(used));
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    unit now = fuck[0];
    ans += now.val;
    vis[now.pos] = true;
    used[now.to] = true;
    if (now.to == pr) {
      while (used[pr] && pr > 1) pr--;
    } else {
      while (used[pl] && pl < n) {
        pl++;
      }
    }
    fuck.clear();
    for (int j = 1; j <= n; j++) {
      if (vis[j]) continue;
      long long r = abs(pr - j), l = abs(j - pl);
      unit a;
      a.pos = j;
      a.val = r * po[j];
      a.to = pr;
      fuck.push_back(a);
      a.val = l * po[j];
      a.to = pl;
      fuck.push_back(a);
    }
    sort(fuck.begin(), fuck.end(), cmp);
  }
  cout << ans << endl;
  return 0;
}
