#include <bits/stdc++.h>
int getbit(long long x, int y) { return (x >> y) & 1; }
long long getoff(long long x, int y) { return x ^ ((1ll) << y); }
using namespace std;
struct pil {
  int first;
  long long second;
  pil() {
    first = 0;
    second = -1e18;
  }
  pil(int x, long long y) {
    first = x;
    second = y;
  }
};
int n, MAX = 1000000, a[200010];
long long res = -1e18, f[200010], t[200010];
pil it[8000000];
long long fnc(int y, pil x) { return (1ll * y * x.first + x.second); }
void update(int id, int l, int r, int u, int v, pil tmp) {
  if (u > r || v < l) return;
  int mid = (l + r) >> 1;
  if (u <= l && v >= r) {
    if (fnc(l, it[id]) >= fnc(l, tmp) && fnc(r, it[id]) >= fnc(r, tmp)) return;
    if (fnc(l, it[id]) <= fnc(l, tmp) && fnc(r, it[id]) <= fnc(r, tmp)) {
      it[id] = tmp;
      return;
    }
    if (fnc(l, it[id]) >= fnc(l, tmp) && fnc(mid, it[id]) >= fnc(mid, tmp)) {
      update(id * 2 + 1, mid + 1, r, u, v, tmp);
      return;
    }
    if (fnc(l, it[id]) <= fnc(l, tmp) && fnc(mid, it[id]) <= fnc(mid, tmp)) {
      swap(it[id], tmp);
      update(id * 2 + 1, mid + 1, r, u, v, tmp);
      return;
    }
    if (fnc(mid + 1, it[id]) >= fnc(mid + 1, tmp) &&
        fnc(r, it[id]) >= fnc(r, tmp)) {
      update(id * 2, l, mid, u, v, tmp);
      return;
    }
    if (fnc(mid + 1, it[id]) <= fnc(mid + 1, tmp) &&
        fnc(r, it[id]) <= fnc(r, tmp)) {
      swap(it[id], tmp);
      update(id * 2, l, mid, u, v, tmp);
      return;
    }
  }
  update(id * 2, l, mid, u, v, tmp);
  update(id * 2 + 1, mid + 1, r, u, v, tmp);
}
long long get(int id, int l, int r, int x) {
  if (x > r || x < l) return -1e18;
  long long kq = fnc(x, it[id]);
  if (l == r) return kq;
  int mid = (l + r) >> 1;
  kq = max(kq, get(id * 2, l, mid, x));
  kq = max(kq, get(id * 2 + 1, mid + 1, r, x));
  return kq;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    t[i] = t[i - 1] + a[i];
    f[i] = f[i - 1] + 1ll * a[i] * i;
  }
  for (int i = 1; i <= n; ++i) {
    long long ans = get(1, -MAX, MAX, a[i]) + f[n] + t[i - 1] - 1ll * a[i] * i;
    res = max(res, ans);
    update(1, -MAX, MAX, -MAX, MAX, pil(i, -t[i - 1]));
  }
  for (int i = 1; i < 4 * MAX; ++i) it[i] = pil(0, -1e18);
  for (int i = n; i >= 1; --i) {
    long long ans = get(1, -MAX, MAX, a[i]) + f[n] + t[i] - 1ll * a[i] * i;
    res = max(res, ans);
    update(1, -MAX, MAX, -MAX, MAX, pil(i, -t[i]));
  }
  res = max(res, f[n]);
  cout << res;
  return 0;
}
