#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long mod_add(long long A, long long B) { return (A + B) % MOD; }
long long mod_sub(long long A, long long B) { return (A + MOD - B) % MOD; }
long long mod_mul(long long A, long long B) {
  return ((A % MOD) * (B % MOD)) % MOD;
}
long long mod_bipow(long long X, long long Y) {
  if (Y == 0)
    return 1;
  else if (Y == 1)
    return X % MOD;
  else if (Y % 2 == 0) {
    long long Z = mod_bipow(X, (long long)(Y / 2));
    return mod_mul(Z, Z);
  } else {
    long long Z = mod_bipow(X, (long long)(Y / 2));
    return mod_mul(mod_mul(Z, Z), X);
  }
}
long long mod_inv(long long X) { return mod_bipow(X, MOD - 2); }
long long mod_div(long long A, long long B) { return mod_mul(A, mod_inv(B)); }
template <class T>
bool amin(T &A, T B) {
  if (A > B) {
    A = B;
    return true;
  }
  return false;
}
template <class T>
bool amax(T &A, T B) {
  if (A < B) {
    A = B;
    return true;
  }
  return false;
}
vector<long long> divisors(long long N) {
  vector<long long> ret;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ret.push_back(i);
      if (i * i != N) ret.push_back(N / i);
    }
  }
  stable_sort(begin(ret), end(ret));
  return ret;
}
map<long long, long long> prime_factors(long long N) {
  map<long long, long long> ret;
  for (long long i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      ret[i]++;
      N /= i;
    }
  }
  if (N != 1) ret[N]++;
  return ret;
}
long long ceil_div(long long X, long long Y) { return (X - 1) / Y + 1; }
vector<long long> cum(vector<long long> V) {
  vector<long long> U((long long)(V).size());
  partial_sum(begin(V), end(V), begin(U));
  return U;
}
struct union_find {
  vector<long long> data;
  union_find(long long size) : data(size, -1) {}
  bool union_set(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool find_set(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long long size(long long x) { return -data[root(x)]; }
};
struct vertex {
  vector<long long> adj = vector<long long>(0);
};
void solve(long long n, vector<long long> a) {
  long long ans = 0;
  vector<bool> went(n);
  long long l = 0, r = n - 1;
  for (decltype(+n) i = 0; i < (n); i++) {
    long long joy = -1;
    bool is_l = true;
    long long index = 0;
    for (decltype(+n) j = 0; j < (n); j++) {
      if (went[j]) continue;
      long long l_joy = a[j] * abs(j - l);
      long long r_joy = a[j] * abs(j - r);
      if (l_joy > r_joy && l_joy > joy) {
        joy = l_joy;
        is_l = true;
        index = j;
      } else if (r_joy > joy) {
        joy = r_joy;
        is_l = false;
        index = j;
      }
    }
    ans += joy;
    went[index] = true;
    is_l ? l++ : r--;
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve(n, move(a));
}
