#include <bits/stdc++.h>
using namespace std;
int tot = 0;
int a[2010];
struct node {
  int id;
  int p;
  long long h;
  node() {}
  node(int id, int p, long long h) : id(id), p(p), h(h) {}
  bool operator<(const node &o) const { return h > o.h; }
} pos[(int)4e6 + 10];
int vis1[2010];
int vis2[2010];
int main(void) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) pos[tot++] = node(i, j, abs(i - j) * a[i]);
  }
  sort(pos, pos + tot);
  long long res = 0;
  for (int i = 0; i < tot; ++i) {
    int id = pos[i].id;
    int p = pos[i].p;
    if (!vis1[id] && !vis2[p]) {
      res += pos[i].h;
      vis1[id] = vis2[p] = 1;
    }
  }
  cout << res << endl;
  return 0;
}
