#include <bits/stdc++.h>
using namespace std;
const int MAXN = (2e5) + 1;
struct hull {
  struct line {
    long long m, c;
    line(long long mm, long long cc) { m = mm, c = cc; }
    long long getVal(long long x) { return m * x + c; }
  };
  vector<line> st;
  bool bad(line l1, line l2, line l3) {
    return (l3.c - l1.c) * (l1.m - l2.m) < (l2.c - l1.c) * (l1.m - l3.m);
  }
  void add(long long m, long long c) {
    while (st.size() > 1 &&
           bad(st[st.size() - 2], st[st.size() - 1], line(m, c)))
      st.pop_back();
    st.push_back(line(m, c));
  }
  long long getMax(long long x) {
    int l = 0, r = st.size() - 1;
    while (r - l > 1) {
      int mid = l + r >> 1;
      if (st[mid].getVal(x) >= st[mid + 1].getVal(x))
        r = mid;
      else
        l = mid;
    }
    return max(st[l].getVal(x), st[r].getVal(x));
  }
} hull;
int n, a[MAXN];
long long ans, s1[MAXN], s2[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s1[i] = s1[i - 1] + a[i];
    s2[i] = s2[i - 1] + 1ll * a[i] * i;
  }
  ans = s2[n];
  for (int r = 1; r <= n; r++) {
    hull.add(r, -s1[r - 1]);
    ans = max(hull.getMax(a[r]) + s1[r - 1] + s2[n] - 1ll * r * a[r], ans);
  }
  hull.st.clear();
  for (int l = n; l >= 1; l--) {
    hull.add(-l, -s1[l]);
    ans = max(hull.getMax(-a[l]) + s1[l] + s2[n] - 1ll * l * a[l], ans);
  }
  cout << ans;
}
