#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n;
  cin >> n;
  pair<long long int, long long int> a[n];
  map<long long int, long long int> vis;
  map<long long int, long long int> done;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  long long int ans = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    if (done[i]) break;
    vector<pair<long long int, long long int> > temp;
    for (long long int j = 0; j < n; j++) {
      if (vis[j] == 0) {
        temp.push_back({abs(j - i) * a[j].first, j});
      }
    }
    long long int i1 = n - i - 1;
    if (i1 != i) {
      for (long long int j = 0; j < n; j++) {
        if (vis[j] == 0) {
          temp.push_back({abs(j - i1) * a[j].first, -j - 1});
        }
      }
    }
    sort(temp.begin(), temp.end(),
         greater<pair<long long int, long long int> >());
    map<long long int, long long int> m;
    for (long long int j = 0; j < temp.size(); j++) {
      if (m[i] == 1 && m[i1] == 1)
        break;
      else {
        if (m[i1] == 0 && temp[j].second < 0 && vis[-temp[j].second - 1] == 0) {
          m[i1]++;
          ans += temp[j].first;
          vis[-temp[j].second - 1]++;
        }
        if (m[i] == 0 && temp[j].second >= 0 && vis[temp[j].second] == 0) {
          m[i]++;
          ans += temp[j].first;
          vis[temp[j].second]++;
        }
      }
    }
    m.clear();
    done[i]++, done[i1]++;
  }
  cout << ans << '\n';
  return 0;
}
