#include <bits/stdc++.h>
using namespace std;
const long long MOD2 = 998244353;
const long long INF = 1e18;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<vector<long long int>> lr(N, vector<long long int>(2, 0));
  for (int i = 0; i < N; i++) {
    lr[i][0] = a[i] * abs(i - 0);
    lr[i][1] = a[i] * abs(N - 1 - i);
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long M = -INF;
    long long mi = 0;
    long long mj = 0;
    long long tmp = 0;
    vector<bool> notYet(N, 1);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 2; j++) {
        if (lr[i][j] > M && notYet[i]) {
          M = lr[i][j];
          mi = i;
          mj = j;
        } else if (lr[i][j] == M && notYet[i]) {
          if (lr[i][j ^ 1] < lr[mi][mj ^ 1]) {
            M = lr[i][j];
            mi = i;
            mj = j;
          }
        } else {
        }
      }
    }
    ans += M;
    notYet[mi] = 0;
    lr[mi][0] = 0;
    lr[mi][1] = 0;
    for (int i = 0; i < N; i++) {
      if (lr[i][mj] > 0) {
        lr[i][mj] -= a[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
