#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int maxa = 0, s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int x = abs(i - j - 1);
      maxa = max(maxa, a[i] * x + a[j] * x);
    }
  }
  cout << maxa + s;
}
