#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const long long INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
int n, q[MAXN], t;
long long a[MAXN], sum[MAXN], base;
inline long long trans1(int i, int j) {
  return sum[i - 1] - sum[j - 1] - a[i] * (i - j);
}
inline long long trans2(int i, int j) {
  return sum[i] - sum[j] + a[i] * (j - i);
}
inline bool check1(int i, int j, int k) {
  return (sum[i - 1] - sum[j - 1]) * (k - j) <
         (sum[j - 1] - sum[k - 1]) * (j - i);
}
inline bool check2(int i, int j, int k) {
  return (sum[j] - sum[i]) * (j - k) > (sum[k] - sum[j]) * (i - j);
}
void init() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
    sum[i] = sum[i - 1] + a[i];
    base += a[i] * i;
  }
}
void solve() {
  long long ans = base;
  q[t = 1] = 1;
  for (int i = 2; i <= n; ++i) {
    int l = 1, r = t - 1, p = t;
    while (l <= r) {
      int m = (l + r) >> 1;
      if (trans1(i, q[m]) >= trans1(i, q[m + 1])) {
        r = (p = m) - 1;
      } else {
        l = m + 1;
      }
    }
    cmax(ans, base + trans1(i, q[p]));
    while (t > 1 && check1(q[t - 1], q[t], i)) {
      --t;
    }
    q[++t] = i;
  }
  q[t = 1] = n;
  for (int i = n - 1; i >= 1; --i) {
    int l = 1, r = t - 1, p = t;
    while (l <= r) {
      int m = (l + r) >> 1;
      if (trans2(i, q[m]) >= trans2(i, q[m + 1])) {
        r = (p = m) - 1;
      } else {
        l = m + 1;
      }
    }
    cmax(ans, base + trans2(i, q[p]));
    while (t > 1 && check2(q[t - 1], q[t], i)) {
      --t;
    }
    q[++t] = i;
  }
  printf("%lld\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
