#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma optimize("fast-math")
using namespace std;
long long table[2000][2000];
void solve() {
  int n;
  cin >> n;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      table[j][i] = arr[i] * abs(i - j);
    }
  }
  int l = 0;
  int r = n - 1;
  vector<int> was(n, false);
  long long summ = 0;
  while (r >= l) {
    long long mx = -1;
    int ind = -1;
    for (int i = 0; i < n; i++) {
      if (was[i]) continue;
      if (table[l][i] > mx) {
        ind = i;
        mx = table[l][i];
      }
    }
    long long m1 = -1;
    int ind2 = -1;
    for (int i = 0; i < n; i++) {
      if (was[i]) continue;
      if (table[r][i] > m1) {
        ind2 = i;
        m1 = table[r][i];
      }
    }
    if (m1 >= mx) {
      summ += table[r][ind2];
      was[ind2] = true;
      r--;
    } else {
      summ += table[l][ind];
      was[ind] = true;
      l++;
    }
  }
  cout << summ;
}
void testcases(int n) {
  n = 1 - n;
  if (!n) cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  unsigned int beg_time = clock();
  testcases(0);
  unsigned int end_time = clock();
  return 0;
}
