#include <bits/stdc++.h>
using namespace std;
const int Len = 2333333;
char buf[Len], *p1 = buf, *p2 = buf, duf[Len], *q1 = duf;
inline char gc();
inline int rd();
inline void pc(char c);
inline void rt(long long x);
inline void flush();
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
int n, tp = 1, q[200005], a[200005];
long long Ans, ans, s[200005];
int main() {
  n = rd(), q[1] = 1;
  for (register int i = 1; i <= n; ++i)
    a[i] = rd(), s[i] = s[i - 1] + a[i], Ans += 1ll * i * a[i];
  for (register int i = 2; i <= n; ++i) {
    int l = 2, r = tp, ts = 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (s[q[mid] - 1] - s[q[mid - 1] - 1] <=
          1ll * a[i] * (q[mid] - q[mid - 1]))
        ts = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    int j = q[ts];
    ans = Max(ans, s[i - 1] - s[j - 1] - 1ll * a[i] * (i - j));
    while (tp > 1 &&
           1ll * (s[i - 1] - s[q[tp - 1] - 1]) * (q[tp] - q[tp - 1]) <=
               1ll * (s[q[tp] - 1] - s[q[tp - 1] - 1]) * (i - q[tp - 1]))
      --tp;
    q[++tp] = i;
  }
  q[tp = 1] = n;
  for (register int i = n - 1; i >= 1; --i) {
    int l = 1, r = tp - 1, ts = tp;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (s[q[mid]] - s[q[mid + 1]] <= 1ll * a[i] * (q[mid] - q[mid + 1]))
        ts = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    int j = q[ts];
    ans = Max(ans, s[i] - s[j] + 1ll * a[i] * (j - i));
    while (tp > 1 && 1ll * (s[q[tp - 1]] - s[i]) * (q[tp - 1] - q[tp]) >=
                         1ll * (s[q[tp - 1]] - s[q[tp]]) * (q[tp - 1] - i))
      --tp;
    q[++tp] = i;
  }
  rt(Ans + ans);
  return flush(), 0;
}
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, Len, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline int rd() {
  char c;
  while (!isdigit(c = gc()) && c != '-')
    ;
  int f = c == '-' ? c = gc(), 1 : 0, x = c ^ 48;
  while (isdigit(c = gc())) x = ((x + (x << 2)) << 1) + (c ^ 48);
  return f ? -x : x;
}
inline void pc(char c) {
  q1 == duf + Len &&fwrite(q1 = duf, 1, Len, stdout), *q1++ = c;
}
inline void rt(long long x) {
  x < 0 ? pc('-'), x = -x : 0, pc((x >= 10 ? rt(x / 10), x % 10 : x) + 48);
}
inline void flush() { fwrite(duf, 1, q1 - duf, stdout); }
