#include <bits/stdc++.h>
using namespace std;
struct Pack {
  long long a, b;
  int id;
  bool operator<(Pack A) const { return (a == A.a ? b < A.b : a < A.a); }
} Line[200005];
int n, q;
vector<Pack> ST[200005 * 4];
long long S[200005], res, res1;
const long long INFL = 1e18;
bool check(Pack A, Pack B, Pack C) {
  return (C.b - B.b) * (A.a - B.a) <= (B.a - C.a) * (B.b - A.b);
}
bool check1(Pack A, Pack B, int x) { return A.a * x + A.b < B.a * x + B.b; }
void Build(int id = 1, int l = 1, int r = n) {
  if (l > r) return;
  if (l == r) {
    ST[id].push_back(Line[l]);
    return;
  }
  int mid = (l + r) / 2;
  Build(id * 2, l, mid);
  Build(id * 2 + 1, mid + 1, r);
  vector<Pack> temp(ST[id * 2].size() + ST[id * 2 + 1].size());
  merge(ST[id * 2].begin(), ST[id * 2].end(), ST[id * 2 + 1].begin(),
        ST[id * 2 + 1].end(), temp.begin());
  sort(temp.begin(), temp.end());
  for (Pack x : temp) {
    while ((int)ST[id].size() > 1 &&
           check(ST[id][ST[id].size() - 2], ST[id][ST[id].size() - 1], x)) {
      ST[id].pop_back();
    }
    ST[id].push_back(x);
  }
}
long long Get(int id, int l, int r, int u, int v, long long t) {
  if (u > r || v < l) return -INFL;
  if (u <= l && v >= r) {
    int L = 0, R = ST[id].size() - 1;
    while (L < R) {
      int mid = (L + R) / 2;
      if (check1(ST[id][mid], ST[id][mid + 1], t)) {
        L = mid + 1;
      } else
        R = mid;
    }
    return ST[id][R].a * t + ST[id][R].b;
  }
  int MID = (l + r) / 2;
  return max(Get(id * 2, l, MID, u, v, t),
             Get(id * 2 + 1, MID + 1, r, u, v, t));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> Line[i].a;
    res1 += Line[i].a * i;
    S[i] = S[i - 1] + Line[i].a;
    Line[i].b = -Line[i].a * i + S[i];
  }
  Build();
  for (int i = 1; i <= n; i++) {
    res = max(res, Get(1, 1, n, 1, i - 1, i) - S[i]);
  }
  for (int i = 1; i <= 4 * n; i++) ST[i].clear();
  for (int i = n; i >= 1; i--) {
    Line[i].b = -Line[i].a * i + S[i - 1];
  }
  Build();
  for (int i = n; i >= 1; i--) {
    res = max(res, Get(1, 1, n, i + 1, n, i) - S[i - 1]);
  }
  cout << res + res1;
  return 0;
}
