#include <bits/stdc++.h>
using namespace std;
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
void _F(const char* name, T arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename T, typename... Args>
void _F(const char* names, T arg1, Args... args) {
  const char* name = strchr(names, ',');
  cerr.write(names, name - names) << " = " << arg1 << '\n';
  _F(name + 2, args...);
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& q) {
  in >> q.first >> q.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& q) {
  out << q.first << " " << q.second;
  return out;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2) {
  return {p1.first + p2.first, p1.second + p2.second};
}
template <typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2) {
  return {p1.first - p2.first, p1.second - p2.second};
}
struct MinCostFlow {
  struct Edge {
    long long f;
    long long c;
    long long u;
    Edge* nex;
    Edge* rev;
    Edge(long long _u, long long _c, long long _f, Edge* _nex)
        : f(_f), u(_u), c(_c), nex(_nex) {}
  };
  vector<Edge*> g;
  MinCostFlow(long long n) { g.resize(n); }
  void AddEdge(long long v, long long u, long long c, long long f) {
    g[v] = new Edge(u, c, f, g[v]);
    g[u] = new Edge(v, -c, 0, g[u]);
    g[v]->rev = g[u];
    g[u]->rev = g[v];
  }
  pair<long long, long long> Flow(long long src, long long sink, long long n) {
    long long flow = 0;
    long long cost = 0;
    while (true) {
      vector<long long> dis(n, (long long)(1e15));
      vector<Edge*> par(n);
      vector<bool> vis(n, false);
      vector<long long> mn(n, 0);
      queue<long long> q;
      q.push(src);
      dis[src] = 0;
      vis[src] = 1;
      mn[src] = (long long)(1e15);
      while (!q.empty()) {
        long long v = q.front();
        q.pop();
        vis[v] = 0;
        for (Edge* e = g[v]; e; e = e->nex) {
          if (e->f <= 0) continue;
          if (dis[e->u] > dis[v] + e->c) {
            dis[e->u] = dis[v] + e->c;
            mn[e->u] = min(mn[v], e->f);
            par[e->u] = e;
            if (!vis[e->u]) {
              vis[e->u] = 1;
              q.push(e->u);
            }
          }
        }
      }
      if (dis[sink] == (long long)(1e15)) break;
      long long curr = sink;
      long long ff = mn[sink];
      cost += ff * dis[sink];
      flow += ff;
      while (curr != src) {
        Edge* e = par[curr];
        e->f -= ff;
        e->rev->f += ff;
        curr = e->rev->u;
      }
    }
    return {flow, cost};
  }
} M(4010);
void solve() {
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    for (long long j = 1; j <= n; j++) {
      M.AddEdge(i, j + n, -a[i] * abs(i - j), 1);
    }
    M.AddEdge(0, i, 0, 1);
    M.AddEdge(i + n, 2 * n + 1, 0, 1);
  }
  cout << -M.Flow(0, 2 * n + 1, 2 * n + 10).second;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  start = clock();
  cout << fixed << setprecision(12);
  for (long long i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
