#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160")
using namespace std;
const int INF = 1e9 + 10;
const long long LINF = (long long)2e18 + 10;
const long double PI = acos(-1);
const long double eps = 1e-8;
const long double EPS = 1e-12;
struct Line {
  long long a, b;
  long long y(long long x) { return a * x + b; }
  Line(long long a, long long b) : a(a), b(b) {}
};
const int N = 2e5 + 10;
long long a[N], ans, best, psum[N];
int n;
vector<Line> hull;
bool is_bad(Line a, Line b, Line c) {
  return (b.b - c.b) * (b.a - a.a) <= (a.b - b.b) * (c.a - b.a);
}
void add_line(Line line) {
  hull.push_back(line);
  while (hull.size() > 2 && is_bad(hull[hull.size() - 3], hull[hull.size() - 2],
                                   hull[hull.size() - 1])) {
    hull[hull.size() - 2] = hull.back();
    hull.pop_back();
  }
}
long long query(long long x) {
  int l = -1, r = hull.size() - 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (hull[m].y(x) <= hull[m + 1].y(x))
      l = m;
    else
      r = m;
  }
  return hull[r].y(x);
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans += a[i] * (i + 1);
    psum[i + 1] = psum[i] + a[i];
  }
  for (int r = 1; r < n; ++r) {
    add_line(Line(r, -psum[r - 1]));
    best = max(best, query(a[r]) + psum[r] - a[r] * (r + 1));
  }
  hull.clear();
  for (int l = n - 2; l >= 0; --l) {
    add_line(Line(-(l + 2), -psum[l + 2]));
    best = max(best, query(-a[l]) + psum[l + 1] - a[l] * (l + 1));
  }
  cout << best + ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  solve();
  return 0;
}
