#include <bits/stdc++.h>
int a[2005];
bool vis[2005];
using std::max;
int main() {
  int n;
  using std::cin;
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int lo = 0, hi = n;
  long long sum1 = 0;
  for (int i = 0; i < n; i++) {
    long long max_val = 0;
    int max_idx = 0;
    for (int j = 0; j < n; j++) {
      if (vis[j]) {
        continue;
      }
      long long cur_val = (long long)a[j] * max(abs(j - lo), abs(hi - 1 - j));
      if (cur_val > max_val) {
        max_val = cur_val;
        max_idx = j;
      }
    }
    sum1 += max_val;
    vis[max_idx] = true;
    if (abs(max_idx - lo) > abs(hi - 1 - max_idx)) {
      lo++;
    } else {
      hi--;
    }
  }
  lo = 0, hi = n;
  long long sum2 = 0;
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    long long max_val = 0;
    int max_idx = 0;
    for (int j = 0; j < n; j++) {
      if (vis[j]) {
        continue;
      }
      long long cur_val = (long long)a[j] * max(abs(j - lo), abs(hi - 1 - j));
      if (cur_val > max_val) {
        max_val = cur_val;
        max_idx = j;
      }
    }
    sum2 += max_val;
    vis[max_idx] = true;
    if (abs(max_idx - lo) >= abs(hi - 1 - max_idx)) {
      lo++;
    } else {
      hi--;
    }
  }
  std::cout << max(sum1, sum2) << std::endl;
  return 0;
}
