#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll modu = pow(10, 9) + 7;
struct my {
  ll happy;
  ll ai;
  ll pos;
  ll from;
};
bool compare(my &m1, my &m2) {
  if (m1.happy != m2.happy) return m1.happy > m2.happy;
  return m1.ai < m2.ai;
}
vector<my> v;
int main() {
  {
    cin.sync_with_stdio(0);
    cout.sync_with_stdio(0);
  };
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      my m;
      m.happy = a[i] * abs(i - j);
      m.ai = a[i];
      m.pos = j;
      m.from = i;
      v.push_back(m);
    }
  }
  vector<bool> b(n, 0), b1(n, 0);
  ll ans = 0;
  sort(v.begin(), v.end(), compare);
  for (ll i = 0; i < v.size(); i++) {
    if (!b[v[i].pos] && !b1[v[i].from]) {
      ans += v[i].happy;
      b[v[i].pos] = 1;
      b1[v[i].from] = 1;
    }
  }
  cout << ans << endl;
}
