#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N];
long long s[N], sum;
void Enter() {
  scanf("%d", &n);
  for (int i = 1, b_ = n; i <= b_; ++i)
    scanf("%d", &a[i]), s[i] = s[i - 1] + a[i], sum += 1ll * i * a[i];
}
pair<long long, long long> cht[N];
int top;
double b[N];
double CutPoint(pair<long long, long long> x, pair<long long, long long> y) {
  return 1.0 * (y.second - x.second) / (x.first - y.first);
}
int Find1(long long x) {
  int l = 1, r = top, mid, pos = 1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (b[mid] <= x)
      pos = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return pos;
}
int Find2(long long x) {
  int l = 1, r = top, mid, pos = 1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (b[mid] <= x)
      pos = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return pos;
}
void Apps() {
  long long w, j, res = 0;
  pair<long long, long long> li;
  top = 1;
  cht[1] = {n, -s[n]};
  b[1] = -10000000000000000;
  for (int i = n - 1, b_ = 1; i >= b_; --i) {
    j = Find1(a[i]);
    w = cht[j].first * a[i] + cht[j].second - 1ll * i * a[i] + s[i];
    res = max(res, w);
    li = {i, -s[i]};
    while (top >= 2 &&
           CutPoint(cht[top - 1], cht[top]) <= CutPoint(cht[top], li))
      top--;
    cht[++top] = li;
    b[top - 1] = CutPoint(cht[top - 1], cht[top]);
    b[top] = -10000000000000000;
  }
  top = 1;
  cht[1] = {1, -s[0]};
  b[1] = -10000000000000000;
  for (int i = 2, b_ = n; i <= b_; ++i) {
    j = Find2(a[i]);
    w = cht[j].first * a[i] + cht[j].second - 1ll * i * a[i] + s[i - 1];
    res = max(res, w);
    li = {i, -s[i - 1]};
    while (top >= 2 &&
           CutPoint(cht[top - 1], cht[top]) >= CutPoint(cht[top], li))
      top--;
    cht[++top] = li;
    b[top] = CutPoint(cht[top - 1], cht[top]);
  }
  cout << res + sum;
}
int main() {
  Enter();
  Apps();
}
