#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
signed main() {
  long long n;
  cin >> n;
  vector<long long> v(n + 1, 0);
  set<long long> s;
  for (long long i = 1; i < n + 1; i++) {
    cin >> v[i];
    s.insert(i);
  }
  vector<long long> vis(n + 1, 0);
  long long ans = 0;
  while (!s.empty()) {
    long long temp = 0;
    long long ind = -1;
    long long pos = -1;
    for (long long i = 1; i <= n; i++) {
      if (!vis[i]) {
        long long t = 0;
        long long in = -1;
        for (auto x : s) {
          long long a = v[i] * abs(i - x);
          if (a >= t) {
            t = a;
            in = x;
          }
        }
        if (t >= temp) {
          temp = t;
          ind = in;
          pos = i;
        }
      }
    }
    ans += temp;
    vis[pos] = 1;
    s.erase(ind);
  }
  cout << ans;
}
