#include <bits/stdc++.h>
using namespace std;
long long MOD = (1e9) + 7;
const long long N = 1000005;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc = 1;
  for (long long ti = 1; ti <= tc; ti++) {
    long long n;
    cin >> n;
    long long a[n], ok[n];
    for (long long i = 0; i < n; i++) cin >> a[i], ok[i] = 1;
    long long l = 0, r = n - 1, ans = 0;
    long long arr[n];
    while (l <= r) {
      long long f = -1, fid = -1;
      for (long long i = 0; i < n; i++) {
        if (!ok[i]) continue;
        long long chk = a[i] * abs(i - l);
        if (f < chk) f = chk, fid = i;
      }
      long long b = -1, bid = -1;
      for (long long i = 0; i < n; i++) {
        if (!ok[i]) continue;
        long long chk = a[i] * abs(i - r);
        if (b < chk) b = chk, bid = i;
      }
      if (f >= b) {
        ans += f;
        ok[fid] = 0;
        arr[l++] = a[fid];
      } else {
        ans += b;
        ok[bid] = 0;
        arr[r--] = a[bid];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
