#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Node {
  long long x, y;
} P[N];
int n, cnt;
long long sum[N], val[N], ans;
void Clear() {
  cnt = 0;
  memset(P, 0, sizeof(P));
}
void Init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%I64d", &val[i]), sum[i] = sum[i - 1] + val[i];
}
bool Best(Node p, Node p1, Node p2) {
  long long f1 = (p.y - p1.y) * (p1.x - p2.x);
  long long f2 = (p1.y - p2.y) * (p.x - p1.x);
  return f1 <= f2;
}
long long Getval(int x, long long val) { return val * P[x].x - P[x].y; }
long long Query(long long val) {
  int l = 1, r = cnt;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (mid + 1 <= cnt && Getval(mid, val) <= Getval(mid + 1, val))
      l = mid + 1;
    else
      r = mid - 1;
  }
  return Getval(l, val);
}
long long Query2(long long val) {
  int l = 1, r = cnt;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (mid + 1 <= cnt && Getval(mid, val) >= Getval(mid + 1, val))
      l = mid + 1;
    else
      r = mid - 1;
  }
  return Getval(l, val);
}
void Add(long long x, long long y) {
  Node p = (Node){x, y};
  while (cnt >= 2 && Best(p, P[cnt], P[cnt - 1])) cnt--;
  P[++cnt] = p;
}
void Solve() {
  for (int i = 1; i <= n; ++i) ans += val[i] * i;
  long long dans = 0ll;
  Clear();
  for (int i = 1; i <= n; ++i) {
    Add(i, sum[i - 1]);
    dans = ((dans > Query(val[i]) - val[i] * i + sum[i - 1])
                ? (dans)
                : (Query(val[i]) - val[i] * i + sum[i - 1]));
  }
  Clear();
  for (int i = n; i >= 1; --i) {
    Add(i, -sum[i]);
    dans = ((dans > -Query2(-val[i]) - val[i] * i + sum[i])
                ? (dans)
                : (-Query2(-val[i]) - val[i] * i + sum[i]));
  }
  printf("%I64d\n", ans + dans);
}
int main() {
  Init();
  Solve();
  return 0;
}
