#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
constexpr double EPS = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL << 60;
constexpr long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main(void) {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = (0); i < (N); ++i) cin >> A[i];
  vector<int> used(N, 0);
  long long ans = 0;
  for (int i = (0); i < (N); ++i) {
    if (i % 2) {
      long long t, mx = -1;
      for (int j = (0); j < (N); ++j) {
        if (used[j]) continue;
        if (chmax(mx, A[j] * abs(N - 1 - i / 2 - j))) t = j;
      }
      ans += mx;
      used[t] = 1;
    } else {
      long long t, mx = -1;
      for (int j = (0); j < (N); ++j) {
        if (used[j]) continue;
        if (chmax(mx, A[j] * abs(i / 2 - j))) t = j;
      }
      ans += mx;
      used[t] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
