#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
struct line {
  long long int a, b;
};
long long int get(const line &l, long long int x) { return l.a * x + l.b; }
long long int intersection(const line &lin1, const line &lin2) {
  return 1.0 * (lin2.b - lin1.b) / (lin1.a - lin2.a);
}
bool conflict(const line &lin1, const line &lin2, const line &lin3) {
  return intersection(lin3, lin2) <= intersection(lin3, lin1);
}
const int N = 200005;
int n, a[N];
long long int dp[N], sum[N], ans, dif;
struct convex_hull {
  deque<line> q;
  void add(const line &l) {
    int k;
    while ((k = (int)q.size()) > 1 && conflict(q[k - 2], q[k - 1], l)) {
      q.pop_back();
    }
    q.push_back(l);
  }
  long long int query(const int &x) {
    int l = -1;
    int r = (int)q.size() - 1;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (get(q[m], x) <= get(q[m + 1], x)) {
        l = m;
      } else {
        r = m;
      }
    }
    return get(q[r], x);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  dif = ans = sum[0] = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    ans += (long long int)a[i] * i;
  }
  convex_hull hull, hull2;
  for (int i = n - 1; i >= 1; --i) {
    hull.add({-i - 1, -sum[i + 1]});
    dif = max(dif, hull.query(-a[i]) + sum[i] - (long long int)a[i] * i);
  }
  for (int i = 2; i <= n; ++i) {
    hull2.add({i - 1, -sum[i - 2]});
    dif = max(dif, hull2.query(a[i]) + sum[i - 1] - (long long int)a[i] * i);
  }
  cout << ans + dif;
  return 0;
}
