#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long INF = 1ll << 60;
const double PI = 2 * asin(1);
void yes() { printf("yes\n"); }
void no() { printf("no\n"); }
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
void YES() { printf("YES\n"); }
void NO() { printf("NO\n"); }
int N;
long long ans = 0, A[2005];
pair<long long, long long> P[2005];
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    P[i] = make_pair(A[i], i);
  }
  sort(P, P + N, greater<pair<long long, long long> >());
  if (N % 2 == 0) {
    long long L = 0, R = N - 1;
    for (int i = 0; i < N; i += 2) {
      long long now1 = P[i].first * abs(L - P[i].second);
      now1 += P[i + 1].first * abs(R - P[i + 1].second);
      long long now2 = P[i].first * abs(R - P[i].second);
      now2 += P[i + 1].first * abs(L - P[i + 1].second);
      ans += max(now1, now2);
      L++;
      R--;
    }
    cout << ans << endl;
    return 0;
  }
  long long ans1 = P[0].first * abs(P[0].second);
  long long L = 1, R = N - 1;
  for (int i = 1; i < N; i += 2) {
    long long now1 = P[i].first * abs(L - P[i].second);
    now1 += P[i + 1].first * abs(R - P[i + 1].second);
    long long now2 = P[i].first * abs(R - P[i].second);
    now2 += P[i + 1].first * abs(L - P[i + 1].second);
    ans1 += max(now1, now2);
    L++;
    R--;
  }
  long long ans2 = P[0].first * abs(N - 1 - P[0].second);
  L = 0;
  R = N - 2;
  for (int i = 1; i < N; i += 2) {
    long long now1 = P[i].first * abs(L - P[i].second);
    now1 += P[i + 1].first * abs(R - P[i + 1].second);
    long long now2 = P[i].first * abs(R - P[i].second);
    now2 += P[i + 1].first * abs(L - P[i + 1].second);
    ans2 += max(now1, now2);
    L++;
    R--;
  }
  cout << max(ans1, ans2) << endl;
  return 0;
}
