#include <bits/stdc++.h>
using namespace std;
template <class T>
struct Edge {
  int s, t;
  T c;
  Edge(int x, T y) : s(-1), t(x), c(y) {}
  Edge(int x, int y, T z) : s(x), t(y), c(z) {}
};
template <class T>
using Edges = vector<Edge<T>>;
template <class T>
using Graph = vector<Edges<T>>;
using ll = long long;
template <class t, class u>
bool chmax(t &a, u b) {
  if (a < b) a = b;
  return a < b;
}
template <class t, class u>
bool chmin(t &a, u b) {
  if (b < a) a = b;
  return b < a;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
ll readl(void) {
  ll x;
  cin >> x;
  return x;
}
int readi(void) {
  int x;
  cin >> x;
  return x;
}
string readstr() {
  string s;
  cin >> s;
  return s;
}
vi readvi(int n, int off = 0) {
  vi v(n);
  for (int i = int(0); i < int(n); i++) v[i] = readi(), v[i] += off;
  return v;
}
vl readvl(int n, int off = 0) {
  vl v(n);
  for (int i = int(0); i < int(n); i++) v[i] = readl(), v[i] += off;
  return v;
}
template <class t>
void print(t x, int suc = 1) {
  cout << x;
  if (suc == 1) cout << "\n";
  if (suc == 2) cout << " ";
}
template <class t>
void print(const vc<t> &v, int suc = 1) {
  for (int i = int(0); i < int(int(v.size())); i++)
    print(v[i], i == int(int(v.size())) - 1 ? 1 : suc);
}
template <class t>
bool inc(t a, t b, t c) {
  return !(c < b || b < a);
}
template <class t>
void compress(vc<t> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class t>
int lwb(const vc<t> &v, const t &a) {
  return lower_bound(v.begin(), v.end(), a) - v.begin();
}
template <class t>
struct Compress {
  vc<t> v;
  Compress() = default;
  Compress(const vc<t> &x) { add(x); }
  Compress(const initializer_list<vc<t>> &x) {
    for (auto &p : x) add(p);
  }
  void add(const t &x) { v.emplace_back(x); }
  void add(const vc<t> &x) { copy(x.begin(), x.end(), back_inserter(v)); }
  void build() { compress(v); }
  int get(const t &x) const { return lwb(v, x); }
  vc<t> get(const vc<t> &x) const {
    vc<t> res(x);
    for (auto &p : res) p = get(p);
    return res;
  }
  const t &operator[](int x) const { return v[x]; }
};
void Yes(bool ex = true) {
  cout << "Yes\n";
  if (ex) exit(0);
}
void YES(bool ex = true) {
  cout << "YES\n";
  if (ex) exit(0);
}
void No(bool ex = true) {
  cout << "No\n";
  if (ex) exit(0);
}
void NO(bool ex = true) {
  cout << "NO\n";
  if (ex) exit(0);
}
void orYes(bool x, bool ex = true) {
  if (x)
    Yes(ex);
  else
    No(ex);
}
void orYES(bool x, bool ex = true) {
  if (x)
    YES(ex);
  else
    NO(ex);
}
void Possible(bool ex = true) {
  cout << "Possible\n";
  if (ex) exit(0);
}
void POSSIBLE(bool ex = true) {
  cout << "POSSIBLE\n";
  if (ex) exit(0);
}
void Impossible(bool ex = true) {
  cout << "Impossible\n";
  if (ex) exit(0);
}
void IMPOSSIBLE(bool ex = true) {
  cout << "IMPOSSIBLE\n";
  if (ex) exit(0);
}
void orPossible(bool x, bool ex = true) {
  if (x)
    Possible(ex);
  else
    Impossible(ex);
}
void orPOSSIBLE(bool x, bool ex = true) {
  if (x)
    POSSIBLE(ex);
  else
    IMPOSSIBLE(ex);
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n = readi();
  vc<pl> a(n);
  for (int i = int(0); i < int(n); i++) {
    a[i] = make_pair(readl(), i);
  }
  for (int i = int(0); i < int(n); i++) {
    for (int j = int(0); j < int(n - 1); j++) {
      if (a[j].first * abs(ll(j - a[j].second)) +
              a[j + 1].first * abs(ll(j + 1 - a[j + 1].second)) <
          a[j].first * abs(ll(j + 1 - a[j].second)) +
              a[j + 1].first * abs(ll(j - a[j + 1].second)))
        swap(a[j], a[j + 1]);
    }
  }
  ll ans = 0;
  for (int i = int(0); i < int(n); i++) {
    ans += a[i].first * abs(ll(i - a[i].second));
  }
  print(ans);
}
