#include <bits/stdc++.h>
using namespace std;
void perform() {
  int n;
  cin >> n;
  vector<pair<double, pair<int, int>>> v;
  for (long long((i)) = (0); ((i)) < ((n)); ((i))++) {
    int t;
    cin >> t;
    double x = (((double)i) > (n - i) ? ((double)i) : (n - i));
    v.push_back(make_pair(t * x, make_pair(t, i)));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  vector<int> ans(n);
  int first = 0, last = n - 1;
  int sum = 0;
  for (auto i : v) {
    int one = fabs(i.second.second - first);
    int two = fabs(i.second.second - last);
    if (one > two) {
      ans[first] = i.second.first;
      sum += one * i.second.first;
      first++;
    } else if (one < two) {
      ans[last] = i.second.first;
      sum += two * i.second.first;
      last--;
    } else {
      if (first > n - 1 - last) {
        ans[last] = i.second.first;
        sum += two * i.second.first;
        last--;
      } else {
        ans[first] = i.second.first;
        sum += one * i.second.first;
        first++;
      }
    }
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long((i)) = (0); ((i)) < ((t)); ((i))++) {
    perform();
  }
}
