#include <bits/stdc++.h>
const int maxn = 2005;
int n, head, tail;
long long ans, a[maxn];
int match[maxn];
std::queue<int> q;
std::priority_queue<std::pair<long long, int> > Q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    q.push(i);
  }
  while (!q.empty()) {
    long long maxx = -1, maxn, to = 0;
    for (int i = 1; i <= n; ++i) {
      if (!match[i] && std::abs(q.front() - i) * a[q.front()] > maxx) {
        maxx = std::abs(q.front() - i) * a[q.front()];
        maxn = i;
        to = 0;
      }
      if (match[i] && std::abs(match[i] - i) * a[match[i]] <
                          std::abs(q.front() - i) * a[q.front()]) {
        maxx = std::abs(q.front() - i) * a[q.front()];
        maxn = i;
        to = match[i];
      }
    }
    match[maxn] = q.front();
    if (to) q.push(to);
    q.pop();
  }
  for (int i = 1; i <= n; ++i) ans += std::abs(match[i] - i) * a[match[i]];
  printf("%lld", ans);
}
