#include <bits/stdc++.h>
using namespace std;
const long long base = 361;
const long long mod = 1e9 + 7;
const long double eps = 1e-5;
const long long maxn = 1e10;
long long n, a[500009], pre[500009], i, ans, res, sizet;
struct segtree_ele {
  long long l, r;
  pair<long long, long long> line;
} segtree[2000009];
long long getval(pair<long long, long long> line, long long gt) {
  return line.first * gt + line.second;
}
long long getnode(long long &x) {
  if (x != 0) {
    return x;
  }
  sizet++;
  x = sizet;
  segtree[x].l = 0;
  segtree[x].r = 0;
  segtree[x].line = {0, -1e18};
  return x;
}
void update(long long id, long long l, long long r,
            pair<long long, long long> line) {
  if (line.first < segtree[id].line.first) {
    swap(segtree[id].line, line);
  }
  if (line.first == segtree[id].line.first) {
    segtree[id].line.second = max(segtree[id].line.second, line.second);
    return;
  }
  if (r - l == 1) {
    return;
  }
  long long mid = (r + l) / 2;
  if (getval(line, l) > getval(segtree[id].line, l)) {
    swap(line, segtree[id].line);
    update(getnode(segtree[id].l), l, mid, line);
  } else {
    if (getval(line, mid) > getval(segtree[id].line, mid)) {
      swap(segtree[id].line, line);
      update(getnode(segtree[id].l), l, mid, line);
    } else {
      update(getnode(segtree[id].r), mid, r, line);
    }
  }
}
long long get(long long id, long long l, long long r, long long gt) {
  if (r - l == 1) {
    return getval(segtree[id].line, gt);
  }
  long long mid = (r + l) / 2;
  if (gt < mid) {
    return max(getval(segtree[id].line, gt),
               get(getnode(segtree[id].l), l, mid, gt));
  } else {
    return max(getval(segtree[id].line, gt),
               get(getnode(segtree[id].r), mid, r, gt));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  n = 0;
  getnode(n);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i] * i;
  }
  for (i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  res = ans;
  for (i = 1; i <= n; i++) {
    res = max(res, ans + get(1, 1, maxn, i) - pre[i]);
    update(1, 1, maxn, {a[i], pre[i] - i * a[i]});
  }
  sizet = 0;
  getnode(sizet);
  for (i = n; i >= 1; i--) {
    res = max(res, ans + get(1, 1, maxn, i) - pre[i - 1]);
    update(1, 1, maxn, {a[i], pre[i - 1] - i * a[i]});
  }
  cout << res << '\n';
}
