#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200000], pref[200000];
long long res = 0;
pair<long long, long long> hull[200000];
int lo = 0, hi = 0;
bool hides(pair<long long, long long> line1, pair<long long, long long> line2,
           pair<long long, long long> newline) {
  return (line2.second - line1.second) * (line2.first - newline.first) >=
         (newline.second - line2.second) * (line1.first - line2.first);
}
long long eval(pair<long long, long long> p, long long x) {
  return p.first * x + p.second;
}
long long maxeval(long long x) {
  int blo = lo, bhi = hi;
  while (blo < bhi - 1) {
    int mid = (blo + bhi) >> 1;
    long long diff = eval(hull[mid], x) - eval(hull[mid - 1], x);
    if (diff > 0) {
      blo = mid;
    } else if (diff < 0) {
      bhi = mid;
    } else {
      blo = mid;
      bhi = mid + 1;
      break;
    }
  }
  return eval(hull[blo], x);
}
void moveRight() {
  lo = n, hi = n;
  for (int s = (n)-1; s >= 0; s--) {
    pair<long long, long long> curr = make_pair(s, -pref[s]);
    while (hi - lo >= 2 && hides(curr, hull[lo], hull[lo + 1])) {
      lo++;
    }
    hull[--lo] = curr;
    res = max(res, maxeval(a[s]) - s * a[s] + pref[s]);
  }
}
void moveLeft() {
  lo = 0, hi = 0;
  for (int s = 0; s < (n); s++) {
    pair<long long, long long> curr = make_pair(s, (s ? -pref[s - 1] : 0));
    while (hi - lo >= 2 && hides(hull[hi - 2], hull[hi - 1], curr)) {
      hi--;
    }
    hull[hi++] = curr;
    res = max(res, maxeval(a[s]) - s * a[s] + (s ? pref[s - 1] : 0));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n); i++) {
    pref[i] = a[i] + (i ? pref[i - 1] : 0);
  }
  moveRight();
  moveLeft();
  long long base = 0;
  for (int i = 0; i < (n); i++) base += (i + 1) * a[i];
  cout << res + base << "\n";
}
