#include <bits/stdc++.h>
using namespace std;
int a[200000 + 5];
long long ps[200000 + 5];
pair<int, long long> operator-(const pair<int, long long> &a,
                               const pair<int, long long> &b) {
  return {a.first - b.first, a.second - b.second};
}
long long cross(const pair<int, long long> &a, const pair<int, long long> &b) {
  return 1ll * a.first * b.second - 1ll * a.second * b.first;
}
pair<int, long long> q[200000 + 5];
int lb(int l, int r, pair<int, long long> k) {
  while (l < r) {
    int mid = (l + r) >> 1;
    if (cross(k, q[mid + 1] - q[mid]) > 0)
      r = mid;
    else
      l = mid + 1;
  }
  return q[l].first;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i];
  int front = 0, rear = -1;
  for (int i = 0; i <= n; i++) {
    while (front < rear &&
           cross(make_pair(i, ps[i]) - q[rear], q[rear] - q[rear - 1]) >= 0)
      rear--;
    q[++rear] = {i, ps[i]};
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int j = lb(front, rear, {1, a[i]});
    ans = max(ans, ps[i] - 1ll * a[i] * i - (ps[j] - 1ll * a[i] * j));
  }
  for (int i = 1; i <= n; i++) ans += 1ll * i * a[i];
  printf("%lld\n", ans);
  return 0;
}
