#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7, N = 2005;
long long a[N], b[N];
long long get(long long i) { return a[i] * abs(i - b[i]); }
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) b[i] = i;
  for (long long k = 0; k < 20; k++) {
    for (long long i = 0; i < n; i++) {
      for (long long j = i + 1; j < n; j++) {
        long long cur = get(i) + get(j);
        swap(b[i], b[j]);
        long long new_cur = get(i) + get(j);
        if (new_cur < cur) swap(b[i], b[j]);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) ans += get(i);
  cout << ans << endl;
}
