#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acos(-1.0);
long long qp(long long a, long long b, int mo) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <typename T>
istream &operator>>(istream &is, vector<T> &vector<long long>) {
  for (auto &v : vector<long long>) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vector<long long>) {
  os << "[";
  for (auto v : vector<long long>) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vector<long long>) {
  os << "deq[";
  for (auto v : vector<long long>) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os,
                    const unordered_multiset<T> &vector<long long>) {
  os << "{";
  for (auto v : vector<long long>) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename T>
void ndarray(vector<T> &vector<long long>, int len) {
  vector<long long>.resize(len);
}
template <typename T, typename... Args>
void ndarray(vector<T> &vector<long long>, int len, Args... args) {
  vector<long long>.resize(len);
  for (auto &v : vector<long long>) ndarray(v, args...);
}
template <typename T>
bool chmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool chmin(T &m, const T q) {
  if (q < m) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first - r.first, l.second - r.second);
}
struct child {
  long long index, origine_index, act, uresi;
};
void solve() {
  long long N;
  cin >> N;
  vector<child> kids;
  for (int i = 1; i <= N; i++) {
    child c;
    cin >> c.act;
    c.index = i;
    c.origine_index = i;
    c.uresi = 0;
    kids.push_back(c);
  }
  while (true) {
    bool flag = true;
    for (auto &kid : kids) {
      for (auto &target : kids) {
        if (kid.index == target.index) continue;
        long long if_ch = kid.act * abs(kid.origine_index - target.index) +
                          target.act * abs(kid.index - target.origine_index);
        if (if_ch > kid.uresi + target.uresi) {
          kid.uresi = kid.act * abs(kid.origine_index - target.index);
          target.uresi = target.act * abs(kid.index - target.origine_index);
          long long index = kid.index;
          kid.index = target.index;
          target.index = index;
          flag = false;
        }
      }
    }
    if (flag) break;
  }
  long long ans = 0;
  for (auto kid : kids) {
    cout << "kid" << kid.origine_index << endl;
    cout << "index: " << kid.index << endl;
    ans += kid.uresi;
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  std::cout << fixed << setprecision(10);
  solve();
  return 0;
}
