#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
long long a[100010];
bool vis[5000];
bool v[5000];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  long long n, m, k, r, x, y;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 0; i <= n / 2; i++) {
    long long m = 0;
    long long ple;
    for (long long j = 0; j < n; j++) {
      if (!vis[j]) {
        if (m < a[j] * (max(i, j) - min(i, j)))
          m = a[j] * (max(i, j) - min(i, j)), ple = j;
        else if (m == a[j] * (max(i, j) - min(i, j))) {
          if ((max(i, j) - min(i, j)) > (max(i, ple) - min(i, ple)))
            m = a[j] * (max(i, j) - min(i, j)), ple = j;
        }
      }
    }
    v[i] = true;
    vis[ple] = true;
    ans += m;
    m = 0;
    for (long long j = 0; j < n; j++) {
      if (!vis[j]) {
        if (m < a[j] * (max(n - i - 1, j) - min(n - i - 1, j)))
          m = a[j] * (max(n - i - 1, j) - min(n - i - 1, j)), ple = j;
        else if (m == a[j] * (max(n - i - 1, j) - min(n - i - 1, j))) {
          if ((max(n - i - 1, j) - min(n - i - 1, j)) >
              (max(n - i - 1, ple) - min(n - i - 1, ple)))
            m = a[j] * (max(n - i - 1, j) - min(n - i - 1, j)), ple = j;
        }
      }
    }
    if (v[n - i - 1]) m = 0;
    v[n - i - 1] = true;
    vis[ple] = true;
    ans += m;
  }
  cout << ans << '\n';
  return (0);
}
