#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  long long best = -1;
  for (int podzial = (1); podzial <= (n - 1); ++podzial) {
    vector<pair<int, int>> l, r;
    for (int i = 0; i < (podzial); ++i) l.emplace_back(a[i], i);
    for (int i = (podzial); i <= (n - 1); ++i) r.emplace_back(a[i], i);
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    sort(r.begin(), r.end());
    reverse(r.begin(), r.end());
    long long suma = 0;
    for (int i = 0; i < (podzial); ++i) {
      long long cel = n - 1 - i;
      long long dod = abs(cel - l[i].second) * l[i].first;
      suma += dod;
    }
    for (int i = 0; i < (((int)((r).size()))); ++i) {
      long long cel = i;
      long long dod = abs(r[i].second - cel) * r[i].first;
      suma += dod;
    }
    if (best == -1 || suma > best) {
      best = suma;
    }
  }
  cout << best << endl;
}
