#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<long long>>;
const long long MOD = 1000000007;
const double PI = 3.1415926535897932;
const long long INF = LLONG_MAX;
long long n;
vector<long long> a;
int solve() {
  cin >> n;
  a.resize(n);
  vector<long long> nums(n);
  for (long long i = (0); i < (n); i++) {
    cin >> a[i];
    nums[i] = i;
  }
  vector<vector<long long>> cost(n, vector<long long>(n));
  for (long long i = (0); i < (n); i++) {
    for (long long j = (0); j < (n); j++) {
      if (i == j) {
        continue;
      } else {
        cost[i][j] = abs(i - j) * a[i];
      }
    }
  }
  long long ans = 0;
  do {
    long long anstmp = 0;
    for (long long i = (0); i < (n); i++) {
      anstmp += cost[i][nums[i]];
    }
    if (anstmp > ans) {
      ans = anstmp;
    }
  } while (next_permutation(nums.begin(), nums.end()));
  cout << ans << endl;
  return 0;
}
int main() {
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int end_solve = solve();
  return end_solve;
}
