#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmaxj(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; }
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int(i) = 0; (i) < (N); (i)++) cin >> A[i];
  long long ans = 0;
  vector<bool> Used(N, false);
  ll end = N - 1;
  for (ll i = 0; i <= end; i++) {
    long long max = 0;
    long long index = 0;
    for (ll j = 0; j < N; j++) {
      if (Used[j]) continue;
      if (abs(i - j) * A[j] > max) {
        if (N % 2 == 1 && index == (N - 1) / 2) {
          if (!Used[i] || !Used[end]) {
            if (A[i] >= A[end]) {
              max = abs(i - j) * A[j];
              index = j;
            }
          }
        } else {
          max = abs(i - j) * A[j];
          index = j;
        }
      }
    }
    ans += max;
    Used[index] = true;
    max = 0;
    index = 0;
    for (ll j = 0; j < N; j++) {
      if (Used[j]) continue;
      if (abs(end - j) * A[j] > max) {
        if (N % 2 == 0 && index == N / 2) {
          if (!Used[i] || !Used[end]) {
            if (A[i] <= A[end]) {
              max = abs(end - j) * A[j];
              index = j;
            }
          }
        } else {
          max = abs(end - j) * A[j];
          index = j;
        }
      }
    }
    ans += max;
    Used[index] = true;
    end--;
  }
  cout << ans << endl;
}
