#include <bits/stdc++.h>
using namespace std;
long long ara[200005], cumu[200005], sum[200005];
vector<long long> m, b;
bool bad(bool f, int f1, int f2, int f3) {
  if (!f)
    return (1.0 * (b[f1] - b[f3]) * (m[f2] - m[f1]) <=
            1.0 * (b[f1] - b[f2]) * (m[f3] - m[f1]));
  else
    return (1.0 * (b[f1] - b[f3]) * (m[f2] - m[f1]) >=
            1.0 * (b[f1] - b[f2]) * (m[f3] - m[f1]));
}
void add(bool f, long long _m, long long _b) {
  m.push_back(_m);
  b.push_back(_b);
  int sz = m.size();
  while (sz >= 3 && bad(f, sz - 3, sz - 2, sz - 1)) {
    long long t = m.back();
    m.pop_back();
    m.pop_back();
    m.push_back(t);
    t = b.back();
    b.pop_back();
    b.pop_back();
    b.push_back(t);
    sz--;
  }
  return;
}
long long eval(int i, long long x) { return m[i] * x + b[i]; }
long long query(long long x) {
  int lo = 0, hi = m.size() - 1;
  long long mx = LLONG_MIN;
  while (lo + 5 < hi) {
    int m1 = (lo + hi) / 2;
    int m2 = m1 + 1;
    long long y1 = eval(m1, x);
    long long y2 = eval(m2, x);
    if (y1 >= y2)
      mx = y1, hi = m1;
    else
      mx = y2, lo = m2;
  }
  for (int i = lo; i <= hi; i++) mx = max(mx, eval(i, x));
  return mx;
}
int main() {
  int n;
  scanf("%d", &n);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &ara[i]), sum[i] = sum[i - 1] + ara[i],
                            cumu[i] = cumu[i - 1] + i * ara[i];
  long long res = cumu[n];
  for (long long i = 1; i <= n; i++) {
    if (i != 1)
      res = max(res,
                cumu[n] - cumu[i] + cumu[i - 1] + sum[i - 1] + query(ara[i]));
    add(0, i, -sum[i - 1]);
  }
  m.clear();
  b.clear();
  for (long long i = n; i >= 1; i--) {
    if (i != n)
      res = max(res, cumu[i - 1] - cumu[i] + cumu[n] + sum[i] + query(ara[i]));
    add(1, i, -sum[i]);
  }
  printf("%lld\n", res);
  return 0;
}
