#include <bits/stdc++.h>
using namespace std;
const long long N = 200007;
map<long long, long long> mp;
void scan(long long &n) { scanf("%lld", &n); }
void scan(long long &n, long long &m) { scanf("%lld%lld", &n, &m); }
void scan(vector<long long> &v) {
  long long n = v.size();
  for (long long i = 1; i < n; i++) {
    scanf("%lld", &v[i]);
    mp[v[i]]++;
  }
}
vector<long long> adj[N];
long long vis[N], lvl[N], lvl1[N], vis1[N];
void edge(long long u, long long v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
long long mod = 1000000007;
bool cmp(pair<pair<long long, long long>, pair<long long, long long> > &x,
         pair<pair<long long, long long>, pair<long long, long long> > &y) {
  if (x.first.first == y.first.first) return x.first.second <= y.first.second;
  return x.first.first <= y.first.first;
}
int main() {
  long long n;
  scanf("%lld", &n);
  long long i, j;
  vector<long long> v(n);
  for (i = 0; i < n; i++) scanf("%lld", &v[i]);
  vector<pair<pair<long long, long long>, pair<long long, long long> > > p;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      long long k = abs(i - j) * v[i];
      p.push_back({{k, v[i]}, {i, j}});
    }
  }
  sort(p.rbegin(), p.rend(), cmp);
  map<long long, long long> mp, mp1;
  long long ans = 0;
  for (auto it : p) {
    long long x = it.second.first;
    long long y = it.second.second;
    if (mp[x] == 0 and mp1[y] == 0) {
      mp[x] = 1;
      mp1[y] = 1;
      ans += it.first.first;
    }
  }
  cout << ans << endl;
  return 0;
}
