#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> num(n);
  long long ans = 0;
  vector<tuple<long long, long long, long long>> memo;
  for (long long i = 0; i < n; i++) {
    cin >> num[i];
  }
  vector<vector<long long>> g(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      memo.push_back(make_tuple(num[i] * abs(i - j), i, j));
    }
  }
  vector<int> seeni(n, 0);
  vector<int> seenj(n, 0);
  sort((memo).begin(), (memo).end());
  reverse((memo).begin(), (memo).end());
  for (long long k = 0; k < (int)memo.size(); k++) {
    long long a, b, c;
    a = get<0>(memo[k]);
    b = get<1>(memo[k]);
    c = get<2>(memo[k]);
    if (seeni[b] == 0 && seenj[c] == 0) {
      ans += a;
      seeni[b] = 1;
      seenj[c] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
