#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
int SIZE(const T (&t)[N]) {
  return N;
}
template <typename T>
int SIZE(const T &t) {
  return t.size();
}
string to_string(const string s, int x1 = 0, int x2 = 1e9) {
  return x1 < int(s.size()) ? s.substr(x1, x2 - x1 + 1) : "";
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(const bool b) { return b ? "true" : "false"; }
string to_string(const char c) { return string({c}); }
template <size_t N>
string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) {
  string t = "";
  for (int s = min(x1, SIZE(b)), e = min(x2, SIZE(b) - 1); s <= e; ++s) {
    t += b[s] + '0';
  }
  return t;
}
template <typename T, typename... E>
string to_string(const T(&v), int x1 = 0, int x2 = 1e9, E... rem);
template <typename T, typename E>
string to_string(const pair<T, E> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T, typename... E>
string to_string(const T(&v), int x1, int x2, E... rem) {
  string res = "[";
  bool first = true;
  x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
  auto l = begin(v);
  advance(l, x1);
  auto r = l;
  advance(r, (x2 - x1) + (x2 < SIZE(v)));
  for (auto e = l; e != r; e = next(e), first = false) {
    if (!first) {
      res += ", ";
    }
    res += to_string(*e, rem...);
  }
  res += "]";
  return res;
}
void dbgm() { ; }
template <typename T, typename... E>
void dbgm(T t, E... e) {
  cout << to_string(t) << ", ";
  dbgm(e...);
}
const int nax = 2005;
vector<long long> a(nax);
class comp {
 public:
  bool operator()(const pair<int, int> &px, const pair<int, int> &py) {
    long long xv = a[px.first] * abs(px.first - px.second);
    long long yv = a[py.first] * abs(py.first - py.second);
    return xv < yv;
  }
};
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, comp> pq;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      pq.push({i, j});
    }
  }
  long long rs = 0;
  vector<bool> vis(n, false);
  vector<bool> vis2(n, false);
  while (!pq.empty()) {
    pair<int, int> p = pq.top();
    pq.pop();
    if (vis[p.first] || vis2[p.second]) continue;
    vis[p.first] = true;
    vis2[p.second] = true;
    long long v = a[p.first] * abs(p.first - p.second);
    rs += v;
  }
  printf("%lld\n", rs);
}
