#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<bool> flag_i;
vector<bool> flag_j;
ll n;
ll search_max(vector<vector<ll>> matrix) {
  ll max = -1;
  int x, y;
  for (long long i = 0; i < (n); ++i) {
    if (flag_i[i]) continue;
    for (long long j = 0; j < (n); ++j) {
      if (flag_j[j]) continue;
      if (matrix[i][j] > max) {
        max = matrix[i][j];
        x = i;
        y = j;
      }
    }
  }
  flag_i[x] = true;
  flag_j[y] = true;
  return max;
}
int main() {
  cin >> n;
  vector<ll> v(n);
  for (long long i = 0; i < (n); ++i) {
    cin >> v[i];
  }
  vector<vector<ll>> matrix(n, vector<ll>(n));
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (n); ++j) {
      matrix[i][j] = abs(i - j) * v[j];
    }
  }
  flag_i.resize(n);
  flag_j.resize(n);
  ll ans = 0;
  for (long long i = 0; i < (n); ++i) {
    ans += search_max(matrix);
  }
  cout << (ans) << endl;
  ;
  return 0;
}
