#include <bits/stdc++.h>
using namespace std;
inline long long ma(long long a, long long b) { return ((a - b > 0) ? a : b); }
inline long long mi(long long a, long long b) { return ((a - b > 0) ? b : a); }
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
bool Q;
struct line {
  mutable long long k, m, p;
  bool operator<(const line& o) const { return Q ? p < o.p : k < o.k; }
};
struct LineContainer : multiset<line> {
  const long long inf = LLONG_MAX;
  inline long long div(long long a, long long b) {
    return a / b - ((a ^ b) < 0 && a % b);
  }
  inline bool isect(iterator x, iterator y) {
    if (y == end()) {
      x->p = inf;
      return false;
    }
    if (x->k == y->k)
      x->p = x->m > y->m ? inf : -inf;
    else
      x->p = div(y->m - x->m, x->k - y->k);
    return x->p >= y->p;
  }
  inline void add(long long k, long long m) {
    auto z = insert({k, m, 0}), y = z++, x = y;
    while (isect(y, z)) z = erase(z);
    if (y != begin() && isect(--x, y)) isect(x, erase(y));
    while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y));
  }
  inline long long query(long long x) {
    assert(!empty());
    Q = 1;
    auto l = *lower_bound({0, 0, x});
    Q = 0;
    return l.k * x + l.m;
  }
};
long long ar[200010], dp[200010], ad[200010], ad1[200010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, froz = 0;
  cin >> n;
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    cin >> ar[i];
    dp[i] = (i == 1) ? ar[i] : dp[i - 1] + ar[i];
    ad[i] = dp[i] - ar[i] * i;
    if (i > 1) ad1[i] = dp[i - 1] - ar[i] * i;
    froz += ar[i] * i;
  }
  LineContainer lc1, lc2;
  long long ans = 0;
  for (int(i) = (n - 1); (i) >= (1); (i)--) {
    lc1.add(i + 1, -dp[i + 1]);
    long long xd = lc1.query(ar[i]);
    ans = ma(ans, xd + ad[i]);
  }
  for (int(i) = (2); (i) < (1 + n); (i)++) {
    lc2.add(i - 1, -dp[i - 2]);
    long long xd = lc2.query(ar[i]);
    ans = ma(ans, xd + ad1[i]);
  }
  cout << ans + froz << endl;
  return 0;
}
