#include <bits/stdc++.h>
using namespace std;
const long long N = 500005;
const long long mod = 1e9 + 7;
void solve() {
  long long x = 0, y = 0, c = 1, ans = 0;
  long long n, m, k, l = 0, r, i;
  cin >> n;
  long long a[n];
  vector<bool> vis(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  r = n - 1;
  while (l <= r) {
    x = 0;
    if (c) {
      i = l;
      l++;
    } else {
      i = r;
      r--;
    }
    for (long long j = 0; j < n; ++j) {
      if (!vis[j] and x < a[j] * abs(j - i)) {
        x = a[j] * abs(j - i);
        y = j;
      }
    }
    ans += x;
    vis[y] = 1;
    c ^= 1;
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
