#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int nextInt() {
  int n;
  scanf("%d", &n);
  return n;
}
const long long is_query = -(1LL << 62);
struct Line {
  long long m, b;
  mutable function<const Line*()> succ;
  bool operator<(const Line& rhs) const {
    if (rhs.b != is_query) return m < rhs.m;
    const Line* s = succ();
    if (!s) return 0;
    long long x = rhs.m;
    return b - s->b < (s->m - m) * x;
  }
};
struct HullDynamic : public 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 (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);
  }
  void insert_line(long long m, long long b) {
    auto y = insert({m, b});
    y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
    if (bad(y)) {
      erase(y);
      return;
    }
    while (next(y) != end() && bad(next(y))) erase(next(y));
    while (y != begin() && bad(prev(y))) erase(prev(y));
  }
  long long eval(long long x) {
    auto l = *lower_bound((Line){x, is_query});
    return l.m * x + l.b;
  }
};
HullDynamic cht_1, cht_2;
const int maxn = (int)2e5 + 50;
long long sum[maxn], a[maxn];
int main() {
  int n = nextInt();
  long long res = 0, mx = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = nextInt();
    sum[i] = sum[i - 1] + a[i];
    res += a[i] * i;
  }
  for (int r = 1; r <= n; r++) {
    cht_1.insert_line(r, -sum[r - 1]);
  }
  for (int r = 1; r <= n; r++) {
    mx = max(mx, cht_1.eval(a[r]) + sum[r - 1] - a[r] * r);
  }
  for (int l = 1; l <= n; l++) {
    cht_2.insert_line(l, -sum[l]);
  }
  for (int l = 1; l <= n; l++) {
    mx = max(mx, cht_2.eval(a[l]) + sum[l] - a[l] * l);
  }
  cout << res + mx << endl;
  return 0;
}
