#include <bits/stdc++.h>
using namespace std;
const int MAX = 1100;
const long long oo = 1LL << 50;
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 add(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 query(long long x) {
    auto l = *lower_bound((Line){x, is_query});
    return l.m * x + l.b;
  }
};
const int N = 2e5 + 100;
long long a[N];
long long pre[N];
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  HullDynamic ch;
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = pre[i - 1] + a[i];
    tot += a[i] * i;
  }
  long long res = tot;
  ch.add(n, -pre[n]);
  for (int i = n - 1; i >= 1; i--) {
    long long val = ch.query(a[i]) - a[i] * i + pre[i];
    res = max(res, tot + val);
    ch.add(i, -pre[i]);
  }
  ch.clear();
  ch.add(1, -pre[1 - 1]);
  for (int i = 2; i <= n; i++) {
    long long val = ch.query(a[i]) + pre[i - 1] - a[i] * i;
    res = max(res, tot + val);
    ch.add(i, -pre[i - 1]);
  }
  cout << res << '\n';
}
