#include <bits/stdc++.h>
using namespace std;
struct Data {
  long long a;
  long long i;
  long long j;
  long long score;
  bool operator<(const Data& d) const {
    return score < d.score || (score == d.score && a > d.a);
  }
};
int main() {
  long long n;
  cin >> n;
  long long a[2000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  priority_queue<Data> Q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      Q.push(Data{a[i], i, j, abs(i - j) * a[i]});
    }
  }
  long long ans = 0;
  bool rowused[2000] = {false};
  bool colused[2000] = {false};
  while (!Q.empty()) {
    Data d = Q.top();
    Q.pop();
    if (rowused[d.i]) continue;
    if (colused[d.j]) continue;
    rowused[d.i] = true;
    colused[d.j] = true;
    ans += d.score;
  }
  cout << ans << endl;
  return 0;
}
