#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return 0;
}
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N);
  for (auto& a : A) {
    cin >> a;
  }
  using P = pair<ll, ll>;
  using PP = pair<P, P>;
  priority_queue<PP> que;
  for (int i = (int)0; i < (int)N; ++i)
    for (int j = (int)0; j < (int)N; ++j) {
      que.push(PP(P(A[i] * abs(i - j), -A[i]), P(i, j)));
    }
  vector<bool> used(N, false), placed(N, false);
  ll ans = 0;
  while (true) {
    PP now = que.top();
    que.pop();
    ll cost = now.first.first;
    ll origin_pos = now.second.first;
    ll next_pos = now.second.second;
    if (placed[next_pos] || used[origin_pos]) {
      continue;
    }
    ans += cost;
    placed[next_pos] = true;
    used[origin_pos] = true;
    bool is_ok = true;
    for (int i = (int)0; i < (int)N; ++i) {
      if (!placed[i]) {
        is_ok = false;
        break;
      }
    }
    if (is_ok) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
