#include <bits/stdc++.h>
using namespace std;
long long presum[200005];
long long total;
long long arr[200005];
long long N;
vector<pair<long long, long long> > hull;
long long getval(int idx, long long X) {
  return hull[idx].first * X + hull[idx].second;
}
double intersect(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.second - b.second) * 1.0 / (b.first - a.first);
}
bool bad(pair<long long, long long> a, pair<long long, long long> b,
         pair<long long, long long> c) {
  return intersect(a, c) <= intersect(a, b);
}
void add(pair<long long, long long> L) {
  while (hull.size() > 1 && bad(hull[hull.size() - 2], hull.back(), L))
    hull.pop_back();
  hull.push_back(L);
}
long long query(long long u) {
  int l = 0, r = hull.size() - 1;
  while (r - l > 0) {
    int mid = (l + r) >> 1;
    if (getval(mid, u) <= getval(mid + 1, u)) {
      l = mid + 1;
    } else
      r = mid;
  }
  return getval(r, u);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  for (long long i = 1; i <= N; i++) {
    cin >> arr[i];
    total += arr[i] * i;
    presum[i] = arr[i] + presum[i - 1];
  }
  long long ans = total;
  for (long long i = 2; i <= N; i++) {
    add({i - 1, -presum[i - 2]});
    ans = max(ans, query(arr[i]) + total + presum[i - 1] - arr[i] * i);
  }
  hull.clear();
  for (long long i = N - 1; i >= 1; i--) {
    add({-i - 1, -presum[i + 1]});
    ans = max(ans, query(-arr[i]) + total + presum[i] - arr[i] * i);
  }
  cout << ans << "\n";
}
