#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}
template <typename T>
void print_array(const T &ary, int size) {
  for (int i = (0); i < (size); ++i) {
    cout << ary[i] << " ";
  }
  cout << endl;
}
const int MOD = 1e9 + 7;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(12);
  int n;
  cin >> n;
  vector<long long> a(n);
  long long ans = 0;
  for (int i = (0); i < (n); ++i) cin >> a[i];
  for (int i = (1); i < (n); ++i) {
    ;
    vector<long long> b = a;
    map<long long, vector<int> > mpl, mpr;
    for (int j = (0); j < (i); ++j) {
      mpl[a[j]].emplace_back(j);
    }
    for (int j = (i); j < (n); ++j) {
      mpr[a[j]].emplace_back(j);
    }
    sort(b.begin(), b.begin() + i, greater<long long>());
    ;
    sort(b.begin() + i, b.end());
    reverse(b.begin(), b.end());
    long long tmp = 0;
    for (int j = (0); j < (n - i); ++j) {
      ;
      tmp += b[j] * abs(mpr[b[j]].back() - j);
      mpr[b[j]].pop_back();
    };
    for (int j = (n - i); j < (n); ++j) {
      ;
      tmp += b[j] * abs(mpl[b[j]].back() - j);
      ;
      mpl[b[j]].pop_back();
    }
    chmax(ans, tmp);
  }
  cout << ans << endl;
}
