#include <bits/stdc++.h>
using namespace std;
void cerr_(istream_iterator<string> it) { (void)it; }
template <class T, class... Args>
void cerr_(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  cerr_(++it, args...);
}
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << '{';
  string sep;
  for (const auto &x : s) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T, class S>
ostream &operator<<(ostream &os, const map<T, S> &m) {
  os << '{';
  string sep;
  for (const auto &x : m) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
int n;
vector<pair<int, int> > v;
long long memo[2001][2001];
long long solve(int i, int l, int r) {
  if (i == n || l > r) return 0;
  long long x = v[i].first;
  long long p = v[i].second;
  long long ans = 0;
  ans = max(ans, x * abs(p - l) + solve(i + 1, l + 1, r));
  ans = max(ans, x * abs(p - r) + solve(i + 1, l, r - 1));
  return ans;
}
void run_test() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) cin >> v[i].first, v[i].second = i;
  sort((v).rbegin(), (v).rend());
  cout << solve(0, 0, n - 1) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  run_test();
  return 0;
}
