#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
long long a[N], pre[N];
long long S, ans;
const long long INF = 1e18;
bool vis[N << 2];
pair<long long, long long> p[N << 1];
inline long long calc(long long x, pair<long long, long long> p) {
  return x * p.first + p.second;
}
void build(int l, int r, int rt) {
  vis[rt] = 0;
  if (l == r) return;
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
}
void add(pair<long long, long long> x, int l, int r, int rt) {
  if (vis[rt] == 0) {
    vis[rt] = 1;
    p[rt] = x;
    return;
  } else {
    if (l == r) {
      if (calc(l, p[rt]) <= calc(l, x)) p[rt] = x;
      return;
    }
    if (calc(l, p[rt]) <= calc(l, x) && calc(r, p[rt]) <= calc(r, x))
      p[rt] = x;
    else if (calc(l, p[rt]) < calc(l, x) || calc(r, p[rt]) < calc(r, x)) {
      int m = (l + r) >> 1;
      add(x, l, m, rt << 1);
      add(x, m + 1, r, rt << 1 | 1);
    }
  }
}
long long query(int x, int l, int r, int rt) {
  if (vis[rt] == 0) return -INF;
  long long ret = calc(x, p[rt]);
  if (l == r) return ret;
  int m = (l + r) >> 1;
  if (x <= m)
    ret = max(ret, query(x, l, m, rt << 1));
  else
    ret = max(ret, query(x, m + 1, r, rt << 1 | 1));
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = int(1); i <= int(n); ++i) cin >> a[i];
  for (int i = int(1); i <= int(n); ++i) {
    pre[i] = pre[i - 1] + a[i];
    S += a[i] * i;
  }
  ans = S;
  for (int i = 1; i <= n; ++i) {
    add(pair<long long, long long>(a[i], pre[i] - a[i] * i), 1, n, 1);
    ans = max(ans, S - pre[i] + query(i, 1, n, 1));
  }
  build(1, n, 1);
  for (int i = n; i >= 1; --i) {
    add(pair<long long, long long>(a[i], pre[i - 1] - a[i] * i), 1, n, 1);
    ans = max(ans, S - pre[i - 1] + query(i, 1, n, 1));
  }
  cout << ans << endl;
}
