#include <bits/stdc++.h>
using namespace std;
vector<bool> vis(2005, false);
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  map<long long, int> make_pair;
  long long max_ = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    make_pair[a[i]] = i;
  }
  int idx = 0;
  for (int j = 0; j <= n; j++) {
    long long sum1 = 0;
    for (int i = 0; i < n; i++) {
      int new_ = max((i + j) % n, abs(i - j));
      int old = make_pair[a[i]];
      sum1 += (a[i] * abs(new_ - old));
    }
    if (sum1 > max_) {
      max_ = sum1;
      idx = j;
    }
  }
  cout << max_ << endl;
  return 0;
}
