#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct point {
  long long x, y;
  point(long long x = 0, long long y = 0) : x(x), y(y) {}
};
int a[maxn];
point st[maxn];
long long sum[maxn];
long long cross(const point &a, const point &b, const point &c) {
  return (a.y - b.y) * (b.x - c.x) - (b.y - c.y) * (a.x - b.x);
}
long long cal(const point &p, int k) { return p.x * k + p.y; }
int main() {
  int n;
  long long base = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    base += 1LL * a[i] * i;
  }
  long long ans = base;
  int top = 0;
  for (int i = 1; i <= n; ++i) {
    point p(i, -sum[i - 1]);
    while (top > 1 && cross(st[top - 2], st[top - 1], p) <= 0) --top;
    st[top++] = p;
    int l = 0, r = top - 1;
    while (r > l) {
      int m = (l + r) >> 1;
      if (cal(st[m], a[i]) >= cal(st[m + 1], a[i]))
        r = m;
      else
        l = m + 1;
    }
    ans = max(ans, base + cal(st[l], a[i]) + sum[i - 1] - 1LL * i * a[i]);
  }
  top = 0;
  for (int i = n; i; --i) {
    point p(i, -sum[i]);
    while (top > 1 && cross(st[top - 2], st[top - 1], p) >= 0) --top;
    st[top++] = p;
    int l = 0, r = top - 1;
    while (r > l) {
      int m = (l + r) >> 1;
      if (cal(st[m], a[i]) >= cal(st[m + 1], a[i]))
        r = m;
      else
        l = m + 1;
    }
    ans = max(ans, base + cal(st[l], a[i]) + sum[i] - 1LL * i * a[i]);
  }
  printf("%I64d\n", ans);
  return 0;
}
