#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
long long n, a[maxn], sum[maxn];
long long calc_move(int from, int to) {
  return a[from] * (long long)(to - from) - (sum[to] - sum[from]);
}
long long crossover(int from, int to) {
  long long headstart = calc_move(from, to);
  if (headstart < 0) return to;
  return to + 1 + headstart / (a[to] - a[from]);
}
long long solve() {
  long long ret = 0;
  deque<int> q;
  for (int i = 0; i < n; i++) sum[i] = (i == 0 ? 0 : sum[i - 1]) + a[i];
  int largest_so_far = -100000000;
  for (int i = 0; i < n; i++) {
    if (a[i] > largest_so_far) {
      while (q.size() >= 2 && crossover(q[0], q[1]) >= crossover(q[0], i))
        q.pop_back();
      q.push_back(i);
      largest_so_far = a[i];
    }
    while (q.size() >= 2 && crossover(q[0], q[1]) <= i) q.pop_front();
    ret = max(ret, calc_move(q[0], i));
  }
  return ret;
}
int main() {
  long long start_char = 0;
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", a + i);
    start_char += (i + 1) * (long long)a[i];
  }
  long long best_delta = solve();
  reverse(a, a + n);
  for (long long i = 0; i < n; i++) a[i] = -a[i];
  best_delta = max(best_delta, solve());
  printf("%lld\n", start_char + best_delta);
  return 0;
}
