#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
pair<long long, long long> p[2005];
long long cost(long long x, long long y) {
  return p[y].first * abs(x - p[y].second);
}
bool cmp(long long i, long long j) {
  return cost(j, i) + cost(i, j) > cost(i, i) + cost(j, j);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, x;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    p[i] = make_pair(x, i);
  }
  for (long long k = 0; k < 5; k++)
    for (long long i = 1; i < n; i++) {
      for (long long j = 1; j < n; j++) {
        if (cmp(j, j + 1)) {
          swap(p[j], p[j + 1]);
        }
      }
    }
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    ans = ans + p[i].first * abs(i - p[i].second);
  cout << ans << '\n';
  return 0;
}
