#include <bits/stdc++.h>
using namespace std;
struct line {
  long long s, t;
  line() {}
  line(long long ss, long long tt) { s = ss, t = tt; }
};
struct CHT {
  deque<line> dq;
  CHT() {}
  bool ck(line L1, line L2, line me) {
    return (double)(me.t - L1.t) / (L1.s - me.s) >=
           (double)(me.t - L2.t) / (L2.s - me.s);
  }
  double cross(line i, line j) { return (double)(i.t - j.t) / (j.s - i.s); }
  void push(line li, int flag) {
    if (flag)
      while (dq.size() > 1 && ck(dq[dq.size() - 2], dq.back(), li))
        dq.pop_back();
    else
      while (dq.size() > 1 && !ck(dq[dq.size() - 2], dq.back(), li))
        dq.pop_back();
    dq.push_back(li);
  }
  long long F(line li, long long x) { return li.s * x + li.t; }
  long long query(long long x) {
    int L = 0, R = dq.size() - 1;
    while (L + 3 < R) {
      int m1 = (2 * L + R) / 3, m2 = (L + 2 * R) / 3;
      if (F(dq[m1], x) > F(dq[m2], x))
        R = m2;
      else
        L = m1;
    }
    long long maxi = F(dq[L], x), ff = 0;
    for (int i = L + 1; i <= R; i++) {
      ff = F(dq[i], x);
      if (maxi < ff) maxi = ff;
    }
    return maxi;
  }
};
int n, a[200005];
long long sum[200005], lrdp[200005], rldp[200005], maxi, key;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    key += 1LL * a[i] * i;
  }
  CHT lrshift, rlshift;
  maxi = 0;
  for (int i = n - 1; i >= 1; i--) {
    lrshift.push(line(i + 1, -sum[i + 1]), 0);
    lrdp[i] = lrshift.query(a[i]) + sum[i] - 1LL * i * a[i];
    maxi = max(maxi, lrdp[i]);
  }
  for (int i = 2; i <= n; i++) {
    rlshift.push(line(i - 1, -sum[i - 2]), 1);
    rldp[i] = rlshift.query(a[i]) + sum[i - 1] - 1LL * i * a[i];
    maxi = max(maxi, rldp[i]);
  }
  printf("%I64d\n", maxi + key);
}
