#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()) {
    while (!Q.empty()) Q.pop();
    long long maxx = -1, maxn;
    for (int i = 1; i <= n; ++i)
      Q.push(std::make_pair(a[q.front()] * std::abs(i - q.front()), i));
    while (!Q.empty()) {
      if (!match[Q.top().second]) {
        match[Q.top().second] = q.front();
        break;
      } else if (std::abs(match[Q.top().second] - Q.top().second) *
                     a[match[Q.top().second]] <
                 Q.top().first) {
        q.push(match[Q.top().second]);
        match[Q.top().second] = q.front();
        break;
      }
      Q.pop();
    }
    q.pop();
  }
  for (int i = 1; i <= n; ++i) ans += std::abs(match[i] - i) * a[match[i]];
  printf("%lld", ans);
}
