#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
inline void chmax(T &t, U f) {
  if (t < f) t = f;
}
struct CHT {
  vector<pair<long long, long long> > ls;
  bool check(pair<long long, long long> l1, pair<long long, long long> l2,
             pair<long long, long long> l3) {
    return (l3.first - l2.first) * (l2.second - l1.second) <=
           (l2.first - l1.first) * (l3.second - l2.second);
  }
  void add(long long a, long long b) {
    pair<long long, long long> l(a, b);
    while (ls.size() >= 2 && check(ls[ls.size() - 2], ls[ls.size() - 1], l))
      ls.pop_back();
    ls.push_back(l);
  }
  long long f(long long k, long long x) {
    return ls[k].first * x + ls[k].second;
  }
  long long query(long long x) {
    assert(ls.size());
    long long lb = -1, ub = ls.size() - 1;
    while (ub - lb > 1) {
      long long mid = (ub + lb) / 2;
      if (f(mid, x) <= f(mid + 1, x))
        lb = mid;
      else
        ub = mid;
    }
    return f(ub, x);
  }
};
const long long SIZE = 200000;
long long N;
long long A[SIZE], S[SIZE];
signed main() {
  scanf("%lld", &N);
  for (long long i = 0; i < (long long)(N); i++) scanf("%lld", &A[i]);
  long long ans = 0, base = 0;
  for (long long i = 0; i < (long long)(N); i++) base += (i + 1) * A[i];
  for (long long i = 0; i < (long long)(N); i++)
    S[i] = (i ? S[i - 1] : 0) + A[i];
  CHT cht1;
  for (long long i = N - 1; i >= 0; i--) {
    cht1.add(-i - 1, -S[i]);
    chmax(ans, cht1.query(-A[i]) - A[i] * (i + 1) + S[i]);
  }
  S[0] = 0;
  for (long long i = 0; i < (long long)(N); i++) S[i + 1] = S[i] + A[i];
  CHT cht2;
  for (long long i = 0; i < (long long)(N); i++) {
    cht2.add(i + 1, -S[i]);
    chmax(ans, cht2.query(A[i]) + S[i] - A[i] * (i + 1));
  }
  cout << base + ans << endl;
  return 0;
}
