#include <bits/stdc++.h>
using namespace std;
long long a[200006], sum[200006], ans1, qx[200006], qy[200006], ans;
int n, s, t, l, r;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    ans1 += a[i] * i;
  }
  s = 1;
  for (int i = 0; i <= n; i++) {
    long long x = i;
    long long y = sum[i];
    while (s < t && (y - qy[t]) * (qx[t] - qx[t - 1]) <=
                        (qy[t] - qy[t - 1]) * (x - qx[t]))
      t--;
    qx[++t] = x;
    qy[t] = y;
  }
  for (int i = 1; i <= n; i++) {
    l = s;
    r = t;
    while (l < r) {
      int mid = (l + r) / 2;
      if (qy[mid + 1] - qy[mid] < a[i] * (qx[mid + 1] - qx[mid]))
        l = mid + 1;
      else
        r = mid;
    }
    ans = max(ans, -qy[l] + qx[l] * a[i] + sum[i] - i * a[i]);
  }
  printf("%lld", ans1 + ans);
}
