#include <bits/stdc++.h>
using namespace std;
deque<long long> pos_remain;
int main() {
  int N;
  scanf("%d", &N);
  vector<pair<long long, long long>> dat(N);
  deque<long long> after(N), bef(N);
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    pos_remain.push_back(i);
    scanf("%lld", &dat[i].first);
    bef[i] = dat[i].first;
    dat[i].second = i;
  }
  sort((dat).begin(), (dat).end(),
       [](const pair<long long, long long>& A,
          const pair<long long, long long>& B) { return A > B; });
  for (int i = 0; i < N; ++i) {
    long long top = pos_remain.back();
    long long low = pos_remain.front();
    if (top - dat[i].second >= dat[i].second - low) {
      after[top] = dat[i].first;
      pos_remain.pop_back();
    } else {
      after[low] = dat[i].first;
      pos_remain.pop_front();
    }
  }
  for (int i = 0; i < N; ++i) {
    long long kntl = 0;
    deque<long long> tmp = bef;
    map<long long, deque<long long>> index;
    for (int k = 0; k < N; ++k) {
      index[after[k]].push_back(k);
    }
    for (int j = 0; j < N; ++j) {
      kntl += tmp[j] * abs(j - index[tmp[j]].front());
      index[tmp[j]].pop_front();
    }
    ans = max(ans, kntl);
    after.push_back(after.front());
    after.pop_front();
  }
  printf("%lld\n", ans);
  return 0;
}
