#include <bits/stdc++.h>
using namespace std;
long long A[2000];
bool done[2000];
map<long long, int> counts;
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (counts.find(A[i]) != counts.end()) {
      counts[A[i]]++;
    } else {
      counts[A[i]] = 1;
    }
  }
  priority_queue<pair<long long, pair<long long, int> > > pq;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      pq.push(make_pair(A[i] * abs(i - j), make_pair(A[i], j)));
    }
  }
  long long ans = 0;
  map<long long, int> done_counts;
  while (!pq.empty()) {
    long long cur = pq.top().first;
    long long cur_a = pq.top().second.first;
    int cur_ind = pq.top().second.second;
    pq.pop();
    if (!done[cur_ind]) {
      if (done_counts.find(cur_a) == done_counts.end() ||
          done_counts[cur_a] < counts[cur_a]) {
        ans += cur;
        if (done_counts.find(cur_a) == done_counts.end()) {
          done_counts[cur_a] = 1;
        } else {
          done_counts[cur_a]++;
        }
        done[cur_ind] = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
