#include <bits/stdc++.h>
using namespace std;
class CHT {
 public:
  deque<pair<long long, long long> > Hull;
  long long type = 1;
  long long getVal(pair<long long, long long> a, long long x) {
    return a.first * x + a.second;
  }
  long long cmp(pair<long long, long long> a, pair<long long, long long> b,
                pair<long long, long long> c) {
    return (((b.second - c.second) * (b.first - a.first) <=
             (a.second - b.second) * (c.first - b.first)));
  }
  void insert(long long inc, long long y) {
    Hull.push_back({inc, y});
    int v;
    while ((v = Hull.size()) > 2 && cmp(Hull[v - 3], Hull[v - 2], Hull[v - 1]))
      Hull[v - 2] = Hull[v - 1], Hull.pop_back();
  }
  long long query(long long x) {
    int l = -1, r = Hull.size() - 1;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (getVal(Hull[m], x) <= getVal(Hull[m + 1], x))
        l = m;
      else
        r = m;
    }
    return getVal(Hull[r], x);
  }
  void print() {
    for (auto x : Hull) {
      cout << x.first << " " << x.second << endl;
    }
  }
};
long long n;
long long a[200010], second[200010];
long long ans = 0, t;
CHT c1, c2;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    t += i * a[i];
    second[i] = second[i - 1] + a[i];
  }
  c1.type = 0;
  c1.insert((long long)1, -second[0]);
  for (long long i = 2; i <= n; i++) {
    ans = max(ans, c1.query(a[i]) - i * a[i] + second[i - 1]);
    c1.insert(i, -second[i - 1]);
  }
  c2.type = 1;
  c2.insert(-n, -second[n]);
  for (long long i = n - 1; i >= 1; i--) {
    ans = max(ans, c2.query(-a[i]) - i * a[i] + second[i]);
    c2.insert(-i, -second[i]);
  }
  cout << ans + t << endl;
}
