#include <bits/stdc++.h>
using namespace std;
bool used1[2001], used2[2001];
int A[2001];
priority_queue<tuple<long long, int, int, int>> pq;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      pq.push({(long long)A[i] * abs(i - j), -A[i], i, j});
  long long ans = 0, cnt = 0;
  while (pq.size()) {
    auto cur = pq.top();
    pq.pop();
    if (used1[get<2>(cur)] || used2[get<3>(cur)]) continue;
    ans += get<0>(cur);
    used1[get<2>(cur)] = 1;
    used2[get<3>(cur)] = 1;
    if (++cnt == N) break;
  }
  cout << ans << '\n';
  return 0;
}
