#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
int const inf = 1e9;
long long const INF = 1e18;
inline void ios_() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template <typename T>
int size(const T& a) {
  return (int)a.size();
}
template <typename T>
T Div(T a, T b) {
  return (a + b - 1) / b;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (auto&& i : v) cin >> i;
  vector<bool> used(n, false);
  long long ans = 0;
  int left = 0, right = n - 1;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long score = -1;
    int p = 0;
    for (int(j) = 0; (j) < (n); (j)++) {
      if (used[j]) continue;
      long long l = abs(j - left) * v[j], r = abs(right - j) * v[j];
      if (chmax(score, max(l, r))) {
        p = j;
      }
    }
    long long l = abs(p - left) * v[p], r = abs(right - p) * v[p];
    if (l > r) {
      ans += l;
      left++;
    } else if (l < r) {
      ans += r;
      right--;
    } else {
      if (v[left] > v[right]) {
        ans += l;
        left++;
      } else {
        ans += r;
        right--;
      }
    }
    used[p] = true;
  }
  cout << ans << endl;
  return 0;
}
