#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long a[200001];
long long prefSum[200001];
long long ans1[200001];
long long ans2[200001];
long long product;
long long cost1(long long i, long long j) {
  long long ans = product;
  ans -= prefSum[j] - prefSum[i];
  ans -= a[i] * i;
  ans += a[i] * j;
  return ans;
}
long long cost2(long long i, long long j) {
  long long ans = product;
  ans += prefSum[j - 1] - prefSum[i - 1];
  ans -= a[j] * j;
  ans += a[j] * i;
  return ans;
}
void compute1(int l, int r, int optl, int optr) {
  if (r < l) return;
  int mid = (l + r) / 2;
  int opt;
  for (int k = optl; k <= min(mid - 1, optr); k++) {
    if (cost1(k, mid) > ans1[mid]) {
      ans1[mid] = cost1(k, mid);
      opt = k;
    }
  }
  compute1(l, mid - 1, optl, opt);
  compute1(mid + 1, r, opt, optr);
}
void compute2(int l, int r, int optl, int optr) {
  if (r < l) return;
  int mid = (l + r) / 2;
  int opt;
  for (int k = max(optl, mid + 1); k <= optr; k++) {
    if (cost2(mid, k) > ans2[mid]) {
      ans2[mid] = cost2(mid, k);
      opt = k;
    }
  }
  compute2(l, mid - 1, optl, opt);
  compute2(mid + 1, r, opt, optr);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    prefSum[i] = a[i];
    prefSum[i] += prefSum[i - 1];
    product += a[i] * (long long)i;
    ans1[i] = -1e18;
    ans2[i] = -1e18;
  }
  compute1(2, n, 1, n - 1);
  compute2(1, n - 1, 2, n);
  cout << max({*max_element(ans1 + 1, ans1 + n + 1),
               *max_element(ans2 + 1, ans2 + n + 1), product});
}
