#include <bits/stdc++.h>
using namespace std;
struct line {
  long long m, c;
  line() { m = 1, c = -1e18; }
  line(long long a, long long b) {
    m = a;
    c = b;
  }
  long long gv(long long x) { return m * 1LL * x + c; }
};
int n;
long long a[200005];
long long sp[200005], p[200005];
long long Total = 0;
line ln[2000005 * 4];
int Cons = 1000000;
void build(int p, int s, int e) {
  ln[p] = line();
  if (s == e) {
    return;
  }
  int m = (s + e) / 2;
  build(p * 2 + 1, s, m);
  build(p * 2 + 2, m + 1, e);
}
void update(int p, int s, int e, line cl) {
  int m = (s + e) / 2;
  bool lef = cl.gv(s - Cons) > ln[p].gv(s - Cons);
  bool mid = cl.gv(m + 1 - Cons) > ln[p].gv(m + 1 - Cons);
  if (mid) {
    swap(cl, ln[p]);
  }
  if (s == e) {
    return;
  } else if (lef != mid) {
    update(p * 2 + 1, s, m, cl);
  } else {
    update(p * 2 + 2, m + 1, e, cl);
  }
}
void add(long long val, long long costpath) {
  update(0, 0, 2000000, line(val, costpath));
}
long long query(int p, int s, int e, int x) {
  if (s == e) {
    return ln[p].gv(x - Cons);
  }
  int m = (s + e) / 2;
  if (x <= m) {
    return max(ln[p].gv(x - Cons), query(p * 2 + 1, s, m, x));
  } else {
    return max(ln[p].gv(x - Cons), query(p * 2 + 2, m + 1, e, x));
  }
}
long long query(int x) { return query(0, 0, 2000000, x); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sp[i] = sp[i - 1] + a[i] * 1LL * i;
    p[i] = p[i - 1] + a[i];
  }
  Total = sp[n];
  long long ans = Total;
  build(0, 0, 2000000);
  for (int i = 1; i <= n; i++) {
    add(i, -p[i - 1]);
    ans = max(ans, Total + p[i - 1] - a[i] * 1LL * i + query(a[i] + Cons));
  }
  build(0, 0, 2000000);
  for (int i = n; i >= 1; i--) {
    add(i, -p[i]);
    ans = max(ans, Total + p[i] - a[i] * 1LL * i + query(a[i] + Cons));
  }
  printf("%lld\n", ans);
  return 0;
}
