#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<bool> used(n, 0);
  for (long long &x : a) cin >> x;
  long long l = 0, r = n - 1;
  long long ans = 0;
  for (long long w = 0; w < n; ++w) {
    long long j = -1, cur_ans = -1;
    bool moveleft = 0;
    for (long long i = 0; i < n; ++i) {
      if (!used[i]) {
        bool left = abs(i - l) > abs(i - r);
        long long cur = a[i] * max(abs(i - l), abs(i - r));
        if (cur > cur_ans) {
          cur_ans = cur;
          moveleft = left;
          j = i;
        }
      }
    }
    used[j] = 1;
    if (moveleft)
      ++l;
    else
      --r;
    ans += cur_ans;
  }
  cout << ans << '\n';
}
