#include <bits/stdc++.h>
using namespace std;
void __print(long long int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  vector<long long int> vis(n, 0);
  long long int ans = 0;
  long long int i = 0;
  long long int f = 0;
  long long int prev = 0;
  for (long long int pos = 0; pos < n; pos++) {
    if (!f) i = prev;
    if (f) {
      i = n - prev - 1;
      prev++;
    }
    long long int tmp = 0, id = -1;
    for (long long int j = 0; j < n; j++) {
      if (vis[j]) continue;
      if (abs(i - j) * v[j] > tmp) {
        tmp = abs(i - j) * v[j];
        id = j;
      } else if (abs(i - j) * v[j] == tmp && id != -1) {
        if (v[j] > v[id]) {
          id = j;
        }
      }
    }
    vis[id] = 1;
    ans += tmp;
    f = !f;
  }
  cout << ans << endl;
}
signed main() {
  long long int t = 1;
  for (long long int tc = 1; tc <= t; tc++) {
    solve();
  }
}
