#include <bits/stdc++.h>
template <typename _T>
inline bool read(_T& x) {
  x = 0;
  _T y = 1;
  char c = getchar();
  while ((c < '0' || '9' < c) && c != EOF) {
    if (c == '-') y = -1;
    c = getchar();
  }
  if (c == EOF) return false;
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
  x *= y;
  return true;
}
int N, top;
long long k[3000007][2];
long long a[3000007], s[3000007];
long long p[3000007];
inline bool check(long long x) {
  return k[top][0] * (x - p[top]) <= (s[x] - s[p[top]]) * k[top][1];
}
inline void init() {
  p[++top] = 1;
  for (int i = 2; i <= N; ++i) {
    while (top > 1 && !check(i)) p[top] = 0, k[top][0] = k[top][1] = 0, top--;
    k[top + 1][0] = s[i] - s[p[top]];
    k[top + 1][1] = i - p[top];
    p[++top] = i;
  }
  k[1][0] = -1;
}
inline void solve() {
  long long res = 0, bs = 0;
  for (int i = 1; i <= N; ++i) bs += a[i] * i;
  res = bs;
  for (int i = 1; i <= N; ++i) {
    {
      int l = std::upper_bound(p + 1, p + top + 1, i) - p, r = top, mid,
          ans = -1;
      while (l <= r) {
        mid = l + r >> 1;
        if (k[mid][0] <= a[i] * k[mid][1])
          ans = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (ans != -1)
        res = std::max(
            res, bs + a[i] * (p[ans] - i) + (long long)(s[i] - s[p[ans]]));
    }
    {
      int l = 1, r = std::upper_bound(p + 1, p + top + 1, i) - p - 1, mid,
          ans = -1;
      while (l <= r) {
        mid = l + r >> 1;
        if (k[mid][0] <= a[i] * k[mid][1])
          ans = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      if (ans != -1) {
        res = std::max(res, bs + a[i] * (p[ans] + 1 - i) +
                                (long long)(s[i - 1] - s[p[ans]]));
        res = std::max(res, bs + a[i] * (p[ans] - i) +
                                (long long)(s[i - 1] - s[p[ans] - 1]));
      }
    }
  }
  printf("%lld\n", res);
}
int main() {
  read(N);
  for (int i = 1; i <= N; ++i) read(a[i]), s[i] = s[i - 1] + a[i];
  init();
  solve();
  return 0;
}
