#include <bits/stdc++.h>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
using ipair = pair<int64_t, int32_t>;
bool operator<(const ipair a, const ipair b) { return a.first > b.first; };
using pair_pq_type = priority_queue<ipair, vector<ipair>, less<ipair>>;
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int32_t N;
  cin >> N;
  vector<int64_t> A(N, 0);
  for (auto& a : A) {
    cin >> a;
  }
  vector<pair_pq_type> pq_vect(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int64_t uscore = abs(i - j) * A[i];
      pq_vect[j].push(make_pair(uscore, i));
    }
  }
  unordered_set<int> used_src;
  unordered_set<int> used_dst;
  int64_t res = 0;
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      if (used_src.count(i) != 0) continue;
      ipair max_pair(-1, 0);
      int32_t max_j_idx = 0;
      for (int j = 0; j < N; j++) {
        if (used_dst.count(j) != 0) continue;
        ipair tmp = pq_vect[j].top();
        while (used_src.count(tmp.second) != 0) {
          pq_vect[j].pop();
          tmp = pq_vect[j].top();
        }
        if (tmp.first > max_pair.first) {
          max_pair = tmp;
          max_j_idx = j;
        }
      }
      res += max_pair.first;
      used_src.emplace(max_pair.second);
      used_dst.emplace(max_j_idx);
    }
  }
  cout << res << endl;
  return 0;
}
