#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
void printVector(const vector<int> &vec) {
  for (int value : vec) {
    cout << value << " ";
  }
  cout << endl;
}
int a[2000];
ll calcHappiness(const vector<int> &vec) {
  int i = 0;
  ll ans = 0;
  for (int value : vec) {
    ans += (ll)(a[value]) * (ll)(abs(value - i));
    i++;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> iton(n);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    iton[i] = i;
  }
  do {
    chmax(ans, calcHappiness(iton));
  } while (next_permutation(iton.begin(), iton.end()));
  cout << ans << endl;
  return 0;
}
