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