#include <bits/stdc++.h>
using namespace std;
inline void logger() { std::cout << " [LOGGER] " << endl; }
template <typename A, typename... B>
void logger(const A& a, const B&... b) {
  cout << a << " , ";
  logger(b...);
}
const long long MOD = 1000000007;
const long long MOD9 = 998244353;
const long long INF = MOD * MOD;
const int MAX = 200005;
int n;
long long solve(vector<pair<long long, long long> > l,
                vector<pair<long long, long long> > r) {
  sort((l).begin(), (l).end(), greater<pair<long long, long long> >());
  sort((r).begin(), (r).end(), greater<pair<long long, long long> >());
  long long res = 0;
  int L = l.size(), R = r.size();
  for (int(i) = 0; (i) < (L); (i)++) {
    res += l[i].first * abs(n - 1 - i - l[i].second);
  }
  for (int(i) = 0; (i) < (R); (i)++) {
    res += r[i].first * abs(r[i].second - i);
  }
  return res;
}
int main() {
  cin >> n;
  vector<long long> a(n);
  for (int(i) = 0; (i) < (n); (i)++) cin >> a[i];
  long long ans = -1;
  for (int(k) = 0; (k) < (n + 1); (k)++) {
    vector<pair<long long, long long> > l, r;
    for (int(i) = 0; (i) < (k); (i)++)
      l.push_back(pair<long long, long long>(a[i], i));
    for (int(i) = 0; (i) < (n - k); (i)++)
      r.push_back(pair<long long, long long>(a[i + k], i + k));
    long long res = solve(l, r);
    ans = max(res, ans);
  }
  cout << (ans) << endl;
}
