#include <bits/stdc++.h>
using namespace std;
int a[2005];
bool fix[20005];
vector<pair<int, int> > v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    v.clear();
    int maxx = 0;
    for (int j = 1; j <= n; j++) {
      if (fix[j]) continue;
      v.push_back({abs(i - j) * a[j], j});
      maxx = max(maxx, abs(i - j) * a[j]);
    }
    sort(v.begin(), v.end());
    for (int j = 0; j < v.size(); j++)
      if (v[j].first == maxx) {
        fix[v[j].second] = 1;
        ans += maxx;
        break;
      }
  }
  cout << ans;
}
