#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
struct convexhull {
  struct line {
    long long m, c;
    line(long long m, long long c) : m(m), c(c) {}
    long long operator()(long long x) { return m * x + c; }
  };
  deque<line> dq;
  bool check(line p1, line p2, line p3) {
    return (p2.m - p1.m) * (p3.c - p2.c) >= (p3.m - p2.m) * (p2.c - p1.c);
  }
  void add(line y) {
    while (dq.size() >= 2 && check(dq[dq.size() - 2], dq[dq.size() - 1], y))
      dq.pop_back();
    dq.push_back(y);
  }
  long long query(long long x) {
    int lo = -1, hi = dq.size() - 1;
    while (lo + 1 < hi) {
      int mid = (lo + hi) / 2;
      if (dq[mid](x) <= dq[mid + 1](x))
        lo = mid;
      else
        hi = mid;
    }
    return dq[hi](x);
  }
};
void solve() {
  int n;
  cin >> n;
  vector<long long> a(n + 1), ps(n + 1);
  long long pre = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ps[i] = ps[i - 1] + a[i];
    pre += a[i] * i;
  }
  vector<long long> dp(n + 1, -INF);
  convexhull cht1, cht2;
  for (int i = 2; i <= n; i++) {
    cht1.add({i - 1, -ps[i - 2]});
    dp[i] = max(dp[i], pre + ps[i - 1] - a[i] * i + cht1.query(a[i]));
  }
  for (int i = n - 1; i > 0; i--) {
    cht2.add({-(i + 1), -ps[i + 1]});
    dp[i] = max(dp[i], pre + ps[i] - a[i] * i + cht2.query(-a[i]));
  }
  long long ans = pre;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  for (int t = 1; t <= tc; t++) {
    solve();
  }
}
