#include <bits/stdc++.h>
using namespace std;
const long long N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;
long long n, Q;
long long arr[N + 2], vis[N];
void solve() {
  cin >> n;
  vector<pair<long long, long long> > vec;
  for (long long i = 0; i < (long long)n; i++) {
    long long x;
    cin >> x;
    vec.push_back({i, x});
  }
  long long i = 0, j = n - 1, ans = 0;
  while (i <= j) {
    pair<long long, long long> p = {-1, -1};
    for (long long k = 0; k < (long long)n; k++) {
      if (vis[k]) continue;
      long long ax = vec[k].second, id = k;
      long long mx = ax * (max(abs(id - i), abs(id - j)));
      if (mx > p.first) {
        p.first = mx;
        p.second = k;
      }
    }
    long long id = p.second, mx;
    long long ax = vec[id].second;
    if (abs(id - j) > abs(id - i))
      mx = ax * abs(id - j), j--;
    else
      mx = ax * abs(id - i), i++;
    ans += mx;
    vis[id] = 1;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) solve();
}
