#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 2e5 + 100, INF = 1e18;
long long n;
long long a[N];
long long sa[N];
long long suma(long long l, long long r) { return sa[r] - sa[l - 1]; }
long long sai[N];
long long sumai(long long l, long long r) { return sai[r] - sai[l - 1]; }
long long ans = -INF;
long long solve(long long from, long long to) {
  long long res;
  if (from == to) res = sumai(1, n);
  if (from < to)
    res = sumai(1, from - 1) + sumai(from + 1, to) - suma(from + 1, to) +
          sumai(to + 1, n) + a[from] * to;
  if (from > to)
    res = sumai(1, to - 1) + sumai(to, from - 1) + suma(to, from - 1) +
          sumai(from + 1, n) + a[from] * to;
  ans = max(ans, res);
  return res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++)
    cin >> a[i], sa[i] = sa[i - 1] + a[i], sai[i] = sai[i - 1] + a[i] * i;
  for (long long i = 1; i <= n; i++) {
    long long l = 1, r = n;
    while (r - l > 1) {
      long long m1 = (l * 2 + r) / 3;
      long long m2 = (l + r * 2) / 3;
      long long res1 = solve(i, m1);
      long long res2 = solve(i, m2);
      if (res1 < res2)
        l = m1 + 1;
      else
        r = m2 - 1;
    }
    for (long long m = l; m <= r; m++) solve(i, m);
  }
  cout << ans;
}
