#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const long long INF = 10e17;
double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }
std::istream &operator>>(std::istream &in, set<int> &o) {
  long long a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
const int mod = 1000000007;
struct Infant {
  long long index;
  long long active;
};
long long calc(int n, vector<Infant> infants) {
  vector<Infant> target(n);
  queue<int> q;
  {
    int left = 0;
    int right = n - 1;
    while (left < right) {
      q.push(left);
      q.push(right);
      left++;
      right--;
    }
    if (n % 2 == 1) q.push(n / 2);
  }
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    long long ma = -1;
    long long ma_i = -1;
    for (int i = 0; i < (infants.size()); ++i) {
      Infant infant = infants[i];
      long long score = abs(t - infant.index) * infant.active;
      if (score > ma) {
        ma = score;
        ma_i = i;
      }
    }
    target[t] = infants[ma_i];
    infants.erase(infants.begin() + ma_i);
  }
  long long ans = 0;
  for (int i = 0; i < (n); ++i) {
    Infant infant = target[i];
    long long diff = abs(infant.index - i);
    long long now = infant.active * diff;
    ans += now;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<Infant> infants(n);
  for (int i = 0; i < (n); ++i) infants[i].index = i;
  for (int i = 0; i < (n); ++i) cin >> infants[i].active;
  long long ans1 = calc(n, infants);
  reverse(infants.begin(), infants.end());
  long long ans2 = calc(n, infants);
  cout << max(ans1, ans2) << endl;
}
