#include <bits/stdc++.h>
using namespace std;
long long a[200010];
long long pre[200010];
long long n, ans, le, ri, w1, w2, v1, v2, maxh, cor;
long long move(long long x, long long y) {
  if (x <= y)
    return ans - pre[y] + pre[x] + a[x] * (y - x);
  else
    return ans + pre[x - 1] - pre[y - 1] + a[x] * (y - x);
}
int main() {
  maxh = -9.223372037e+18;
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    pre[i] = pre[i - 1] + a[i];
    ans += a[i] * i;
  }
  for (int i = 1; i <= n; i++) {
    le = 1;
    ri = n;
    cor = -9.223372037e+18;
    while (le + 1 <= ri) {
      w1 = le + (ri - le) / 3;
      w2 = ri - (ri - le) / 3;
      v1 = move(i, w1);
      v2 = move(i, w2);
      if (v1 > v2)
        ri = w2 - 1, cor = max(cor, v1);
      else
        le = w1 + 1, cor = max(cor, v2);
    }
    cor = max(cor, move(i, le));
    if (cor > maxh) maxh = cor;
  }
  printf("%I64d", maxh);
  return 0;
}
