#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;
const ll INF = 1e18;
using ld = long double;
int a[N];
ll pref[N];
struct line {
  ll k, b;
  ll f(ll x) { return k * x + b; }
};
ld inter(line a, line b) { return ld(b.b - a.b) / ld(a.k - b.k); }
line v[N];
int vl, vr;
void add(line a) {
  while (vr - vl > 1 && inter(v[vr - 1], v[vr - 2]) > inter(a, v[vr - 2])) vr--;
  v[vr++] = a;
  if (false) cerr << a.k << " " << a.b << " asd" << endl;
  for (int i = vl; i + 1 < vr; ++i) {
    if (false) cerr << inter(v[i], v[i + 1]) << " ";
  }
  if (false) cerr << endl;
  for (int i = vl; i < vr; ++i) {
    if (false) cerr << v[i].k << " " << v[i].b << " line\n";
  }
}
ll get(ll x) {
  if (vl >= vr) return -INF;
  if (vl + 1 == vr) return v[vl].f(x);
  if (0) {
    ll res = -INF;
    for (int i = vl; i < vr; ++i) {
      res = max(res, v[i].f(x));
    }
    return res;
  }
  int l = vl, r = vr - 2;
  ll res = -INF;
  while (l <= r) {
    int m = (l + r) / 2;
    for (int d = -50; d <= 50; ++d)
      if (d + m >= vl && d + m < vr) res = max(res, v[m + d].f(x));
    if (inter(v[m], v[m + 1]) >= ld(x)) {
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  res = max(res, v[vl].f(x));
  res = max(res, v[vr - 1].f(x));
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  ll start = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
    start += a[i] * 1ll * i;
  }
  ll mx = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
    }
    ll max_val = get(a[i]) + pref[i - 1] - a[i] * 1ll * i;
    mx = max(mx, max_val);
    add({i, -pref[i - 1]});
  }
  vl = vr = 0;
  for (int i = n; i >= 1; --i) {
    for (int j = i + 1; j <= n; ++j) {
    }
    ll max_val = get(-a[i]) + pref[i] - a[i] * 1ll * i;
    mx = max(mx, max_val);
    add({-i, -pref[i]});
  }
  cout << start + mx;
}
