#include <bits/stdc++.h>
using namespace std;
long long n;
void solve() {
  cin >> n;
  vector<long long> a(n);
  vector<bool> used(n), useda(n);
  for (long long i = 0; i < (long long)n; ++i) cin >> a[i];
  long long ans = 0;
  for (long long step = 0; step < (long long)n; ++step) {
    long long fst = -1, lst = -1;
    for (long long i = 0; i < (long long)n; ++i) {
      if (!used[i]) {
        if (fst == -1) fst = i;
        lst = i;
      }
    }
    long long ind = -1;
    for (long long i = 0; i < (long long)n; ++i) {
      if (useda[i]) continue;
      if (ind == -1 ||
          max(i - fst, lst - i) * a[i] > max(ind - fst, lst - ind) * a[ind])
        ind = i;
    }
    used[ind - fst > lst - ind ? fst : lst] = 1;
    useda[ind] = 1;
    ans += max(ind - fst, lst - ind) * a[ind];
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
