#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct CHT {
  set<pair<pair<T, T>, long double> > S;
  set<pair<long double, pair<T, T> > > I;
  T INF_T = numeric_limits<T>::max();
  long double INF = 1e18;
  inline void Clear() {
    S.clear();
    I.clear();
  }
  inline void Swap(CHT &X) {
    S.swap(X.S);
    I.swap(X.I);
  }
  inline void Add(pair<T, T> X) {
    long double t = -INF;
    auto it = S.lower_bound({X, -INF});
    while ((int)S.size() > 0) {
      if (it == S.begin()) {
        t = -INF;
        break;
      }
      it--;
      long double r = Intersection(it->first, X);
      if (r <= it->second)
        I.erase({it->second, it->first}), it = S.erase(it);
      else {
        t = r;
        break;
      }
    }
    it = S.lower_bound({X, -INF});
    while ((int)S.size() > 0) {
      if (it == S.end()) break;
      long double r = Intersection(X, it->first);
      if (r <= t) {
        r = -INF;
        pair<T, T> Y = it->first;
        I.erase({it->second, it->first});
        it = S.erase(it);
        if (it != S.begin()) it--, r = Intersection(it->first, Y);
        S.insert({Y, r});
        I.insert({r, Y});
        return;
      } else {
        pair<T, T> Y = it->first;
        I.erase({it->second, it->first});
        it = S.erase(it);
        if (it != S.end() && it->second <= r) continue;
        S.insert({Y, r});
        I.insert({r, Y});
        break;
      }
    }
    S.insert({X, t});
    I.insert({t, X});
  }
  T GetMax(T X) {
    auto it = I.upper_bound({(long double)X, {INF_T, INF_T}});
    it--;
    return (X * it->second.first + it->second.second);
  }
  inline long double Intersection(pair<T, T> X, pair<T, T> Y) {
    if (X.first == Y.first && X.second <= Y.second) return (-INF);
    if (X.first == Y.first) return (INF);
    return ((long double)(Y.second - X.second) / (X.first - Y.first));
  }
};
const int N = 200005;
int n, A[N];
long long tot, Mx, P[N];
CHT<long long> C;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    P[i] = P[i - 1] + A[i];
    tot += 1ll * i * A[i];
    C.Add({i, -P[i - 1]});
    Mx = max(Mx, C.GetMax(A[i]) + P[i - 1] - 1ll * i * A[i]);
  }
  C.Clear();
  for (int i = n; i; i--) {
    C.Add({i, -P[i]});
    Mx = max(Mx, C.GetMax(A[i]) + P[i] - 1ll * i * A[i]);
  }
  return !printf("%lld", Mx + tot);
}
