#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC optimize(2)
const int N = 2e5 + 3;
long long i, j, n, l, r, fu, mid, a[N], ans, tmp, S[N];
char c;
inline void in(register long long &x) {
  fu = x = 0;
  c = getchar();
  while (c < '0' || c > '9') fu |= c == '-', c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x = fu ? -x : x;
}
inline long long max(register long long a, register long long b) {
  return a > b ? a : b;
}
inline long long ask(register long long i, register long long j) {
  return i > j ? (long long)(j - i) * a[i] + S[i - 1] - S[j - 1]
               : (long long)(j - i) * a[i] - S[j] + S[i];
}
int main() {
  in(n);
  for (i = 1; i <= n; ++i)
    in(a[i]), ans += (long long)i * a[i], S[i] = S[i - 1] + a[i];
  for (i = 1; i <= n; ++i) {
    l = 1, r = n;
    while (l < r) {
      mid = l + r >> 1;
      if (ask(i, mid) >= ask(i, mid + 1))
        r = mid;
      else
        l = mid + 1;
    }
    tmp = max(tmp, ask(i, l));
    l = 1, r = n;
    while (l < r) {
      mid = l + r + 1 >> 1;
      if (ask(i, mid) >= ask(i, mid - 1))
        l = mid;
      else
        r = mid - 1;
    }
    tmp = max(tmp, ask(i, l));
  }
  printf("%lld", ans + tmp);
}
