#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
const int CASES = 3;
template <class FLOWTYPE, class COSTTYPE>
struct Edge {
  int rev, from, to, id;
  FLOWTYPE cap, icap;
  COSTTYPE cost;
  Edge(int r, int f, int t, FLOWTYPE ca, COSTTYPE co, int id = -1)
      : rev(r), from(f), to(t), cap(ca), icap(ca), cost(co), id(id) {}
  friend ostream &operator<<(ostream &s, const Edge &E) {
    if (E.cap > 0)
      return s << E.from << "->" << E.to << '(' << E.cap << ',' << E.cost
               << ')';
    else
      return s;
  }
};
template <class FLOWTYPE, class COSTTYPE>
struct Graph {
  vector<vector<Edge<FLOWTYPE, COSTTYPE> > > list;
  Graph(int n = 0) : list(n) {}
  void init(int n = 0) {
    list.clear();
    list.resize(n);
  }
  void reset() {
    for (int i = 0; i < (int)list.size(); ++i)
      for (int j = 0; j < list[i].size(); ++j) list[i][j].cap = list[i][j].icap;
  }
  inline vector<Edge<FLOWTYPE, COSTTYPE> > &operator[](int i) {
    return list[i];
  }
  inline const size_t size() const { return list.size(); }
  inline Edge<FLOWTYPE, COSTTYPE> &redge(const Edge<FLOWTYPE, COSTTYPE> &e) {
    if (e.from != e.to)
      return list[e.to][e.rev];
    else
      return list[e.to][e.rev + 1];
  }
  void addedge(int from, int to, FLOWTYPE cap, COSTTYPE cost, int id = -1) {
    list[from].push_back(Edge<FLOWTYPE, COSTTYPE>((int)list[to].size(), from,
                                                  to, cap, cost, id));
    list[to].push_back(Edge<FLOWTYPE, COSTTYPE>((int)list[from].size() - 1, to,
                                                from, 0, -cost));
  }
  void add_undirected_edge(int from, int to, FLOWTYPE cap, COSTTYPE cost,
                           int id = -1) {
    list[from].push_back(Edge<FLOWTYPE, COSTTYPE>((int)list[to].size(), from,
                                                  to, cap, cost, id));
    list[to].push_back(Edge<FLOWTYPE, COSTTYPE>((int)list[from].size() - 1, to,
                                                from, cap, cost, id));
  }
  friend ostream &operator<<(ostream &s, const Graph &G) {
    s << endl;
    for (int i = 0; i < G.size(); ++i) {
      s << i << ":";
      for (auto e : G.list[i]) s << " " << e;
      s << endl;
    }
    return s;
  }
};
template <class FLOWTYPE, class COSTTYPE>
COSTTYPE MinCostFlow(Graph<FLOWTYPE, COSTTYPE> &G, int s, int t, FLOWTYPE f) {
  int n = (int)G.size();
  vector<COSTTYPE> dist(n, -1);
  vector<int> prevv(n), preve(n), seen(n, 0);
  COSTTYPE res = 0;
  while (f > 0) {
    seen.assign(n, 0);
    dist[s] = 0;
    seen[s] = true;
    while (true) {
      bool update = false;
      for (int v = 0; v < n; ++v) {
        if (!seen[v]) continue;
        for (int i = 0; i < G[v].size(); ++i) {
          Edge<FLOWTYPE, COSTTYPE> &e = G[v][i];
          if (e.cap > 0 && (!seen[e.to] || dist[e.to] > dist[v] + e.cost)) {
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v;
            preve[e.to] = i;
            seen[e.to] = true;
            update = true;
          }
        }
      }
      if (!update) break;
    }
    if (!seen[t]) return -1;
    FLOWTYPE d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += dist[t] * d;
    for (int v = t; v != s; v = prevv[v]) {
      Edge<FLOWTYPE, COSTTYPE> &e = G[prevv[v]][preve[v]];
      Edge<FLOWTYPE, COSTTYPE> &re = G.redge(e);
      e.cap -= d;
      re.cap += d;
    }
  }
  return res;
}
template <typename T, bool directed>
struct Dinic {
  struct edge {
    int to;
    T cap;
    int rev;
    edge() {}
    edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
  };
  vector<vector<edge> > G;
  vector<int> level, iter;
  Dinic() {}
  Dinic(int n) : G(n), level(n), iter(n) {}
  int add_edge(int from, int to, T cap) {
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, directed ? 0 : cap, G[from].size() - 1);
    return G[to].back().rev;
  }
  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    queue<int> que;
    level[s] = 0;
    que.emplace(s);
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      for (int i = 0; i < (int)G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.emplace(e.to);
        }
      }
    }
  }
  T dfs(int v, int t, T f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        T d = dfs(e.to, t, min(f, e.cap));
        if (d == 0) continue;
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  }
  T flow(int s, int t, T lim) {
    T fl = 0;
    while (1) {
      bfs(s);
      if (level[t] < 0 || lim == 0) break;
      fill(iter.begin(), iter.end(), 0);
      while (1) {
        T f = dfs(s, t, lim);
        if (f == 0) break;
        fl += f;
        lim -= f;
      }
    }
    return fl;
  }
  T flow(int s, int t) { return flow(s, t, numeric_limits<T>::max() / 2); }
  T cut(int s, int t, int x, int a) {
    static_assert(directed, "must be directed");
    auto &e = G[x][a];
    int y = e.to;
    T cr = G[y][e.rev].cap;
    if (cr == 0) return e.cap = 0;
    e.cap = G[y][e.rev].cap = 0;
    T cap = cr - flow(x, y, cr);
    if (x != s && cap != 0) flow(x, s, cap);
    if (t != y && cap != 0) flow(t, y, cap);
    return cap;
  }
  T link(int s, int t, int x, int a, T f) {
    auto &e = G[x][a];
    e.cap += f;
    return flow(s, t, f);
  }
};
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int s = 2 * n, t = 2 * n + 1;
  Graph<int, int> G(2 * n + 2);
  for (int i = 0; i < n; ++i) {
    G.addedge(s, i, 1, 0);
    G.addedge(n + i, t, 1, 0);
    for (int j = 0; j < n; ++j) {
      if (abs(i - j) < n / 3) continue;
      G.addedge(i, n + j, 1, -1 * a[i] * abs(j - i));
    }
  }
  cout << -1 * MinCostFlow(G, s, t, n) << endl;
}
int main() {
  solve();
  return 0;
}
