#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
struct Line {
  long long k, b;
  long long get(long long x) { return k * x + b; }
};
int n;
long long delta = 0, pref[N], a[N];
struct ConvexHull {
  int sz;
  Line *hull;
  ConvexHull(int MX) {
    hull = new Line[MX];
    sz = 0;
  }
  bool bad1(Line p, Line c, Line n) {
    return (n.b - p.b) * (p.k - c.k) <= (p.k - n.k) * (c.b - p.b);
  }
  void add(long long k, long long b) {
    Line next = (Line){k, b};
    while (sz > 1 && bad1(hull[sz - 2], hull[sz - 1], next)) sz--;
    hull[sz++] = next;
  }
  long long calc(long long x) {
    int l = -1, r = sz - 1;
    while (r - l > 1) {
      int m = (l + r) >> 1;
      if (hull[m].get(x) <= hull[m + 1].get(x))
        l = m;
      else
        r = m;
    }
    return hull[r].get(x);
  }
};
ConvexHull *ss;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  ConvexHull *ss = new ConvexHull(n);
  for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
  ss->add(1, 0);
  for (int i = 2; i <= n; ++i) {
    delta = max(delta, ss->calc(a[i]) + pref[i - 1] - a[i] * i);
    ss->add(i, -pref[i - 1]);
  }
  ss->sz = 0;
  ss->add(-n, -pref[n]);
  for (int i = n - 1; i >= 1; --i) {
    delta = max(delta, ss->calc(-a[i]) - a[i] * i + pref[i]);
    ss->add(-i, -pref[i]);
  }
  long long ret = 0;
  for (int i = 1; i <= n; ++i) ret += a[i] * i;
  cout << ret + delta;
  return 0;
}
