#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; ++i) cin >> A[i];
  vector<vector<long long>> X(N, vector<long long>(N));
  for (long long i = 0; i < N; ++i) {
    for (long long j = 0; j < N; ++j) {
      X[i][j] = A[i] * abs(i - j);
    }
  }
  long long ans = 0;
  for (long long k = 0; k < N; ++k) {
    long long max_v = -1;
    long long max_i = -1;
    long long max_j = -1;
    for (long long i = 0; i < X.size(); ++i) {
      for (long long j = 0; j < X[0].size(); ++j) {
        if (max_v < X[i][j]) {
          max_v = X[i][j];
          max_i = i;
          max_j = j;
        }
      }
    }
    ans += max_v;
    vector<vector<long long>> X2;
    for (long long i = 0; i < X.size(); ++i) {
      if (i != max_i) {
        vector<long long> X2_v;
        for (long long j = 0; j < X[0].size(); ++j) {
          if (j != max_j) {
            X2_v.push_back(X[i][j]);
          }
        }
        X2.push_back(X2_v);
      }
    }
    X = X2;
  }
  cout << ans << endl;
}
