#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
const long long INF = INT64_MAX;
long long a[N], dp[N], sum[N];
vector<int> q;
inline long long y1(int i) { return sum[i - 1]; }
inline long long x1(int i) { return i; }
inline long long dy1(int i, int j) { return y1(j) - y1(i); }
inline long long dx1(int i, int j) { return x1(j) - x1(i); }
inline long long y2(int i) { return sum[i]; }
inline long long x2(int i) { return i; }
inline long long dy2(int i, int j) { return y2(j) - y2(i); }
inline long long dx2(int i, int j) { return x2(j) - x2(i); }
bool check1(int x, long long k) {
  if (x == q.size() - 1) return true;
  return dy1(q[x], q[x + 1]) >= dx1(q[x], q[x + 1]) * k;
}
bool check2(int x, long long k) {
  if (x == q.size() - 1) return true;
  return dy2(q[x], q[x + 1]) >= dx2(q[x], q[x + 1]) * k;
}
int main() {
  long long n, preans = 0;
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    preans += a[i] * i;
  }
  long long ans = 0;
  q.clear();
  q.push_back(1);
  for (int i = 2; i <= n; i++) {
    int l = 0, r = q.size();
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check1(mid, a[i]))
        r = mid - 1;
      else
        l = mid + 1;
    }
    int j = q[l];
    ans = max(ans, sum[i - 1] - sum[j - 1] - a[i] * (i - j));
    while (q.size() >= 2 && dy1(*++q.rbegin(), q.back()) * dx1(q.back(), i) >=
                                dy1(q.back(), i) * dx1(*++q.rbegin(), q.back()))
      q.pop_back();
    q.push_back(i);
  }
  q.clear();
  q.push_back(n);
  for (int i = n - 1; i >= 1; i--) {
    int l = 0, r = q.size();
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check2(mid, a[i]))
        r = mid - 1;
      else
        l = mid + 1;
    }
    int j = q[l];
    ans = max(ans, sum[i] - sum[j] + a[i] * (j - i));
    while (q.size() >= 2 && dy2(*++q.rbegin(), q.back()) * dx2(q.back(), i) <=
                                dy2(q.back(), i) * dx2(*++q.rbegin(), q.back()))
      q.pop_back();
    q.push_back(i);
  }
  cout << ans + preans;
}
