#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  os << "(" << a.first << ", " << a.second << ")";
  return os;
}
const char newl = '\n';
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<bool> used(n, false);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int l = 0, r = n - 1;
  long long ans = 0;
  for (int z = 0; z < n; ++z) {
    pair<long long, int> x = make_pair(0, 0), y = make_pair(0, 0);
    for (int i = 0; i < n; ++i)
      if (!used[i] &&
          ((x.first < a[i] * abs(l - i)) ||
           (x.first == a[i] * abs(l - i) && abs(l - x.second) < abs(l - i)))) {
        x = make_pair(a[i] * abs(l - i), i);
      }
    for (int i = 0; i < n; ++i)
      if (!used[i] &&
          ((y.first < a[i] * abs(r - i)) ||
           (y.first == a[i] * abs(r - i) && abs(r - y.second) < abs(r - i)))) {
        y = make_pair(a[i] * abs(r - i), i);
      }
    if ((x.first > y.first) ||
        (x.first == y.first && abs(l - x.second) > abs(r - y.second))) {
      ans += x.first;
      used[x.second] = true;
      l++;
    } else {
      ans += y.first;
      used[y.second] = true;
      r--;
    }
  }
  cout << ans << endl;
}
