#include <bits/stdc++.h>
using namespace std;
tuple<vector<int>, vector<int>> Dijkstra(
    const vector<map<int, array<long long, 2>>>& graph,
    const vector<long long>& potential, int istart, int iend) {
  auto n = graph.size();
  priority_queue<tuple<int, int>> q;
  vector<int> d(n, numeric_limits<int>::max());
  vector<int> prev(n, numeric_limits<int>::max());
  d[istart] = 0;
  q.push(tuple<int, int>{d[istart], istart});
  while (!q.empty()) {
    auto dtmp = -get<0>(q.top());
    auto u = get<1>(q.top());
    q.pop();
    if (d[u] < dtmp) continue;
    for (auto m : graph[u]) {
      auto cost = m.second[1];
      auto capacity = m.second[0];
      auto v = m.first;
      auto alt = d[u] + cost + potential[u] - potential[v];
      if (capacity > 0 && alt < d[v]) {
        d[v] = alt;
        prev[v] = u;
        q.push(tuple<int, int>{-alt, v});
      }
    }
  }
  return tuple<vector<int>, vector<int>>{d, prev};
}
long long PrimalDual(vector<map<int, array<long long, 2>>>& graph, int s, int t,
                     long long flow) {
  const int N = graph.size();
  vector<long long> potential(N, 0);
  long long res = 0;
  auto tmp = graph;
  for (int i = 0; i < N; i++) {
    for (auto e : tmp[i]) {
      auto v = e.first;
      graph[v][i] = array<long long, 2>{-0, -graph[i][v][1]};
    }
  }
  while (flow > 0) {
    auto ret = Dijkstra(graph, potential, s, t);
    auto d = get<0>(ret);
    auto prev = get<1>(ret);
    if (d.back() == numeric_limits<int>::max()) return -1;
    for (int i = 0; i < N; i++) {
      potential[i] += d[i];
    }
    long long d_min = flow;
    for (int v = t; v != s; v = prev[v]) {
      auto u = prev[v];
      d_min = min(d_min, graph[u][v][0]);
    }
    flow -= d_min;
    res += d_min * potential[t];
    for (int v = t; v != s; v = prev[v]) {
      auto u = prev[v];
      graph[u][v][0] -= d_min;
      graph[v][u][0] += d_min;
    }
  }
  return res;
}
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<map<int, array<long long, 2>>> graph(2 * N + 2);
  for (int i = 0; i < N; i++) {
    graph[0][1 + i] = array<long long, 2>{1, 0};
    graph[1 + N + i][2 * N + 1] = array<long long, 2>{1, 0};
    for (int j = 0; j < N; j++) {
      graph[1 + i][1 + N + j] = array<long long, 2>{1, -A[i] * abs(i - j)};
    }
  }
  auto ret = PrimalDual(graph, 0, 2 * N + 1, N);
  cout << -ret << endl;
  return 0;
}
