#include <bits/stdc++.h>
using namespace std;
int pct(int x) { return __builtin_popcount(x); }
int pct(long long x) { return __builtin_popcountll(x); }
int bit(int x) { return 31 - __builtin_clz(x); }
int bit(long long x) { return 63 - __builtin_clzll(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
long long cdiv(long long a, long long b) {
  return a / b + !(a < 0 || a % b == 0);
}
template <typename T>
void leftShift(vector<T> &v, long long k) {
  k %= (int)v.size();
  if (k < 0) k += (int)v.size();
  rotate(v.begin(), v.begin() + k, v.end());
}
template <typename T>
void rightSift(vector<T> &v, long long k) {
  leftShift(v, (int)v.size() - k);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
  uniform_int_distribution<long long> uid(l, r);
  return uid(rng);
}
inline int nxt() {
  int x;
  cin >> x;
  return x;
}
inline int nxtll() {
  long long x;
  cin >> x;
  return x;
}
void pr() {}
void sc() {}
template <typename Head, typename... Tail>
void pr(Head H, Tail... T) {
  cout << H << " ";
  pr(T...);
}
template <typename Head, typename... Tail>
void sc(Head &H, Tail &...T) {
  cin >> H;
  sc(T...);
}
string to_string(__int128 x) {
  string s = "";
  bool neg = 0;
  if (x < 0) {
    s += "-";
    neg = 1;
  }
  if (!x) s += '0';
  while (x) {
    int rem = x % 10;
    s += to_string(rem);
    x /= 10;
  }
  reverse(s.begin() + neg, s.end());
  return s;
}
const int mod = 1e9 + 7;
int pwr(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * 1LL * a) % mod;
    a = (a * 1LL * a) % mod;
    b >>= 1;
  }
  return ans;
}
const int N = 2005;
int a[N];
void solve() {
  int n = nxt();
  for (int i = 1; i <= n; i++) {
    sc(a[i]);
  }
  long long ans = 0;
  for (int p = 0; p <= n; p++) {
    vector<pair<int, int> > v, v1;
    for (int i = 1; i <= p; i++) {
      v.push_back({a[i], i});
    }
    for (int i = p + 1; i <= n; i++) {
      v1.push_back({a[i], i});
    }
    sort(v.rbegin(), v.rend());
    sort(v1.rbegin(), v1.rend());
    long long cur = 0;
    for (int j = 0; j <= (int)v.size() - 1; j++) {
      cur += abs(n - j - v[j].second) * 1LL * v[j].first;
    }
    for (int j = 0; j <= (int)v1.size() - 1; j++) {
      cur += abs(j + 1 - v1[j].second) * 1LL * v1[j].first;
    }
    ans = max(ans, cur);
  }
  pr(ans);
}
signed main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  for (int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
