#include <bits/stdc++.h>
using namespace std;
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
  i >> p.x >> p.y;
  return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
  for (auto& v : t) {
    i >> v;
  }
  return i;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {
  o << p.x << ' ' << p.y;
  return o;
}
template <typename T>
std::ostream& operator<<(std::ostream& o, const vector<T>& t) {
  if (t.empty()) o << '\n';
  for (size_t i = 0; i < t.size(); ++i) {
    o << t[i] << " \n"[i == t.size() - 1];
  }
  return o;
}
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
T gcd(T a, T b) {
  if (a < b) swap(a, b);
  return b ? gcd(b, a % b) : a;
}
const int MOD = 1000000007;
const long long INF = numeric_limits<long long>::max() / 4;
pair<long long, vector<long long>> hungarian(
    const vector<vector<long long>>& a) {
  if (a.empty()) return {0, {}};
  long long n = (int)(a).size() + 1, m = (int)(a[0]).size() + 1;
  vector<long long> u(n), v(m), p(m), ans(n - 1);
  for (int(i) = 1; (i) < (int)(n); (i)++) {
    p[0] = i;
    long long j0 = 0;
    vector<long long> dist(m, 1LL << 62), pre(m, -1);
    vector<bool> done(m + 1);
    do {
      done[j0] = true;
      long long i0 = p[j0], j1, delta = 1LL << 62;
      for (int(j) = 1; (j) < (int)(m); (j)++)
        if (!done[j]) {
          auto cur = a[i0 - 1][j - 1] - u[i0] - v[j];
          if (cur < dist[j]) dist[j] = cur, pre[j] = j0;
          if (dist[j] < delta) delta = dist[j], j1 = j;
        }
      for (int(j) = 0; (j) < (int)(m); (j)++) {
        if (done[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          dist[j] -= delta;
      }
      j0 = j1;
    } while (p[j0]);
    while (j0) {
      long long j1 = pre[j0];
      p[j0] = p[j1], j0 = j1;
    }
  }
  for (int(j) = 1; (j) < (int)(m); (j)++)
    if (p[j]) ans[p[j] - 1] = j - 1;
  return {-v[0], ans};
}
void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<long long> A(n);
  cin >> A;
  vector<vector<long long>> AA;
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    vector<long long> x;
    for (int(j) = 0; (j) < (int)(n); (j)++)
      x.push_back((1LL << 33) - A[i] * abs(i - j));
    AA.push_back(x);
  }
  long long C = (1LL << 33) * n;
  cout << C - hungarian(AA).first << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve(cin, cout);
  return 0;
}
