#include <bits/stdc++.h>
using namespace std;
long long n;
std::vector<long long> a(2007);
struct Comparer {
  bool operator()(const bitset<2007> &b1, const bitset<2007> &b2) const {
    return b1.to_ulong() < b2.to_ulong();
  }
};
std::map<bitset<2007>, long long, Comparer> dp[2007];
long long res = 0;
long long func(long long pos, bitset<2007> taken) {
  if (pos == (n + 1)) {
    return 0;
  }
  if (dp[pos].find(taken) != dp[pos].end()) return dp[pos][taken];
  long long cres = 0;
  for (long long int i = 1; i < n + 1; i++) {
    if (!taken[i]) {
      taken[i] = 1;
      long long ex = abs(pos - i) * a[pos];
      cres = max(cres, ex + func(pos + 1, taken));
      taken[i] = 0;
    }
  }
  return dp[pos][taken] = max(dp[pos][taken], cres);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> a[i + 1];
  bitset<2007> pos;
  cout << func(1, pos);
}
