#include <bits/stdc++.h>
using namespace std;
const long long int INF = LONG_LONG_MAX;
const long long int NINF = LONG_LONG_MIN / 2;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int& x : a) cin >> x;
  long long int l = 0;
  long long int r = n - 1;
  long long int ans = 0;
  vector<long long int> done(n, 0);
  while (l <= r) {
    long long int pos = 0;
    long long int mx = 0;
    bool left = true;
    for (long long int i = 0; i < n; i++) {
      if (!done[i]) {
        long long int c1 = a[i] * abs(i - l);
        long long int c2 = a[i] * abs(i - r);
        if (c1 > c2) {
          if (c1 > mx) {
            left = true;
            pos = i;
            mx = c1;
          }
        } else {
          if (c2 > mx) {
            pos = i;
            left = false;
            mx = c2;
          }
        }
      }
    }
    if (left) {
      l++;
      ans += mx;
    } else {
      r--;
      ans += mx;
    }
    done[pos] = true;
  }
  cout << ans << endl;
}
