#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int mod = 1e9 + 7;
int a[N], st[N], top;
long long pr[N];
int main() {
  auto calc = [&](int r1, int r2, int i) {
    return (pr[r2] - pr[r1]) * (i - r2) >= (pr[i] - pr[r2]) * (r2 - r1);
  };
  auto _fd = [&](int val) {
    int ans = 1, l = 2, r = top;
    while (l <= r) {
      int mid = l + r >> 1;
      int id1 = st[mid], id2 = st[mid - 1];
      if ((pr[id1] - pr[id2]) <= val * 1ll * (id1 - id2))
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    return st[ans];
  };
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) pr[i] = pr[i - 1] + a[i];
  long long sum = 0;
  for (int i = 1; i <= n; i++) sum += i * 1ll * a[i];
  top = 1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    while (top >= 2 && calc(st[top - 1], st[top], i)) top--;
    st[++top] = i;
  }
  for (int i = 1; i <= n; i++) {
    int x = _fd(a[i]);
    ans = max(ans, (x - i) * 1ll * a[i] + pr[i] - pr[x]);
  }
  cout << ans + sum;
}
