#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
long long a[N], prf[N];
long long res, sum;
struct Line {
  long long a, b;
  Line(long long a = 0, long long b = 0) : a(a), b(b) {}
};
bool bad(Line l1, Line l2, Line l3) {
  return (l1.b - l3.b) * (l2.a - l1.a) <= (l3.a - l1.a) * (l1.b - l2.b);
}
struct ConvexHullTrick {
  vector<Line> L;
  ConvexHullTrick() { L.clear(); }
  void add(Line l3) {
    while (L.size() >= 2 && bad(L[L.size() - 2], L[L.size() - 1], l3))
      L.pop_back();
    L.push_back(l3);
  }
  long long calc(int pos, long long x) {
    if (pos == L.size()) return (long long)4e18;
    return L[pos].a * x + L[pos].b;
  }
  long long get(long long x) {
    int l = 0, r = L.size() - 1;
    while (l < r) {
      int mid = l + r >> 1;
      if (calc(mid, x) <= calc(mid + 1, x))
        r = mid;
      else
        l = mid + 1;
    }
    return calc(l, x);
  }
} cht;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    prf[i] = prf[i - 1] + a[i];
    sum += a[i] * i;
  }
  cht = ConvexHullTrick();
  for (int i = 2; i <= n; ++i) {
    cht.add(Line(-i + 1, prf[i - 2]));
    res = max(res, prf[i - 1] - a[i] * i - cht.get(a[i]));
  }
  cht = ConvexHullTrick();
  for (int i = n - 1; i >= 1; --i) {
    cht.add(Line(i + 1, prf[i + 1]));
    res = max(res, prf[i] - a[i] * i - cht.get(-a[i]));
  }
  cout << res + sum << '\n';
}
