#include <bits/stdc++.h>
using namespace std;
int a[200005];
long long yi[200005];
long long sl[200005];
long long xi[200005];
int ls;
void addLine(long long m, long long c) {
  while (ls >= 1) {
    if (m * xi[ls - 1] + c >= sl[ls - 1] * xi[ls - 1] + yi[ls - 1])
      ls--;
    else
      break;
  }
  if (ls == 0) {
    yi[ls] = c;
    sl[ls] = m;
    xi[ls] = 1000005;
    ls++;
    return;
  }
  xi[ls] = (c - yi[ls - 1]) / (sl[ls - 1] - m);
  int lo = xi[ls] - 2;
  int hi = xi[ls] + 2;
  for (xi[ls] = hi; xi[ls] >= lo; xi[ls]--) {
    if (m * xi[ls] + c >= sl[ls - 1] * xi[ls] + yi[ls - 1]) break;
  }
  yi[ls] = c;
  sl[ls] = m;
  ls++;
}
void addLine2(long long m, long long c) {
  while (ls >= 1) {
    if (m * xi[ls - 1] + c >= sl[ls - 1] * xi[ls - 1] + yi[ls - 1])
      ls--;
    else
      break;
  }
  if (ls == 0) {
    yi[ls] = c;
    sl[ls] = m;
    xi[ls] = -10000000;
    ls++;
    return;
  }
  xi[ls] = (c - yi[ls - 1]) / (sl[ls - 1] - m);
  int lo = xi[ls] - 2;
  int hi = xi[ls] + 2;
  for (xi[ls] = lo; xi[ls] <= hi; xi[ls]++) {
    if (m * xi[ls] + c >= sl[ls - 1] * xi[ls] + yi[ls - 1]) break;
  }
  yi[ls] = c;
  sl[ls] = m;
  ls++;
}
long long sa[200005];
int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    sa[i] = a[i];
    ans += a[i] * 1ll * (i + 1);
    if (i) sa[i] += sa[i - 1];
  }
  long long mx = 0;
  ls = 0;
  addLine(n, -sa[n - 1]);
  for (int i = n - 2; i >= 0; i--) {
    int x = a[i];
    long long bef = 0;
    if (i) bef = sa[i - 1];
    int lo = 0;
    int hi = ls - 1;
    while (lo + 1 <= hi) {
      int md = (lo + hi) / 2;
      long long f1 = sl[md] * x + yi[md];
      long long f2 = sl[md + 1] * x + yi[md + 1];
      if (f1 <= f2)
        lo = md + 1;
      else
        hi = md;
    }
    mx = max(sl[lo] * x + yi[lo] + bef - i * 1ll * a[i], mx);
    addLine(i + 1, -sa[i]);
  }
  ls = 0;
  addLine2(1, sa[n - 1]);
  for (int i = 1; i < n; i++) {
    int x = a[i];
    long long bef = sa[n - 1] - sa[i];
    int lo = 0;
    int hi = ls - 1;
    while (lo + 1 <= hi) {
      int md = (lo + hi) / 2;
      long long f1 = sl[md] * x + yi[md];
      long long f2 = sl[md + 1] * x + yi[md + 1];
      if (f1 <= f2)
        lo = md + 1;
      else
        hi = md;
    }
    mx = max(sl[lo] * x + yi[lo] - bef - (i + 2) * 1ll * a[i], mx);
    long long Y = sa[n - 1] - sa[i - 1];
    addLine2(i + 1, Y);
  }
  printf("%lld\n", mx + ans);
}
