#include <bits/stdc++.h>
using namespace std;
int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};
long long POWLL(long long x, int n) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
const long long INF = 1ll << 60;
class POS {
 public:
  long long happy, a;
  int pos, id;
  POS() {}
  POS(long long happy, long long a, int pos, int id)
      : happy(happy), a(a), pos(pos), id(id) {}
  bool operator<(const POS &p) const { return happy < p.happy; }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<long long> A(N);
  priority_queue<POS> pq;
  for (int i = (int)0; i < (int)N; i++) {
    cin >> A[i];
    for (int j = (int)0; j < (int)N; j++) {
      long long happy = A[i] * abs<long long>(j - i);
      POS tmp = POS(happy, A[i], j, i);
      pq.push(tmp);
    }
  }
  vector<int> ANS(N, -1);
  set<int> s;
  while (!pq.empty()) {
    auto u = pq.top();
    pq.pop();
    if (ANS[u.pos] != -1 || s.find(u.id) != s.end()) continue;
    s.insert(u.id);
    ANS[u.pos] = u.id;
  }
  long long ans = 0;
  for (int i = (int)0; i < (int)N; i++) {
    long long id = ANS[i];
    ans += A[id] * abs(id - (long long)i);
  }
  cout << ans << "\n";
  return 0;
};
