#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  a %= 1000000007;
  if (n == 1) return a;
  if (n == 0) return 1;
  if (n % 2)
    return (a * (power((a * a) % 1000000007, n / 2) % 1000000007)) % 1000000007;
  return power((a * a) % 1000000007, n / 2) % 1000000007;
}
const long long inf = (long long)1e18;
long long inverse(long long x) { return power(x, 1000000007 - 2) % 1000000007; }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, ans = 0;
  cin >> n;
  vector<long long> v(n + 5), used(n + 5);
  for (long long i = 1; i < n + 1; ++i) cin >> v[i];
  long long i1 = 1, i2 = n;
  for (long long i = 1; i < n / 2 + 1; ++i) {
    vector<pair<long long, long long> > x, y;
    for (long long i = 1; i < n + 1; ++i)
      if (!used[i]) x.push_back({abs(i - i1) * v[i], i});
    for (long long i = 1; i < n + 1; ++i)
      if (!used[i]) y.push_back({abs(i - i2) * v[i], i});
    sort(x.begin(), x.end(), greater<pair<long long, long long> >());
    sort(y.begin(), y.end(), greater<pair<long long, long long> >());
    ans += x[0].first + y[0].first;
    used[x[0].second] = used[y[0].second] = 1;
    i1++;
    i2--;
  }
  cout << ans << "\n";
  return 0;
}
