#include <bits/stdc++.h>
using namespace std;
const int64_t Sz = 2e5 + 5;
const int64_t MX = 8e6 + 5;
struct Line {
  int64_t m, b;
  int64_t operator()(int64_t x) { return m * x + b; }
};
int64_t a[Sz];
int64_t Sum[Sz];
Line IT[MX];
int64_t n;
void update(int64_t vt, int64_t st, int64_t ed, Line li) {
  int64_t mid = ((st + MX) + (ed + MX)) / 2 - MX;
  bool lt = li(st) > IT[vt](st);
  bool mi = li(mid) > IT[vt](mid);
  if (mi) {
    swap(IT[vt], li);
  }
  if (st == ed) {
    return;
  }
  if (lt != mi) {
    update(2 * vt, st, mid, li);
  } else {
    update(2 * vt + 1, mid + 1, ed, li);
  }
}
int64_t query(int64_t vt, int64_t st, int64_t ed, int64_t x) {
  if (st == ed) {
    return IT[vt](x);
  }
  int64_t mid = ((st + MX) + (ed + MX)) / 2 - MX;
  if (x <= mid) {
    return max(IT[vt](x), query(2 * vt, st, mid, x));
  }
  return max(IT[vt](x), query(2 * vt + 1, mid + 1, ed, x));
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int64_t s = 0;
  cin >> n;
  for (int64_t i = 1; i <= n; i++) {
    cin >> a[i];
    Sum[i] = Sum[i - 1] + a[i];
    s += a[i] * i;
  }
  int64_t res = 0;
  for (int64_t i = n; i >= 1; i--) {
    Line x;
    x.m = i;
    x.b = -Sum[i];
    res = max(res, query(1, -1e6, 1e6, a[i]) + Sum[i] - a[i] * i);
    update(1, -1e6, 1e6, x);
  }
  for (int64_t i = 0; i < MX; i++) {
    IT[i].m = 0;
    IT[i].b = -2e9;
  }
  for (int64_t i = 1; i <= n; i++) {
    res = max(res, query(1, -1e6, 1e6, a[i]) + Sum[i - 1] - a[i] * i);
    Line val;
    val.m = i;
    val.b = -Sum[i - 1];
    update(1, -1e6, 1e6, val);
  }
  cout << res + s;
  return 0;
}
