#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const long long MAX = 9000000000000000000;
const long long MIN = -9000000000000000000;
const long double DMAX = 4500;
const long double DMIN = -4500;
const long long MOD = 1000000007;
template <typename T>
void fin(T a) {
  cout << a << endl;
  exit(0);
}
long long sigma(long long n, long long m) {
  return ((n + m) * (m - n + 1) * 0.5);
}
void Main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a;
  for (long long i = 0; i < (n); ++i) {
    long long s;
    cin >> s;
    a.push_back(make_pair(i, s));
  }
  long long ans = 0;
  do {
    long long g = 0;
    for (long long i = 0; i < n; i++) {
      g += abs(i - a[i].first) * a[i].second;
    }
    ans = max(ans, g);
  } while (next_permutation(a.begin(), a.end()));
  fin(ans);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}
