#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const int64_t INF = 1e18;
const int inf = 1e9;
const int64_t mod = 1e9 + 7;
bool print_space_enable = false;
void print() {
  cout << endl;
  print_space_enable = false;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  if (print_space_enable) cout << " ";
  cout << fixed << setprecision(15) << head;
  print_space_enable = true;
  print(std::forward<Tail>(tail)...);
}
template <typename T>
void print(vector<T> v) {
  for (size_t i = 0; i < v.size(); i++) {
    if (i > 0) std::cout << " ";
    std::cout << v[i];
  }
  std::cout << std::endl;
}
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  for (int64_t i = 0; i < (int64_t)n; i++) {
    cin >> a[i];
  }
  vector<pair<int64_t, int64_t>> b(n);
  for (int64_t i = 0; i < (int64_t)n; i++) {
    b[i] = {a[i], i};
  }
  int64_t l = 0, r = n - 1;
  vector<bool> used(n + 1, false);
  int64_t res = 0;
  for (int64_t i = 0; i < (int64_t)n; i++) {
    priority_queue<pair<int64_t, int64_t>> q;
    for (int64_t j = 0; j < (int64_t)n; j++) {
      if (not used[j]) {
        if (abs(l - j) * a[j] >= abs(r - j) * a[j]) {
          q.push({abs(l - j) * a[j], j});
        } else {
          q.push({abs(r - j) * a[j], j});
        }
      }
    }
    int64_t c = q.top().first;
    int64_t index = q.top().second;
    q.pop();
    if (abs(l - index) * a[index] > abs(r - index) * a[index]) {
      res += c;
      used[index] = true;
      l++;
    } else if (abs(r - index) * a[index] > abs(l - index) * a[index]) {
      res += c;
      used[index] = true;
      r--;
    } else {
      if (i == n - 1) {
        res += c;
      } else {
        int64_t c2 = q.top().first;
        int64_t index2 = q.top().second;
        q.pop();
        res += c + c2;
        used[index] = used[index2] = true;
        l++, r--, i++;
      }
    }
  }
  print(res);
  return 0;
}
