#include <bits/stdc++.h>
using namespace std;
set<long long> s;
const long long maxn = 2e3 + 10;
long long raw[maxn];
bool vis[maxn];
signed main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> raw[i];
    s.insert(i);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long L = *s.begin(), R = *s.rbegin();
    long long M = -1, idx = 0, d = -1;
    for (long long j = 1; j <= n; j++)
      if (!vis[j]) {
        if (j - L > R - j) {
          if (M < (j - L) * raw[j]) {
            M = (j - L) * raw[j];
            idx = j, d = L;
          }
        } else {
          if (M < (R - j) * raw[j]) {
            M = (R - j) * raw[j];
            idx = j, d = R;
          }
        }
      }
    ans += M;
    vis[idx] = 1;
    s.erase(d);
  }
  cout << ans << endl;
  return 0;
}
