#include <bits/stdc++.h>
using namespace std;
inline int Read(int &r) {
  int b = 1, c = getchar();
  while (c < '0' || '9' < c) b = c == '-' ? -1 : b, c = getchar();
  while ('0' <= c && c <= '9')
    r = (r << 1) + (r << 3) + (c ^ '0'), c = getchar();
  return r *= b;
}
const int N = 2e5 + 10;
const double EPS = 1e-7;
struct STACK {
  int ary[N], tp;
  inline void push(const int &x) { ary[++tp] = x; }
  inline void pop() { tp--; }
  inline void clear() { tp = 0; }
  inline bool empty() { return !tp; }
  inline int size() { return tp; }
  inline int operator[](const int &i) { return ary[tp - i]; }
} stk;
int n;
int num[N];
long long sum[N], org;
long long Calc1(const int &i, const int &k) { return 1ll * i * k - sum[i - 1]; }
long long Calc2(const int &i, const int &k) { return 1ll * i * k - sum[i]; }
long long Query(int k, int typ) {
  if (stk.size() == 1) {
    if (typ == 1)
      return Calc1(stk[0], k);
    else
      return Calc2(stk[0], k);
  }
  int le = 0, ri = stk.size() - 2;
  while (le + 1 < ri) {
    int mi = (le + ri) >> 1;
    if (typ == 1)
      if (sum[stk[mi + 1] - 1] - sum[stk[mi] - 1] <=
          1ll * k * (stk[mi + 1] - stk[mi]))
        le = mi;
      else
        ri = mi;
    else if (sum[stk[mi + 1]] - sum[stk[mi]] >=
             1ll * k * (stk[mi + 1] - stk[mi]))
      ri = mi;
    else
      le = mi;
  }
  if (typ == 1)
    return max(max(Calc1(stk[le], k), Calc1(stk[ri], k)),
               Calc1(stk[ri + 1], k));
  else
    return max(max(Calc2(stk[le], k), Calc2(stk[ri], k)),
               Calc2(stk[ri + 1], k));
}
int main() {
  Read(n);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + Read(num[i]);
  for (int i = 1; i <= n; i++) org += 1ll * i * num[i];
  long long ovr = 0;
  for (int i = 1; i <= n; i++) {
    while (stk.size() > 1 &&
           (sum[stk[0] - 1] - sum[stk[1] - 1]) * (i - stk[0]) >=
               (sum[i - 1] - sum[stk[0] - 1]) * (stk[0] - stk[1]))
      stk.pop();
    stk.push(i);
    ovr = max(ovr, Query(num[i], 1) - 1ll * i * num[i] + sum[i - 1]);
  }
  stk.clear();
  for (int i = n; i >= 1; i--) {
    while (stk.size() > 1 && (sum[stk[1]] - sum[stk[0]]) * (stk[0] - i) <=
                                 (sum[stk[0]] - sum[i]) * (stk[1] - stk[0]))
      stk.pop();
    stk.push(i);
    ovr = max(ovr, Query(num[i], 2) - 1ll * i * num[i] + sum[i]);
  }
  printf("%lld\n", org + ovr);
  return 0;
}
