#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int *a = new int[n + 1];
  vector<bool> c(n + 1, false);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int min = 1;
  int max = n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int k = 0;
    bool flag = false;
    long long c_max = 0;
    for (int j = 1; j <= n; j++) {
      if (c[j] == true) continue;
      if (abs(j - min) < abs(j - max)) {
        if (c_max < (long long)a[j] * abs(j - max)) {
          c_max = (long long)a[j] * abs(j - max);
          flag = true;
          k = j;
        }
      } else {
        if (c_max < (long long)a[j] * abs(j - min)) {
          c_max = (long long)a[j] * abs(j - min);
          flag = false;
          k = j;
        }
      }
    }
    sum += c_max;
    if (flag == true) max--;
    if (flag == false) min++;
    c[k] = true;
  }
  cout << sum << endl;
}
