#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T MIN(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T, typename... Args>
inline T MIN(const T &a, const T &b, Args... args) {
  return MIN(MIN(a, b), args...);
}
template <typename T, typename... Args>
inline T MAX(const T &a, const T &b, Args... args) {
  return MAX(MAX(a, b), args...);
}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
long long pos[2010], ori[2010], res;
bool vis[2010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ori[i];
  int l = 1, r = n;
  for (int tt = 1; tt <= n; tt++) {
    int i = (tt & 1 ? l : r);
    if (i == r) l++, r--;
    long long mx = -1, p = -1;
    for (int j = 1; j <= n; j++) {
      if (vis[j]) continue;
      if (ori[j] * abs(j - i) > mx) mx = ori[j] * abs(j - i), p = j;
    }
    res += mx;
    vis[p] = 1;
  }
  cout << res << '\n';
  return 0;
}
