#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25;
long long f[N], s[N], a[N], res;
int n;
deque<pair<long long, long long> > dq;
bool ok(pair<long long, long long> x, pair<long long, long long> y,
        pair<long long, long long> z) {
  return ((x.second - y.second) * (z.first - y.first) >
          (y.first - x.first) * (y.second - z.second));
}
void add(pair<long long, long long> x) {
  while (dq.size() > 1 && !ok(x, dq[dq.size() - 1], dq[dq.size() - 2]))
    dq.pop_back();
  dq.push_back(x);
}
long long cal(int m, int x) { return dq[m].first * x + dq[m].second; }
long long query(int x) {
  if (dq.size() == 1) return cal(0, x);
  int l = 0, r = dq.size() - 2;
  while (l < r) {
    int m = (l + r) >> 1;
    if (cal(m, x) < cal(m + 1, x))
      l = m + 1;
    else
      r = m;
  }
  return max(cal(l, x), cal(l + 1, x));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    f[i] = f[i - 1] + a[i] * i;
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i <= n; ++i) add(pair<long long, long long>(i, -s[i - 1]));
  for (int i = 1; i <= n; ++i) {
    res = max(res, query(a[i]) + s[i - 1] - a[i] * i);
  }
  dq.clear();
  for (int i = 1; i <= n; ++i) add(pair<long long, long long>(i, -s[i]));
  for (int i = 1; i <= n; ++i) {
    res = max(res, query(a[i]) + s[i] - a[i] * i);
  }
  cout << res + f[n];
}
