#include <bits/stdc++.h>
using namespace std;
const long long maxn = 4e5 + 50;
const long long mod = 1e9 + 7;
const long long base = 1e15;
long long l1[maxn];
long long r[maxn];
long long dp[maxn];
long long a[maxn];
long long b[maxn];
long long nw;
long long j;
long long n;
long long m;
struct tk {
  long long x, y;
  tk operator-(const tk &other) { return {-x + other.x, -y + other.y}; }
  bool operator%(const tk &other) {
    return ((long double)(x) / (long double)y) >
           ((long double)(other.x) / (long double)other.y);
  }
};
long double first(tk d1, tk d2) {
  return (long double)(d2.y - d1.y) / (d1.x - d2.x);
}
tk c[maxn];
long long f[maxn];
void add(tk nw) {
  while (m >= 2 && first(c[m - 1], nw) > first(c[m], nw)) m--;
  ++m;
  c[m] = nw;
}
long long chk(long long val, long long id) { return c[id].x * val + c[id].y; }
long long q(long long val) {
  long long l = 1, h = m;
  while (l + 1 < h) {
    long long mid = (l + h) / 2;
    if (first(c[mid], c[mid + 1]) > val)
      h = mid;
    else
      l = mid;
  }
  long long ans = -1e18;
  ans = max(ans, chk(val, h));
  return max(ans, chk(val, l));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("GIDDY.inp", "r")) {
    freopen("GIDDY.inp", "r", stdin);
    freopen("GIDDY.out", "w", stdout);
  }
  cin >> n;
  long long ans = 0;
  f[0] = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    f[i] = f[i - 1] + a[i];
    ans += a[i] * i;
  }
  m = 0;
  long long ans1 = ans;
  add({1, -f[0]});
  for (long long i = 2; i <= n; i++) {
    add({(i), -f[i - 1]});
    ans1 = max(ans1, ans + f[i - 1] - a[i] * i + q(a[i]));
  }
  m = 0;
  add({-n, -f[n]});
  for (long long i = n - 1; i >= 1; i--) {
    add({-(i), -f[i]});
    ans1 = max(ans1, ans - a[i] * i + f[i] + q(-a[i]));
  }
  cout << ans1;
}
