#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &x : v) in >> x;
  return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
  out << "[" << p.first << ", " << p.second << "]"
      << "\n";
  return out;
}
template <class T1, class T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  cin >> A;
  vector<vector<long long>> B(N, vector<long long>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      B[i][j] = A[i] * abs(j - i);
    }
  }
  vector<long long> row(N, 0);
  vector<long long> column(N, 0);
  vector<tuple<long long, long long, long long, long long, long long>> C;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      C.push_back(make_tuple(B[i][j], -A[i], -abs(j - i), i, j));
    }
  }
  sort((C).rbegin(), (C).rend());
  long long ans = 0;
  for (auto c : C) {
    long long val, y, x, _, __;
    tie(val, _, __, y, x) = c;
    if (!row[y] and !column[x]) {
      ans += val;
      row[y] = 1;
      column[x] = 1;
    }
  }
  cout << ans << endl;
}
