#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
class baby {
 public:
  long long score;
  int from;
  int to;
  baby(long long score, int from, int to) {
    this->score = score;
    this->from = from;
    this->to = to;
  };
  friend bool operator<(const baby& a, const baby& b) {
    if (a.score < b.score) return true;
    if (a.score > b.score) return false;
    return false;
  };
};
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  priority_queue<baby> q;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      q.emplace(A[i] * abs(i - j), i, j);
    }
  }
  set<int> from;
  set<int> to;
  long long score = 0;
  while (!q.empty()) {
    auto b = q.top();
    q.pop();
    if (from.count(b.from) == 1 || to.count(b.to) == 1) continue;
    score += b.score;
    from.insert(b.from);
    to.insert(b.to);
  }
  cout << score << endl;
  return 0;
}
