#include <bits/stdc++.h>
using namespace std;
int pct(int x) { return __builtin_popcount(x); }
int pct(long long x) { return __builtin_popcountll(x); }
int bit(int x) { return 31 - __builtin_clz(x); }
int bit(long long x) { return 63 - __builtin_clzll(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
long long cdiv(long long a, long long b) {
  return a / b + !(a < 0 || a % b == 0);
}
template <typename T>
void leftShift(vector<T> &v, long long k) {
  k %= (int)v.size();
  if (k < 0) k += (int)v.size();
  rotate(v.begin(), v.begin() + k, v.end());
}
template <typename T>
void rightShift(vector<T> &v, long long k) {
  leftShift(v, (int)v.size() - k);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
  uniform_int_distribution<long long> uid(l, r);
  return uid(rng);
}
inline int nxt() {
  int x;
  cin >> x;
  return x;
}
inline int nxtll() {
  long long x;
  cin >> x;
  return x;
}
void pr() {}
void sc() {}
template <typename Head, typename... Tail>
void pr(Head H, Tail... T) {
  cout << H << " ";
  pr(T...);
}
template <typename Head, typename... Tail>
void sc(Head &H, Tail &...T) {
  cin >> H;
  sc(T...);
}
string to_string(__int128 x) {
  string s = "";
  bool neg = 0;
  if (x < 0) {
    s += "-";
    neg = 1;
  }
  if (!x) s += '0';
  while (x) {
    int rem = x % 10;
    s += to_string(rem);
    x /= 10;
  }
  reverse(s.begin() + neg, s.end());
  return s;
}
const int mod = 1e9 + 7;
int pwr(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * 1LL * a) % mod;
    a = (a * 1LL * a) % mod;
    b >>= 1;
  }
  return ans;
}
const long long INF = 1e9;
struct MinimumCostMaximumFlow {
  static const long long InfCapacity = INF;
  struct Edge {
    long long to;
    long long rev;
    long long capacity;
    long long cost;
  };
  vector<vector<Edge> > g;
  void init(long long n) { g.assign(n, vector<Edge>()); }
  void add(long long i, long long j, long long capacity = InfCapacity,
           long long cost = long long()) {
    Edge e, f;
    e.to = j, f.to = i;
    e.capacity = capacity, f.capacity = 0;
    e.cost = cost, f.cost = -cost;
    g[i].push_back(e);
    g[j].push_back(f);
    g[i].back().rev = (long long)g[j].size() - 1;
    g[j].back().rev = (long long)g[i].size() - 1;
  }
  void addB(long long i, long long j, long long capacity = InfCapacity,
            long long cost = long long()) {
    add(i, j, capacity, cost);
    add(j, i, capacity, cost);
  }
  pair<long long, long long> minimumCostMaximumFlow(long long s, long long t,
                                                    long long f = InfCapacity,
                                                    bool useSPFA = false) {
    long long n = g.size();
    vector<long long> dist(n);
    vector<long long> prev(n);
    vector<long long> prevEdge(n);
    pair<long long, long long> total = make_pair(0, 0);
    vector<long long> potential(n);
    while (f > 0) {
      fill(dist.begin(), dist.end(), INF);
      if (useSPFA || total.second == 0) {
        deque<long long> q;
        q.push_back(s);
        dist[s] = 0;
        vector<bool> inqueue(n);
        while (!q.empty()) {
          long long i = q.front();
          q.pop_front();
          inqueue[i] = false;
          for (long long ei = 0; ei < (long long)g[i].size(); ei++) {
            const Edge &e = g[i][ei];
            long long j = e.to;
            long long d = dist[i] + e.cost;
            if (e.capacity > 0 && d < dist[j]) {
              if (!inqueue[j]) {
                inqueue[j] = true;
                q.push_back(j);
              }
              dist[j] = d;
              prev[j] = i;
              prevEdge[j] = ei;
            }
          }
        }
      } else {
        vector<bool> vis(n);
        priority_queue<pair<long long, long long> > q;
        q.push(make_pair(-0, s));
        dist[s] = 0;
        while (!q.empty()) {
          long long i = q.top().second;
          q.pop();
          if (vis[i]) continue;
          vis[i] = true;
          for (long long ei = 0; ei < (long long)g[i].size(); ei++) {
            const Edge &e = g[i][ei];
            if (e.capacity <= 0) continue;
            long long j = e.to;
            long long d = dist[i] + e.cost + potential[i] - potential[j];
            if (dist[j] > d) {
              dist[j] = d;
              prev[j] = i;
              prevEdge[j] = ei;
              q.push(make_pair(-d, j));
            }
          }
        }
      }
      if (dist[t] == INF) break;
      if (!useSPFA)
        for (long long i = 0; i < n; i++) potential[i] += dist[i];
      long long d = f;
      long long distt = 0;
      for (long long v = t; v != s;) {
        long long u = prev[v];
        const Edge &e = g[u][prevEdge[v]];
        d = min(d, e.capacity);
        distt += e.cost;
        v = u;
      }
      f -= d;
      total.first += d * distt;
      total.second += d;
      for (long long v = t; v != s; v = prev[v]) {
        Edge &e = g[prev[v]][prevEdge[v]];
        e.capacity -= d;
        g[e.to][e.rev].capacity += d;
      }
    }
    return total;
  }
};
const int N = 2005;
int a[N];
void solve() {
  int n = nxt();
  long long h = 0;
  for (int i = 1; i <= n; i++) {
    sc(a[i]);
  }
  MinimumCostMaximumFlow mcmf;
  mcmf.init(2 * n + 5);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      mcmf.add(i, j + n, 1, -a[i] * 1LL * abs(i - j));
    }
  }
  int S = 2 * n + 1, T = S + 1;
  for (int i = 1; i <= n; i++) {
    mcmf.add(S, i, 1, 0);
    mcmf.add(n + i, T, 1, 0);
  }
  cout << -mcmf.minimumCostMaximumFlow(S, T).first;
}
signed main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
