#include <bits/stdc++.h>
using namespace std;
struct Point {
  long long x, y;
  Point() {}
  Point(long long _x, long long _y) : x(_x), y(_y) {}
  Point operator-(const Point &t) const { return Point(x - t.x, y - t.y); }
  long long operator*(const Point &t) const { return x * t.y - y * t.x; }
} p[200005], q[200005];
int r, n;
long long a[200005];
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    p[i] = Point(i, p[i - 1].y + a[i]);
    sum += a[i] * i;
  }
  long long ans = 0;
  r = 0;
  for (int i = n; i >= 1; --i) {
    while (r > 1 && (p[i] - q[r]) * (q[r] - q[r - 1]) <= 0) --r;
    ++r;
    q[r] = p[i];
    int lef, rig;
    lef = 1;
    rig = r;
    while (lef < rig) {
      int m1 = (2 * lef + rig) / 3;
      int m2 = (lef + 2 * rig + 2) / 3;
      if (q[m2].y - q[m1].y < q[m2].x * a[i] - q[m1].x * a[i])
        lef = m1 + 1;
      else
        rig = m2 - 1;
    }
    ans = max(ans, a[i] * q[lef].x - a[i] * i - q[lef].y + p[i].y);
  }
  r = 0;
  for (int i = 1; i <= n; ++i) {
    while (r > 1 && (p[i - 1] - q[r]) * (q[r] - q[r - 1]) >= 0) --r;
    ++r;
    q[r] = p[i - 1];
    int lef, rig;
    lef = 1;
    rig = r;
    while (lef < rig) {
      int m1 = (2 * lef + rig) / 3;
      int m2 = (lef + 2 * rig + 2) / 3;
      if (a[i] * q[m1].x - q[m1].y < a[i] * q[m2].x - q[m2].y)
        lef = m1 + 1;
      else
        rig = m2 - 1;
    }
    ans = max(ans, a[i] * q[lef].x - q[lef].y + p[i - 1].y - (i - 1) * a[i]);
  }
  ans += sum;
  printf("%I64d\n", ans);
  return 0;
}
