#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
  return is;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> p) {
  cout << '(' << p.first << ", " << p.second << ')';
  return os;
}
template <class T>
void print(const vector<T> &v, const string &delimiter) {
  for (int i = 0; i < (int)(v.size()); i++)
    cout << (0 < i ? delimiter : "") << v.at(i);
  cout << endl;
}
template <class T>
void print(const vector<vector<T>> &vv, const string &delimiter) {
  for (const auto &v : vv) print(v, delimiter);
}
const double PI = acos(-1.0);
struct Edge {
  int from, to;
  ll weight;
};
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;
  vector<Edge> es(n * n);
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) {
      es.push_back(Edge{i, j, a[i] * abs(i - j)});
    }
  sort(es.rbegin(), es.rend(),
       [](Edge a, Edge b) { return a.weight < b.weight; });
  ll ans = 0;
  vector<bool> a_used(n), b_used(n);
  for (const Edge &e : es) {
    if (a_used[e.from] || b_used[e.to]) continue;
    ans += e.weight;
    a_used[e.from] = true;
    b_used[e.to] = true;
  }
  cout << ans << endl;
}
