#include <bits/stdc++.h>
const double pi = 3.141592653589793238462643383279;
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline int readInt() {
  int x;
  scanf("%d", &x);
  return x;
}
const double EPS = 1E-8;
class UnionFind {
 public:
  vector<int> par;
  vector<int> siz;
  UnionFind(int sz_) : par(sz_), siz(sz_, 1) {
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(int sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  int size(int x) { return siz[root(x)]; }
};
long long modPow(long long x, long long n, long long mod = 1000000007) {
  if (n == 0) return 1;
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    res %= mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
bool sieve[5000000 + 10];
void makeSieve() {
  for (int i = 0; i < 5000000 + 10; ++i) sieve[i] = true;
  sieve[0] = sieve[1] = false;
  for (int i = 2; i * i < 5000000 + 10; ++i)
    if (sieve[i])
      for (int j = 2; i * j < 5000000 + 10; ++j) sieve[i * j] = false;
}
bool isprime(long long n) {
  if (n == 0 || n == 1) return false;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) return false;
  return true;
}
const int MAX = 3000010;
long long fac[MAX], finv[MAX], inv[MAX];
const long long mod2 = 998244353;
const long long mod3 = 1777777777;
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
long long modinv(long long a, long long m) {
  long long x, y;
  extGCD(a, m, x, y);
  return mod(x, m);
}
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
vector<vector<long long>> mul(vector<vector<long long>> &A,
                              vector<vector<long long>> &B) {
  vector<vector<long long>> C(A.size(), vector<long long>((int)B[0].size()));
  for (int i = 0; i < A.size(); ++i) {
    for (int k = 0; k < B.size(); ++k) {
      for (int j = 0; j < B[0].size(); ++j) {
        C[i][j] = (C[i][j] + A[i][k] % 1000000007 * B[k][j] % 1000000007) %
                  1000000007;
      }
    }
  }
  return C;
}
vector<vector<long long>> matPow(vector<vector<long long>> A, long long n) {
  vector<vector<long long>> B(A.size(), vector<long long>((int)A.size()));
  for (int i = 0; i < A.size(); ++i) {
    B[i][i] = 1;
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
template <class TYPE>
struct Fenwick {
  int N;
  vector<long long> bit;
  Fenwick() : N(0) {}
  Fenwick(int n) : N(n), bit(n + 1, 0) {}
  void add(int i, long long x) {
    while (i <= N) {
      bit[i] += x;
      i += (i & -i);
    }
  }
  long long sum(int i) {
    long long res = 0;
    while (i > 0) {
      res += bit[i];
      i -= (i & -i);
    }
    return res;
  }
  long long range(int i, int j) { return sum(j) - sum(i); }
  long long get(int i) { return sum(i) - sum(i - 1); }
  long long getKth(long long k) {
    ++k;
    int res = 0;
    int n = 1;
    while (n < bit.size()) n *= 2;
    for (int i = n / 2; i > 0; i /= 2) {
      if (res + i < bit.size() && bit[res + i] < k) {
        k = k - bit[res + i];
        res = res + i;
      }
    }
    return res + 1;
  }
};
bool used1[2010];
bool used2[2010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(4);
  int N;
  cin >> N;
  long long ans = 0;
  vector<long long> A(N);
  for (int i = 0; i < (int)N; ++i) {
    cin >> A[i];
  }
  priority_queue<pair<long long, pair<int, pair<int, int>>>> q;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      q.push(make_pair(A[i] * (long long)abs((i - j)),
                       make_pair(-A[i], make_pair(i, j))));
    }
  }
  while (q.size()) {
    auto p = q.top();
    q.pop();
    int idx1 = p.second.second.first, idx2 = p.second.second.second;
    if (used1[idx1] || used2[idx2]) continue;
    ans += p.first;
    used1[idx1] = used2[idx2] = true;
  }
  cout << ans << endl;
  return 0;
}
