#include <bits/stdc++.h>
using namespace std;
using large = long long;
int main() {
  int n;
  cin >> n;
  auto a = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  auto grid = vector<vector<int>>(n, vector<int>(n));
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      grid[x][y] = a[x] * abs(x - y);
    }
  }
  auto indices = vector<int>(n, -1);
  for (int y = 0; y + 1 < n; y++) {
    int maxval = INT_MIN;
    int maxind = -1;
    for (int x = 0; x < n; x++) {
      if (indices[x] >= 0) continue;
      auto s = grid[x][y] - grid[x][y + 1];
      if (s >= maxval) {
        maxval = s;
        maxind = x;
      }
    }
    indices[maxind] = y;
  }
  for (int x = 0; x < n; x++)
    if (indices[x] < 0) indices[x] = n - 1;
  auto sum = 0LL;
  for (int x = 0; x < n; x++) {
    sum += grid[x][indices[x]];
  }
  cout << sum;
  return 0;
}
