#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n], ans = 0;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long b[n][n];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      b[i][j] = abs(i - j) * a[i];
    }
  }
  for (long long k = 0; k < n; k++) {
    long long max = 0, x, y;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        if (max < b[i][j]) {
          max = b[i][j];
          x = i;
          y = j;
        }
      }
    }
    ans = ans + max;
    for (long long i = 0; i < n; i++) b[x][i] = 0;
    for (long long i = 0; i < n; i++) b[i][y] = 0;
  }
  cout << ans;
  return 0;
}
