#include <bits/stdc++.h>
using namespace std;
int a[2000];
vector<int> dp(6, 0);
vector<vector<int>> r;
int flag = 0;
int n;
int ans = 0;
void dfs(int cur, int sum) {
  if (cur == n / 2) {
    if (sum > ans) ans = sum;
    return;
  }
  for (int i = 0; i < n; i++) {
    if (dp[i]) continue;
    dp[i] = 1;
    for (int j = 0; j < n; j++) {
      if (!dp[j]) {
        dp[j] = 1;
        dfs(cur + 1, sum + abs(j - i) * (a[i] + a[j]));
        dp[j] = 0;
      }
    }
    dp[i] = 0;
  }
  return;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  dfs(0, 0);
  cout << ans << endl;
  return 0;
}
