#include <bits/stdc++.h>
using namespace std;
const long long linf = 10000000000000043;
const int inf = 1000000043;
void pause(bool a = true) {}
template <class T>
inline const T sqr(const T &x) {
  return x * x;
}
template <class T>
inline T dist(pair<T, T> a, pair<T, T> b) {
  return sqrt(sqr(a.first - b.first) + sqr(a.second - b.second));
}
template <class T>
inline T prod(pair<T, T> a, pair<T, T> b, pair<T, T> c = make_pair(0, 0)) {
  return (a.first - c.first) * (b.second - c.second) -
         (a.second - c.second) * (b.first - c.first);
}
template <class T>
inline bool intriangle(pair<T, T> a, pair<T, T> b, pair<T, T> c, pair<T, T> d) {
  return (abs(prod(a, b, c)) ==
          abs(prod(a, b, d)) + abs(prod(a, c, d)) + abs(prod(b, c, d)));
}
template <class T>
inline int sg(T a) {
  return (a < 0 ? -1 : a ? 1 : 0);
}
long long rng(long long a, long long b) {
  return (((((long long)rand()) << 16) + rand()) % (b - a + 1)) + a;
}
bool inConvPoly(const vector<pair<long long, long long> > &a,
                pair<long long, long long> b) {
  long long l = 1;
  long long r = a.size() - 1;
  if (sg(prod(a[l], b, a[0])) * sg(prod(a[r], b, a[0])) >= 0) return false;
  if (intriangle(a[l], a[r], a[0], b)) return true;
  while (l != r - 1)
    (prod(a[(l + r) / 2], b, a[0]) < 0) ? l = (l + r) / 2 : r = (l + r) / 2;
  return sg(prod(b, a[r], a[l])) * sg(prod(b, a[0], a[l])) < 0;
}
template <class T>
T mex(vector<T> a) {
  set<T> b(a.begin(), a.end());
  for (int i = 0;; ++i)
    if (!b.count(i)) return i;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long popcnt(long long mask) {
  long long cnt = 0;
  while (mask) cnt += mask % 2, mask /= 2;
  return cnt;
}
unsigned long long powi(unsigned long long a, unsigned long long b,
                        long long mod = 1000000007) {
  if (b < 2) return b ? a : 1;
  return (powi((a * a) % mod, b / 2, mod) * (b % 2 ? a : 1LL)) % mod;
}
bool isn(char c) { return ('0' <= c && c <= '9'); }
template <class T>
bool read(T &out) {
  int c = getchar(), sign = 1;
  T num = 0;
  for (; !isn(c) && c != '-'; c = getchar())
    if (c == EOF) return false;
  if (c == '-') {
    sign = -1;
    c = getchar();
  }
  if (c == EOF) return false;
  for (; isn(c); c = getchar()) num = num * 10 + c - '0';
  out = sign * num;
  return true;
}
long long time_limit = 1000000;
long long start = clock();
bool time_break() {
  int g = clock();
  return (clock() - start > time_limit * 0.9);
}
long long fact(long long n, long long mod = linf) {
  long long g = 1;
  for (int i = 0; i < (n); i++) g *= (i + 1);
  return g;
}
void init(long long tl = 1000000) {
  ios::sync_with_stdio(false);
  srand(time(0));
  time_limit = tl;
}
template <class T>
bool maxz(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool minz(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool maxze(T &a, T b) {
  if (a <= b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool minze(T &a, T b) {
  if (a >= b) {
    a = b;
    return true;
  }
  return false;
}
long long mod7 = 1000000007;
long long mod9 = 1000000009;
bool isprime(long long n) {
  if (n < 2) return 0;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long randLL() {
  return (((long long)rand()) << 47) + (((long long)rand()) << 31) +
         (((long long)rand()) << 15) + (((long long)rand()) >> 1);
}
bool isprimeL(long long n, int it = 50) {
  if (n < 2) return 0;
  if (n == 2) return 1;
  if (n % 2 == 0) return 0;
  for (int i = 0; i < (it); i++) {
    long long x = randLL() % (n - 1) + 1;
    if (gcd(x, n) != 1) return 0;
    if (powi(x, n - 1, n) != 1) return 0;
  }
  return 1;
}
vector<long long> a;
vector<long long> s;
long long n;
long long getbest(long long len, bool b) {
  long long best = -linf;
  for (int i = 0; i < (n - len + 1); i++) {
    if (b)
      if (i) maxz(best, a[i - 1] * len - (s[i + len - 1] - s[i - 1]));
    if (!b)
      if (i != n - len)
        maxz(best, -a[i + len] * len + (s[i + len - 1] - (i ? s[i - 1] : 0)));
    long long j = 4564;
  }
  return best;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  a.assign(n, 0);
  s.assign(n, 0);
  for (int i = 0; i < (n); i++) cin >> a[i];
  s[0] = a[0];
  for (int i = 1; i < (n); i++) s[i] = s[i - 1] + a[i];
  long long l = 0;
  long long r = n - 1;
  while (r - l > 2) {
    long long m1 = (l * 2 + r) / 3;
    long long m2 = (l + 2 * r) / 3;
    if (getbest(m1, 1) < getbest(m2, 1))
      l = m1;
    else
      r = m2;
  }
  long long best = 0;
  for (int i = max(1LL, r - 30); i < min(n, r + 30); i++) {
    maxz(best, getbest(i, 1));
  }
  l = 0;
  r = n - 1;
  while (r - l > 2) {
    long long m1 = (l * 2 + r) / 3;
    long long m2 = (l + 2 * r) / 3;
    if (getbest(m1, 0) < getbest(m2, 0))
      l = m1;
    else
      r = m2;
  }
  for (int i = max(1LL, r - 30); i < min(n, r + 30); i++) {
    maxz(best, getbest(i, 0));
  }
  long long ans = 0;
  for (int i = 0; i < (n); i++) ans += a[i] * (i + 1);
  cout << ans + best << endl;
  pause(1);
  return 0;
}
