#include <bits/stdc++.h>
using namespace std;
long long n, t1, a, wynik, maxl, maxp, x, suma, licz;
pair<pair<long long, long long>, long long> t[1000002];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  maxp = n;
  maxl = 1;
  for (int i = 1; i <= n; i++) {
    cin >> t[i].first.second;
    t[i].first.second *= -1;
    t[i].second = i;
    t[i].first.first = t[i].first.second *
                       max(abs(t[i].second - maxp), abs(t[i].second - maxl)) *
                       -1;
    ;
  }
  for (int i = 1; i <= n; i++) {
    sort(t + 1, t + 1 + n);
    wynik += t[n].first.first;
    if (abs(t[n].second - maxl) > abs(t[n].second - maxp))
      maxl++;
    else
      maxp--;
    t[n].first.first = t[n].first.second = t[n].second = 0;
    for (int i = 1; i <= n; i++)
      t[i].first.first = t[i].first.second *
                         max(abs(t[i].second - maxp), abs(t[i].second - maxl)) *
                         -1;
  }
  cout << wynik << endl;
}
