#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
struct infant {
  int id;
  long long seat;
  long long score;
  bool operator<(const infant &other) const {
    if (score < other.score)
      return true;
    else
      return false;
  }
};
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  vector<infant> infants(N * N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      infants[i * N + j].id = i;
      infants[i * N + j].score = A[i] * abs(i - j);
      infants[i * N + j].seat = j;
    }
  }
  sort((infants).begin(), (infants).end());
  reverse((infants).begin(), (infants).end());
  set<long long> selected, seated;
  int idx = 0;
  long long sum = 0, num_selected = 0;
  while (num_selected < N) {
    if (selected.find(infants[idx].id) == selected.end() &&
        seated.find(infants[idx].seat) == seated.end()) {
      selected.insert(infants[idx].id);
      seated.insert(infants[idx].seat);
      sum += infants[idx].score;
      num_selected++;
      if (num_selected == N) break;
    }
    idx++;
  }
  cout << sum << endl;
  return 0;
}
