#include <bits/stdc++.h>
int inp() {
  char c = getchar();
  int neg = 1;
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * neg;
}
struct Node {
  long long k;
  long long b;
  long long get(int x) { return x * k + b; }
} s[200010];
int top = 0;
long long sum[200010], a[200010];
void insert(Node x) {
  while (top > 1 && ((s[top].b - x.b) * (s[top].k - s[top - 1].k) <=
                     (s[top - 1].b - s[top].b) * (x.k - s[top].k)))
    top--;
  s[++top] = x;
}
long long query(long long x) {
  int l = 1;
  int r = top;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (s[mid].get(x) <= s[mid + 1].get(x))
      l = mid + 1;
    else
      r = mid;
  }
  return s[l].get(x);
}
int main() {
  int n = inp();
  for (int i = 1; i <= n; i++) {
    a[i] = inp();
    sum[i] = sum[i - 1] + a[i];
  }
  long long ans = 0;
  long long pre = 0;
  for (int i = 1; i <= n; i++) pre += (a[i] * (long long)i);
  for (int i = 2; i <= n; i++) {
    insert((Node){i - 1, -sum[i - 2]});
    ans = std::max(ans, query(a[i]) + sum[i - 1] - (a[i] * (long long)i));
  }
  top = 0;
  for (int i = n - 1; i >= 1; i--) {
    insert((Node){-i - 1, -sum[i + 1]});
    ans = std::max(ans, query(-a[i]) + sum[i] - (a[i] * (long long)i));
  }
  std::cout << ans + pre << std::endl;
}
