#include <bits/stdc++.h>
const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const long long LINF = 1000000000000000000;
const double EPS = 1E-10;
template <class T, class S>
bool chmax(T &a, const S &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class S>
bool chmin(T &a, const S &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N;
  std::cin >> N;
  long long A;
  std::priority_queue<
      std::pair<long long, std::pair<long long, std::pair<int, int>>>>
      que;
  for (int i(0); i < N; ++i) {
    std::cin >> A;
    for (int j(0); j < N; ++j) {
      que.push({std::abs(i - j) * A, {-A, {i, j}}});
    }
  }
  long long ans(0);
  std::vector<bool> usedi(N, false), usedj(N, false);
  while (!que.empty()) {
    std::pair<long long, std::pair<long long, std::pair<int, int>>> p(
        que.top());
    que.pop();
    if (usedi[p.second.second.first] || usedj[p.second.second.second]) continue;
    ans += p.first;
    usedi[p.second.second.first] = usedj[p.second.second.second] = true;
  }
  std::cout << ans << std::endl;
  return 0;
}
