#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);
  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++) {
      g[i][j] = num[i] * abs(i - j);
    }
  }
  vector<int> seen(n, 0);
  vector<int> seen2(n, 0);
  long long ans = 0;
  int k = 0;
  int l, r;
  while (k < n) {
    long long maxi = 0;
    for (long long i = 0; i < n; i++) {
      if (seen[i] == 1) {
        continue;
      }
      for (long long j = 0; j < n; j++) {
        if (seen2[j] == 0) {
          if (maxi < g[i][j]) {
            maxi = g[i][j];
            l = i;
            r = j;
          }
        }
      }
    }
    seen[l] = 1;
    seen2[r] = 1;
    ans += maxi;
    k++;
  }
  cout << ans << endl;
  return 0;
}
