#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (n); i++) cin >> a[i];
  long long res = 0;
  vector<bool> used(n, false);
  for (long long i = 0; i < (n + 1) / 2; i++) {
    long long tmp = 0, who = -1;
    for (long long j = i + 1; j < n; j++) {
      if (used[j]) continue;
      if (tmp <= abs(j - i) * a[j]) {
        tmp = abs(j - i) * a[j];
        who = j;
      }
    }
    used[who] = true;
    res += tmp;
    tmp = 0;
    if (n % 2 == 1 && i == (n - 1) / 2) continue;
    for (long long j = n - i - 2; j >= 0; j--) {
      if (used[j]) continue;
      if (tmp <= abs(j - (n - 1 - i)) * a[j]) {
        tmp = abs(j - (n - 1 - i)) * a[j];
        who = j;
      }
    }
    used[who] = true;
    res += tmp;
  }
  cout << res << endl;
  return 0;
}
