#include <bits/stdc++.h>
using namespace std;
bool query = 0;
struct line {
  long long m, b;
  mutable function<const line*()> succ;
  bool operator<(const line rhs) const {
    if (!query) return (m < rhs.m);
    const line* s = succ();
    return s ? (b - s->b) < (rhs.m * (s->m - m)) : 0;
  }
};
struct hull : multiset<line> {
  bool bad(iterator y) {
    auto z = next(y);
    if (y == begin()) {
      if (z == end()) return 0;
      return (y->m == z->m) && (y->b <= z->b);
    }
    auto x = prev(y);
    if (z == end()) return (y->m == x->m) && (y->b <= x->b);
    return (1.0) * (x->b - y->b) * (z->m - y->m) >=
           (1.0) * (y->b - z->b) * (y->m - x->m);
  }
  void add(long long m, long long b) {
    auto it = insert({m, b});
    it->succ = [=] { return (next(it) == end()) ? 0 : &*next(it); };
    if (bad(it)) {
      erase(it);
      return;
    }
    while (next(it) != end() && bad(next(it))) erase(next(it));
    while (it != begin() && bad(prev(it))) erase(prev(it));
  }
  long long eval(long long x) {
    query = 1;
    line l = *lower_bound({x, 0});
    query = 0;
    return (l.m * x + l.b);
  }
};
hull h;
int N;
int A[200005];
long long SumA[200005];
long long SumAi[200005];
long long Solve() {
  for (int i = 1; i <= N; i++) {
    SumA[i] = SumA[i - 1] + A[i];
    SumAi[i] = SumAi[i - 1] + (1LL * A[i] * i);
  }
  long long Ans = -9e18;
  for (int i = 1; i <= N; i++) {
    h.add(-i, -SumA[i - 1]);
    Ans = max(Ans, h.eval(-A[i]) - 1LL * A[i] * i + SumA[i - 1] + SumAi[N]);
  }
  h.clear();
  for (int i = N; i; i--) {
    h.add(i, -SumA[i]);
    Ans = max(Ans, h.eval(A[i]) - 1LL * A[i] * i + SumA[i] + SumAi[N]);
  }
  return Ans;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
  printf("%I64d\n", Solve());
}
