#include <bits/stdc++.h>
void dout() { std::cout << std::endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {}
template <typename T>
void doutArr(std::string name, std::vector<T> &a) {}
long long best = 0;
void go(int pos, int n, std::vector<int> &a, std::vector<int> &newPlace,
        long long count) {
  if (pos == n) {
    best = std::max(best, count);
    return;
  }
  if (newPlace[pos] > -1) {
    go(pos + 1, n, a, newPlace, count);
    return;
  }
  for (int i = 0; i < n; i++) {
    if (pos == i || newPlace[i] != -1) {
      continue;
    }
    newPlace[pos] = i;
    newPlace[i] = pos;
    int diff = std::abs(pos - i);
    go(pos + 1, n, a, newPlace, count + a[pos] * diff + a[i] * diff);
    newPlace[pos] = -1;
    newPlace[i] = -1;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  std::vector<int> newPlace(n, -1);
  go(0, n, a, newPlace, 0L);
  std::cout << best;
  return 0;
}
