#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX / 2;
const long long MOD = 1e9 + 7;
template <typename T>
class ConvexHullTrick {
 private:
  vector<pair<T, T>> lines;
  int head;
  bool check(pair<T, T> l1, pair<T, T> l2, pair<T, T> l3) {
    return (l3.second - l2.second) * (l2.first - l1.first) >=
           (l2.second - l1.second) * (l3.first - l2.first);
  }
  T f(int i, T x) { return lines[i].first * x + lines[i].second; }

 public:
  ConvexHullTrick() : head(0) {}
  bool empty() { return lines.size() - head == 0; }
  void insert(T a, T b) {
    pair<T, T> line(a, b);
    if (lines.size() - head >= 1 && a == lines.back().first &&
        b > lines.back().second)
      return;
    while (lines.size() - head >= 2 &&
           check(*(lines.end() - 2), lines.back(), line))
      lines.pop_back();
    lines.emplace_back(line);
  }
  T getmin(T x) {
    int low = -1, high = lines.size() - 1;
    while (high - low > 1) {
      int mid = (high + low) / 2;
      (f(mid, x) >= f(mid + 1, x) ? low : high) = mid;
    }
    return f(high, x);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> sum(N + 1, 0);
  long long ans = 0;
  for (int i = 0; (i) < (N); ++(i)) {
    cin >> a[i];
    ans += a[i] * (i + 1);
    sum[i + 1] = sum[i] + a[i];
  }
  ConvexHullTrick<long long> CHT1;
  long long aa = 0;
  for (int i = 0; (i) < (N); ++(i)) {
    if (i > 0) {
      aa = max(aa, -CHT1.getmin(a[i]) + sum[i] - (i + 1) * a[i]);
    }
    CHT1.insert(-(i + 1), sum[i]);
  }
  ConvexHullTrick<long long> CHT2;
  for (int i = N - 1; i >= 0; i--) {
    if (i < N - 1) {
      aa = max(aa, -CHT2.getmin(-a[i]) + sum[i + 1] - (i + 1) * a[i]);
    }
    CHT2.insert(i + 1, sum[i + 1]);
  }
  ans += aa;
  cout << ans << endl;
  return 0;
}
