#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
inline unsigned long long qpow(unsigned long long a, unsigned long long b) {
  unsigned long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = i;
    cin >> b[i];
  }
  long long mx = -INF;
  do {
    long long c = 0;
    for (int i = 1; i <= n; i++) c += fabs(a[i] - i) * b[i];
    mx = max(mx, c);
  } while (next_permutation(a.begin() + 1, a.end()));
  cout << mx;
}
