#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int ma = n - 1, mi = 0;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    map<int, int> m;
    vector<int> li(n + 1);
    int maxi = INT_MIN;
    for (int j = 0; j < n; j++) {
      if (v[j] == -1) continue;
      int temp1 = abs(j - ma) * v[j];
      int temp2 = abs(j - mi) * v[j];
      if (temp1 > temp2) {
        li[j] = 1;
        if (m[temp1] == 0) m[temp1] = j;
        maxi = max(maxi, temp1);
      } else {
        li[j] = 0;
        if (m[temp2] == 0) m[temp2] = j;
        maxi = max(maxi, temp2);
      }
    }
    int cor = m[maxi];
    if (li[cor] == 0)
      mi++;
    else
      ma--;
    v[cor] = -1;
    ans += maxi;
    m.clear();
    li.clear();
  }
  cout << ans;
}
