#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
long long a[MAXN];
struct polygon_convex {
  vector<complex<long long> > p;
} res;
inline long long cross(const complex<long long>& a,
                       const complex<long long>& b) {
  return (conj(a) * b).imag();
}
long long calc(int i, int x) {
  return a[i] * res.p[x].real() - res.p[x].imag();
}
vector<complex<long long> > p;
long long solve() {
  res.p.resize(p.size() + 5);
  int m = 0, n = p.size() - 1;
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    while (m > 1 &&
           cross(p[i] - res.p[m - 1], res.p[m - 1] - res.p[m - 2]) <= 0)
      --m;
    res.p[m++] = p[i];
    int l = 0, r = m - 1;
    while (l < r) {
      int mid = (2 * l + r) / 3;
      int midd = (l + 2 * r + 2) / 3;
      if (calc(i, mid) < calc(i, midd)) {
        l = mid + 1;
      } else {
        r = midd - 1;
      }
    }
    ans = max(ans, calc(i, l) + p[i].imag() - i * a[i]);
  }
  m = 0;
  for (int i = 1; i <= n; i++) {
    while (m > 1 &&
           cross(p[i - 1] - res.p[m - 1], res.p[m - 1] - res.p[m - 2]) >= 0)
      --m;
    res.p[m++] = p[i - 1];
    int l = 0, r = m - 1;
    while (l < r) {
      int mid = (2 * l + r) / 3;
      int midd = (l + 2 * r + 2) / 3;
      if (calc(i, mid) < calc(i, midd)) {
        l = mid + 1;
      } else {
        r = midd - 1;
      }
    }
    ans = max(ans, calc(i, l) + p[i - 1].imag() - (i - 1) * a[i]);
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  p.push_back(complex<long long>(0, 0));
  long long ans = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    ans += a[i] * i;
    sum += a[i];
    p.push_back(complex<long long>(i, sum));
  }
  cout << ans + solve() << endl;
  return 0;
}
