#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long n, a[2010];
long long f(long long i, set<long long> s) {
  if (i >= n) return 0;
  long long mx = -1;
  set<long long> s1 = s;
  for (auto j : s) {
    s1.erase(j);
    mx = max(mx, a[i] * abs(i - j) + f(i + 1, s1));
    s1.insert(j);
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  if (fopen("inp.txt", "r"))
    freopen("inp.txt", "r", stdin), freopen("out.txt", "w", stdout);
  ;
  cin >> n;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  set<long long> s;
  for (long long i = 0; i < n; ++i) s.insert(i);
  cout << f(0, s);
  return 0;
}
