#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long mod = 1e9 + 7;
template <class T>
T maxt(T x, T y) {
  if (x > y)
    return x;
  else
    return y;
}
template <class T>
T mint(T x, T y) {
  if (x > y)
    return y;
  else
    return x;
}
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
struct edge {
  int from;
  int to;
  long long cost;
};
vector<long long> bellman_ford(vector<edge> edges, int V, int E, int r,
                               long long INF = 100000000000) {
  vector<long long> cost_to(V, INF);
  cost_to[r] = 0;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < E; j++) {
      edge e = edges[j];
      if (cost_to[e.from] == INF) continue;
      if (cost_to[e.to] > cost_to[e.from] + e.cost) {
        cost_to[e.to] = cost_to[e.from] + e.cost;
        if (i == V - 1) {
          printf("NEGATIVE CYCLE\n");
          return {};
        }
      }
    }
  }
  return cost_to;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
template <class T>
inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chmax(T& a, T b) {
  if (a < b) a = b;
}
vector<int> cnt;
void dfs(const vector<vector<int>>& G, int v, int p) {
  for (auto nv : G[v]) {
    if (nv == p) continue;
    dfs(G, nv, v);
  }
  cnt[v] = 1;
  for (auto c : G[v]) {
    if (c == p) continue;
    cnt[v] += cnt[c];
  }
}
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  priority_queue<vector<long long>> que;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      auto t = A[i];
      que.push({abs(i - j) * A[i], abs(i - j), i, j});
    }
  }
  long long ans = 0;
  int cnt = N;
  vector<int> from(N, 0), to(N, 0);
  while (cnt != 0) {
    auto t = que.top();
    que.pop();
    if (from[t[2]] || to[t[3]]) continue;
    from[t[2]]++;
    to[t[3]]++;
    cnt--;
    ans += t[0];
  }
  cout << ans << endl;
}
