#include <bits/stdc++.h>
using namespace std;
const int Maxn = 400000 + 10;
struct Point {
  long long x, y;
  Point operator+(const Point &A) { return (Point){x + A.x, y + A.y}; }
  Point operator-(const Point &A) { return (Point){x - A.x, y - A.y}; }
} P[Maxn];
int n, A[Maxn], cnt;
long long sum[Maxn];
double CalCJ(Point A, Point B) { return A.x * B.y - A.y * B.x; }
bool OnLeft(Point P, Point A, Point B) { return CalCJ(B - A, P - A) > 0; }
bool OnRight(Point P, Point A, Point B) { return CalCJ(B - A, P - A) < 0; }
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (long long)A[i];
  long long ans = 0, tot;
  for (int i = 1; i <= n; i++) ans += (long long)A[i] * (long long)i;
  tot = ans;
  P[++cnt] = (Point){1, sum[0]};
  for (int i = 2; i <= n; i++) {
    Point C = (Point){1ll, (long long)A[i]};
    int l = 2, r = cnt + 1;
    P[cnt + 1] = (Point){n + 1, (0x3f3f3f3f) * 10ll};
    while (l < r) {
      int mid = ((l + r) >> 1);
      if (!OnRight(C + P[mid - 1], P[mid - 1], P[mid]))
        l = mid + 1;
      else
        r = mid;
    }
    l--;
    long long nans = tot - (long long)A[i] * (long long)i + sum[i - 1] +
                     P[l].x * (long long)A[i] - P[l].y;
    ans = ((ans) > (nans) ? (ans) : (nans));
    Point Q = (Point){(long long)i, sum[i - 1]};
    while (cnt > 1 && !OnLeft(Q, P[cnt - 1], P[cnt])) cnt--;
    P[++cnt] = Q;
  }
  P[cnt = 1] = (Point){n, sum[n]};
  for (int i = n - 1; i; i--) {
    Point C = (Point){1ll, (long long)A[i]};
    int l = 2, r = cnt + 1;
    P[cnt + 1] = (Point){0, (-0x3f3f3f3f) * 10ll};
    while (l < r) {
      int mid = ((l + r) >> 1);
      if (!OnLeft(P[mid - 1] - C, P[mid - 1], P[mid]))
        l = mid + 1;
      else
        r = mid;
    }
    l--;
    long long nans = tot + sum[i] - (long long)A[i] * (long long)i - P[l].y +
                     P[l].x * (long long)A[i];
    ans = ((ans) > (nans) ? (ans) : (nans));
    Point Q = (Point){(long long)i, sum[i]};
    while (cnt > 1 && !OnRight(Q, P[cnt - 1], P[cnt])) cnt--;
    P[++cnt] = Q;
  }
  printf("%I64d\n", ans);
}
int main() {
  solve();
  return 0;
}
