#include <bits/stdc++.h>
using namespace std;
struct line {
  long long int m, b;
};
long double intersectX(line X, line Y) {
  if (X.m == Y.m) return INT_MAX;
  return (double)(Y.b - X.b) / (double)(X.m - Y.m);
}
long long int eval(long long int x, line X) { return (X.m) * x + X.b; }
deque<line> st;
vector<long double> points;
void addline(line X) {
  if (st.empty()) {
    st.push_back(X);
    return;
  }
  if (st.size() == 1) {
    points.push_back(intersectX(X, st.back()));
    st.push_back(X);
    return;
  }
  while (points.size()) {
    line l2 = st.back();
    st.pop_back();
    line l1 = st.back();
    if (intersectX(X, l1) >= points.back()) {
      st.push_back(l2);
      break;
    } else {
      points.pop_back();
    }
  }
  points.push_back(intersectX(X, st.back()));
  st.push_back(X);
}
long long int findBest(long long int x) {
  long long int idx =
      lower_bound(points.begin(), points.end(), x) - points.begin();
  return eval(x, st[idx]);
}
long long int n, pre[200100], sum[200100], totalSum, a[200100];
void solve() {
  cin >> n;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    cin >> a[i];
  }
  pre[0] = 0, sum[0] = 0;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    sum[i] = sum[i - 1] + a[i];
    pre[i] = pre[i - 1] + a[i] * i;
  }
  line l;
  l.m = 1;
  l.b = 0;
  addline(l);
  totalSum = pre[n];
  long long int ans = totalSum;
  for (__typeof(n + 1) i = (2) - ((2) > (n + 1));
       i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {
    long long int loc =
        findBest(a[i]) + totalSum - pre[i] + pre[i - 1] + sum[i - 1];
    ans = max(ans, loc);
    l.m = i;
    l.b = -sum[i - 1];
    addline(l);
  }
  st.clear();
  points.clear();
  l.m = -n;
  l.b = -sum[n];
  addline(l);
  for (long long int i = n - 1; i >= 1; i--) {
    long long int loc =
        findBest(-a[i]) + totalSum + pre[i - 1] - pre[i] + sum[i];
    ans = max(ans, loc);
    l.m = -i;
    l.b = -sum[i];
    addline(l);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
