#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;
int n, a[N], top;
long long s[N], ans, res;
struct point {
  int x;
  long long y;
  inline point operator-(const point& rhs) const {
    return (point){x - rhs.x, y - rhs.y};
  }
  inline long long get(int k) { return (long long)k * x + y; }
} sta[N];
inline long long cross(const point& a, const point& b) {
  return a.x * b.y - a.y * b.x;
}
void insert(point a) {
  while (top > 1 && cross(a - sta[top - 1], sta[top] - sta[top - 1]) <= 0)
    --top;
  sta[++top] = a;
}
void insert_(point a) {
  while (top > 1 && cross(a - sta[top - 1], sta[top] - sta[top - 1]) >= 0)
    --top;
  sta[++top] = a;
}
long long query(int k) {
  int l = 2, r = top, ans = 1;
  while (l <= r) {
    const int mid = (l + r) / 2;
    long long x = sta[mid - 1].get(k), y = sta[mid].get(k);
    if (x < y)
      l = (ans = mid) + 1;
    else
      r = mid - 1;
  }
  return sta[ans].get(k);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i), s[i] = s[i - 1] + a[i], res += (long long)i * a[i];
  ans = res;
  for (int i = 2; i <= n; ++i) {
    insert((point){i - 1, -s[i - 2]});
    ans = max(ans, res + query(a[i]) - (long long)a[i] * i + s[i - 1]);
  }
  top = 0;
  for (int i = n - 1; i; --i) {
    insert_((point){i + 1, -s[i + 1]});
    ans = max(ans, res + query(a[i]) - (long long)a[i] * i + s[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
