#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
const int N = 2e5 + 5;
const int M = 1e6 + 3;
long long s, a[N], sum[N], b[N], k[N], mx;
int t[M << 4];
long long w(int pos, int x) { return k[x] * pos + b[x]; }
void updat(int ro, int l, int r, int x) {
  if (w(((l + r) >> 1), x) > w(((l + r) >> 1), t[ro])) swap(t[ro], x);
  if (l == r) return;
  if (w(l, x) > w(l, t[ro])) updat(ro << 1, l, ((l + r) >> 1), x);
  if (w(r, x) > w(r, t[ro])) updat(ro << 1 | 1, ((l + r) >> 1) + 1, r, x);
}
long long query(int ro, int l, int r, int x) {
  if (l == r) return w(x, t[ro]);
  return max(w(x, t[ro]),
             (x > ((l + r) >> 1) ? query(ro << 1 | 1, ((l + r) >> 1) + 1, r, x)
                                 : query(ro << 1, l, ((l + r) >> 1), x)));
}
void work() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]), sum[i] = sum[i - 1] + a[i], s += a[i] * i;
  b[0] = -1e18;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, sum[i - 1] - a[i] * i + query(1, -M, M, a[i]));
    k[i] = i, b[i] = -sum[i - 1];
    updat(1, -M, M, i);
  }
  memset(t, 0, sizeof(t));
  for (int i = n; i; i--) {
    mx = max(mx, sum[i] - i * a[i] + query(1, -1e6, 1e6, a[i]));
    k[i] = i, b[i] = -sum[i];
    updat(1, -1e6, 1e6, i);
  }
  printf("%lld", mx + s);
}
}  // namespace FGF
int main() {
  FGF::work();
  return 0;
}
