#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &s) {
  s = 0;
  char ch = getchar();
  bool flag = 0;
  while (!isdigit(ch)) flag = ch == '-' ? 1 : flag, ch = getchar();
  while (isdigit(ch)) s = ((s + (s << 2)) << 1) + ch - '0', ch = getchar();
  s = flag ? -s : s;
}
int n, A[210000], Q[210000], s, e;
long long Sum[210000], Pre, ans;
inline long long Get_y(int a, int b) { return Sum[a] - Sum[b]; }
inline long long Get_x(int a, int b) { return b - a; }
inline int Find(int k) {
  int l = s, r = e - 1, mid, Tmp = Q[e];
  while (l <= r) {
    mid = l + r >> 1;
    if (Get_y(Q[mid], Q[mid + 1]) > k * Get_x(Q[mid], Q[mid + 1]))
      l = mid + 1;
    else
      r = mid - 1, Tmp = Q[mid];
  }
  return Tmp;
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i)
    read(A[i]), Sum[i] = Sum[i - 1] + A[i], Pre = Pre + 1ll * i * A[i];
  Q[e = s = 1] = 0;
  for (int i = 1, now; i <= n; ++i) {
    now = Find(-A[i]),
    ans = max(ans, Sum[i] - Sum[now] - 1ll * (i - now) * A[i]);
    while (e > s && Get_y(Q[e - 1], Q[e]) * Get_x(Q[e - 1], i) <=
                        Get_x(Q[e - 1], Q[e]) * Get_y(Q[e - 1], i))
      --e;
    Q[++e] = i;
  }
  Q[s = e = n + 1] = n + 1;
  for (int i = n + 1; i >= 1; --i) Sum[i] = Sum[i - 1];
  for (int i = n, now; i >= 1; --i) {
    now = Find(-A[i]),
    ans = max(ans, Sum[i] - Sum[now] - 1ll * (i - now) * A[i]);
    while (e > s && Get_y(Q[s], Q[s + 1]) * Get_x(i, Q[s + 1]) >=
                        Get_x(Q[s], Q[s + 1]) * Get_y(i, Q[s + 1]))
      ++s;
    Q[--s] = i;
  }
  printf("%lld\n", Pre + ans);
  return 0;
}
