#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 200005;
int a[maxn];
long long sum[maxn], now;
long long f(int i, int j) { return (long long)j * a[i] - sum[j]; }
long long g(int i) { return now + sum[i] - (long long)a[i] * i; }
int main() {
  int n;
  scanf("%d", &n);
  now = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    now += (long long)a[i] * i;
  }
  long long ans = -INF;
  for (int i = 1; i <= n; i++) {
    int l = 0, r = n, mid;
    while (l < r) {
      mid = (l + r) >> 1;
      if (f(i, mid) >= f(i, mid + 1))
        r = mid;
      else
        l = mid + 1;
    }
    ans = max(ans, f(i, r) + g(i));
    ans = max(ans, f(i, 0) + g(i));
    ans = max(ans, f(i, n) + g(i));
  }
  cout << ans << endl;
  return 0;
}
