#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 201001;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> vec(n, 0);
  for (long long int d = 0; d < n; d++) {
    cin >> vec[d];
  }
  long long int l = 0, r = n - 1;
  long long int ans = 0;
  for (long long int d = 0; d < n; d++) {
    long long int best = 0, rem = 0, st = 0;
    for (long long int i = 0; i < n; i++) {
      if (abs(i - l) * vec[i] > best) {
        best = abs(i - l) * vec[i];
        rem = i;
        st = 0;
      }
      if (abs(i - r) * vec[i] > best) {
        best = abs(i - r) * vec[i];
        rem = i;
        st = 1;
      }
    }
    ans += best;
    if (st == 0) {
      l++;
    } else {
      r--;
    }
    vec[rem] = 0;
  }
  cout << ans;
}
