#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
using P = pair<ll, ll>;
struct CHTrick {
  deque<P> lines;
  bool isMonoticX = false;
  CHTrick(bool flag = false) { isMonoticX = flag; }
  bool check(P l1, P l2, P l3) {
    return (long double)(l3.second - l2.second) * (l2.first - l1.first) >=
           (long double)(l2.second - l1.second) * (l3.first - l2.first);
  }
  void add(ll a, ll b) {
    if (lines.size() > 0 && lines.back().first == a) {
      b = max(b, lines.back().second);
      lines.pop_back();
    }
    P line(a, b);
    while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line)) {
      lines.pop_back();
    }
    lines.push_back(line);
  }
  ll f(int i, ll x) { return lines[i].first * x + lines[i].second; }
  ll f(P line, ll x) { return line.first * x + line.second; }
  bool comp(ll lv, ll rv) { return lv <= rv; }
  ll get(ll x) {
    if (isMonoticX) {
      while (lines.size() >= 2 && comp(f(0, x), f(1, x))) {
        lines.pop_front();
      }
      return f(0, x);
    } else {
      int low = -1, high = lines.size() - 1;
      while (high - low > 1) {
        int mid = (high + low) / 2;
        if (comp(f(mid, x), f(mid + 1, x)))
          low = mid;
        else
          high = mid;
      }
      return f(high, x);
    }
  }
};
int main() {
  int n;
  scanf(" %d", &n);
  vector<ll> a(n + 1);
  for (int(i) = 0; (i) < (int)(n); ++(i)) scanf(" %lld", &a[i + 1]);
  vector<ll> sum(a);
  for (int(i) = 0; (i) < (int)(n); ++(i)) sum[i + 1] += sum[i];
  ll c_def = 0;
  for (ll i = 1; i <= n; ++i) c_def += a[i] * i;
  ll mx = 0;
  CHTrick mvL;
  mvL.add(-n, -sum[n]);
  for (ll i = n - 1; i > 0; --i) {
    ll v = mvL.get(-a[i]) + sum[i] - a[i] * i;
    mx = max(mx, v);
    mvL.add(-i, -sum[i]);
  }
  CHTrick mvR;
  mvR.add(1, -sum[0]);
  for (ll i = 2; i <= n; ++i) {
    ll v = mvR.get(a[i]) + sum[i - 1] - a[i] * i;
    mx = max(mx, v);
    mvR.add(i, -sum[i - 1]);
  }
  printf("%lld\n", c_def + mx);
  return 0;
}
