#include <bits/stdc++.h>
using namespace std;
int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};
long long POWLL(long long x, int n) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};
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;
};
const long long INF = 1ll << 60;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<long long> A(N);
  vector<int> pos(N);
  for (int i = (int)0; i < (int)N; i++) {
    cin >> A[i];
    pos[i] = i;
  }
  long long ans = 0;
  long long l = 0, r = N - 1;
  set<int> s;
  while (s.size() < N) {
    int id;
    long long pos;
    long long tmp = -INF;
    for (int i = (int)0; i < (int)N; i++) {
      if (s.find(i) != s.end()) continue;
      long long a = A[i];
      long long l_score = a * abs(i - l);
      long long r_score = a * abs(r - i);
      if (l_score > r_score) {
        if (l_score > tmp) {
          pos = 0;
          tmp = l_score;
          id = i;
        }
      } else {
        if (r_score > tmp) {
          pos = 1;
          tmp = r_score;
          id = i;
        }
      }
    }
    s.insert(id);
    ans += tmp;
    if (pos) {
      r--;
    } else {
      l++;
    }
  }
  cout << ans << "\n";
  return 0;
};
