#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<bool> x(n, false);
  vector<bool> y(n, false);
  vector<pair<long long, pair<int, int>>> vec(0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      long long d = abs(i - j);
      vec.push_back({-d * a[i], {i, j}});
    }
  }
  sort(vec.begin(), vec.end());
  long long res = 0;
  for (int i = 0; i < n * n; ++i) {
    if (x[vec[i].second.first] || y[vec[i].second.second]) continue;
    res += vec[i].first;
    x[vec[i].second.first] = true;
    y[vec[i].second.second] = true;
  }
  cout << -res << "\n";
  return 0;
}
