#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
struct line {
  long long m, c;
  long long operator()(long long x) { return m * x + c; }
} Lichao[8 * N];
void init() {
  for (int i = 0; i < 8 * N; ++i) Lichao[i].m = -1;
}
void insert(int v, int l, int r, line seg) {
  if (Lichao[v].m == -1) {
    Lichao[v] = seg;
    return;
  }
  if (l + 1 == r) {
    if (seg(l) > Lichao[v](l)) Lichao[v] = seg;
    return;
  }
  int mid = (l + r) >> 1, lson = v * 2, rson = v * 2 + 1;
  if (Lichao[v].m > seg.m) swap(Lichao[v], seg);
  if (Lichao[v](mid) < seg(mid)) {
    swap(Lichao[v], seg);
    insert(lson, l, mid, seg);
  } else
    insert(rson, mid, r, seg);
}
long long query(int v, int l, int r, int x) {
  if (Lichao[v].m == -1) {
    return -1e18;
  }
  if (l + 1 == r) return Lichao[v](x);
  int mid = (l + r) >> 1, lson = v * 2, rson = v * 2 + 1;
  if (x < mid)
    return max(Lichao[v](x), query(lson, l, mid, x));
  else
    return max(Lichao[v](x), query(rson, mid, r, x));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n + 1];
  long long pre[n + 1], second = 0, ans = 0;
  pre[0] = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i + 1];
    second += (i + 1) * 1ll * (a[i + 1]);
    pre[i + 1] = pre[i] + a[i + 1];
  }
  ans = second;
  init();
  for (int i = 0; i < n; ++i) {
    if (i) {
      long long eval = query(1, -N, N, a[i + 1]);
      ans = max(ans, second + pre[i] - (i + 1) * 1ll * a[i + 1] + eval);
    }
    line temp;
    temp.m = (i + 1);
    temp.c = -pre[i];
    if (i != n - 1) insert(1, -N, N, temp);
  }
  init();
  for (int i = n - 1; i >= 0; --i) {
    if (i != n - 1) {
      long long eval = query(1, -N, N, a[i + 1]);
      ans = max(ans, second + pre[i + 1] - (i + 1) * 1ll * a[i + 1] + eval);
    }
    line temp;
    temp.m = (i + 1);
    temp.c = -pre[i + 1];
    if (i) insert(1, -N, N, temp);
  }
  cout << ans;
  return 0;
}
