#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto& x : A) cin >> x;
  vector<pair<long long, pair<int, int>>> a;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      long long c = A[i] * abs(i - j);
      a.push_back({-c, {i, j}});
    }
  }
  sort(a.begin(), a.end());
  vector<bool> ai(N), aj(N);
  long long res = 0;
  for (auto p : a) {
    auto c = -p.first;
    auto i = p.second.first;
    auto j = p.second.second;
    if (ai[i] || aj[j]) continue;
    ai[i] = aj[j] = true;
    res += c;
  }
  cout << res << endl;
}
