#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int qp(int a, ll b) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a;
    a = 1ll * a * a;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo) {
  int ans = 1;
  do {
    if (b & 1) ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll comb(int n, int r) {
  vector<vector<ll> > v(n + 1, vector<ll>(r + 1, 0));
  for (int i = 0; i < n + 1; i++) {
    v[i][0] = 1;
    if (i < r + 1) v[i][i] = 1;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < min(i, r + 1); j++) {
      v[i][j] = v[i - 1][j - 1] + v[i - 1][j];
    }
  }
  return v[n][r];
}
int main() {
  int n;
  cin >> n;
  vector<ll> vec;
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    ll x;
    cin >> x;
    vec.push_back(x);
  }
  vector<vector<int> > table(n, vector<int>(n, 0));
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    for (int j = 0, j_len = (n); j < j_len; ++j) {
      table[i][j] = abs(i - j) * vec[i];
    }
  }
  ll total = 0;
  vector<int> indices;
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    indices.push_back(i);
  }
  int loffset = 0;
  int roffset = 0;
  for (int k = 0, k_len = (n); k < k_len; ++k) {
    int mi, mv;
    mi = mv = 0;
    bool is_left;
    for (const auto &i : indices) {
      int left = loffset;
      int right = n - 1 - roffset;
      if (table[i][left] < table[i][right] && table[i][right] > mv) {
        mv = table[i][right];
        mi = i;
        is_left = false;
      } else if (table[i][left] > mv) {
        mv = table[i][left];
        mi = i;
        is_left = true;
      }
    }
    total += mv;
    for (auto it = indices.begin(); it != indices.end();) {
      if (*it == mi) {
        indices.erase(it);
        break;
      }
      ++it;
    }
    if (is_left) {
      loffset += 1;
    } else {
      roffset += 1;
    }
  }
  cout << total << '\n';
  return 0;
}
