#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    a = a * a % c, b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 200000 + 10, maxn = 100000 + 10, inf = 0x3f3f3f3f;
long long a[N], b[N];
int q[N], top;
long long cal(int x, int y) {
  if (x <= y)
    return a[x] * (y - x) + b[x] - b[y];
  else
    return a[x] * (y - x) + b[x - 1] - b[y - 1];
}
int main() {
  int n;
  scanf("%d", &n);
  long long te = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    b[i] = a[i] + b[i - 1];
    te += a[i] * i;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int l = 0, r = n;
    while (l < r - 3) {
      int m = (l + r) / 2, m1 = (m + r) / 2;
      if (cal(i, m) <= cal(i, m1))
        l = m;
      else
        r = m1;
    }
    for (int j = max(1, r - 5); j <= min(n, r + 5); j++)
      ans = max(ans, cal(i, j));
  }
  printf("%lld\n", ans + te);
  return 0;
}
