#include <bits/stdc++.h>
using namespace std;
struct Line {
  long long k, b;
  Line(long long k1 = 0, long long b1 = 0) {
    k = k1;
    b = b1;
  }
} line[200020];
int n, a[200020], top;
long long sum[200020], ans;
void print(long long x) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (x <= 1000000000)
    printf("%d\n", (int)x);
  else
    printf("%d%09d\n", (int)(x / 1000000000), (int)(x % 1000000000));
}
bool valid(int top, int per) {
  long long b2 = line[top].b - line[top - 1].b;
  long long k2 = line[top - 1].k - line[top].k;
  if (k2 < 0) k2 = -k2, b2 = -b2;
  long long b1 = line[top - 1].b - line[top - 2].b;
  long long k1 = line[top - 2].k - line[top - 1].k;
  if (k1 < 0) k1 = -k1, b1 = -b1;
  if (per == 0)
    return b2 * k1 > k2 * b1;
  else
    return b2 * k1 < k2 * b1;
}
long long binary(long long x, int per) {
  int l = 1, r = top;
  while (l < r) {
    int mid = (l + r) / 2;
    long long b2, k2;
    if (per == 0) {
      b2 = line[mid + 1].b - line[mid].b;
      k2 = line[mid].k - line[mid + 1].k;
    } else {
      b2 = line[(top + 1) - (mid + 1)].b - line[(top + 1) - (mid)].b;
      k2 = line[(top + 1) - (mid)].k - line[(top + 1) - (mid + 1)].k;
    }
    if (k2 < 0) k2 = -k2, b2 = -b2;
    if (x * k2 <= b2)
      r = mid;
    else
      l = mid + 1;
  }
  if (per == 0)
    return line[l].k * x + line[l].b;
  else
    return line[(top + 1) - l].k * x + line[(top + 1) - l].b;
}
int main() {
  scanf("%d", &n);
  sum[0] = 0;
  long long preans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    preans += (long long)a[i] * i;
  }
  ans = -1e18;
  top = 0;
  for (int i = 1; i <= n; i++) {
    line[++top] = Line(i, -sum[i - 1]);
    while (top > 2 && !valid(top, 0)) --top, line[top] = line[top + 1];
    long long now = binary(a[i], 0) + sum[i - 1] - (long long)a[i] * i + preans;
    if (now > ans) ans = now;
  }
  top = 0;
  for (int i = n; i >= 1; i--) {
    line[++top] = Line(i, -sum[i]);
    while (top > 2 && !valid(top, 1)) --top, line[top] = line[top + 1];
    long long now = binary(a[i], 1) + sum[i] - (long long)a[i] * i + preans;
    if (now > ans) ans = now;
  }
  print(ans);
  return 0;
}
