#include <bits/stdc++.h>
using namespace std;
void printVector(const vector<int>& vec) {
  for (int value : vec) {
    cout << value << " ";
  }
  cout << endl;
}
int main() {
  int N, a;
  int ans = 0;
  int uresisa = 0;
  vector<int> points;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    points.push_back(a);
  }
  vector<int> nums(N);
  iota(nums.begin(), nums.end(), 0);
  do {
    uresisa = 0;
    for (int i = 0; i < nums.size(); i++) {
      uresisa += points[i] * abs(i - nums[i]);
    }
    if (ans < uresisa) {
      ans = uresisa;
    }
  } while (next_permutation(nums.begin(), nums.end()));
  cout << ans;
  return 0;
}
