#include <bits/stdc++.h>
using namespace std;
bool Q;
struct Line {
  mutable long long k, m, p;
  bool operator<(const Line& o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<Line> {
  const long long inf = LLONG_MAX;
  long long div(long long a, long long b) {
    return a / b - ((a ^ b) < 0 && a % b);
  }
  bool isect(iterator x, iterator y) {
    if (y == end()) {
      x->p = inf;
      return false;
    }
    if (x->k == y->k)
      x->p = x->m > y->m ? inf : -inf;
    else
      x->p = div(y->m - x->m, x->k - y->k);
    return x->p >= y->p;
  }
  void add(long long k, long long m) {
    auto z = insert({k, m, 0}), y = z++, x = y;
    while (isect(y, z)) z = erase(z);
    if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
    while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y));
  }
  long long query(long long x) {
    assert(!empty());
    Q = 1;
    auto l = *lower_bound({0, 0, x});
    Q = 0;
    return l.k * x + l.m;
  }
};
long long solve(const vector<int>& a, int n) {
  vector<long long> p(n + 1);
  for (int i = 1; i <= n; i++) {
    p[i] = p[i - 1] + a[i];
  }
  vector<long long> q(n + 1);
  q[n] = a[n];
  for (int i = n - 1; i >= 1; i--) {
    q[i] = q[i + 1] + a[i];
  }
  vector<long long> b1(n + 1), b2(n + 1);
  LineContainer lc1;
  lc1.add(1, q[1]);
  for (int i = 2; i <= n; i++) {
    long long cur = (long long)a[i] * (long long)i + q[i];
    b1[i] = lc1.query(a[i]) - cur;
    lc1.add(i, q[i]);
  }
  LineContainer lc2;
  lc2.add(n, -p[n]);
  for (int i = n - 1; i >= 1; i--) {
    long long cur = (long long)a[i] * (long long)i - p[i];
    b2[i] = lc2.query(a[i]) - cur;
    lc2.add(i, -p[i]);
  }
  long long best = 0;
  for (int i = 1; i <= n; i++) {
    best = max(best, max(b1[i], b2[i]));
  }
  return best;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long tot = 0;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    tot += (long long)a[i] * (long long)i;
  }
  long long best = solve(a, n);
  cout << tot + best << endl;
  return 0;
}
