#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long A[2001];
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  int person[2001] = {0};
  int pos[2001] = {0};
  deque<pair<long, pair<int, int>>> score;
  for (int i = 1; i <= N; i++) {
    for (int pos = 1; pos <= N; pos++) {
      score.push_back(make_pair(A[i] * abs(i - pos), make_pair(i, pos)));
    }
  }
  sort(score.begin(), score.end());
  long sum = 0;
  int count = 0;
  for (auto itr = score.rbegin(); count < N; itr++) {
    if (person[(*itr).second.first] == 0 && pos[(*itr).second.second] == 0) {
      person[(*itr).second.first] = 1;
      pos[(*itr).second.second] = 1;
      sum += (*itr).first;
      count++;
    }
  }
  cout << sum << endl;
  return 0;
}
