#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
long long b[500005];
struct Line {
  long long a, b;
  Line() {}
  Line(long long a, long long b) : a(a), b(b) {}
  long long get(long long x) { return a * x + b; }
};
struct ConvexHull {
  vector<Line> a;
  bool bad(Line l1, Line l2, Line l3) {
    return (l2.a - l3.a) * (l2.b - l1.b) >= (l1.a - l2.a) * (l3.b - l2.b);
  }
  void add(Line l) {
    while ((int(a.size())) >= 2 &&
           bad(a[(int(a.size())) - 2], a[(int(a.size())) - 1], l))
      a.pop_back();
    a.push_back(l);
  }
  long long get(long long x) {
    int l = -1, r = (int(a.size())) - 1;
    while (l + 1 < r) {
      int m = (l + r) / 2;
      if (a[m].get(x) <= a[m + 1].get(x))
        l = m;
      else
        r = m;
    }
    return a[r].get(x);
  }
};
ConvexHull ch;
inline long long sum(int l, int r) {
  if (l > r) return 0;
  if (!l) return b[r];
  return b[r] - b[l - 1];
}
int main() {
  scanf("%d", &n);
  long long second = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    second += 1LL * (i + 1) * a[i];
    b[i] = a[i];
    if (i) b[i] += b[i - 1];
  }
  long long ans = second;
  for (int i = 0; i < n; ++i) {
    ch.add(Line(i + 1, -sum(0, i - 1)));
    ans =
        max(ans, second + ch.get(a[i]) + sum(0, i - 1) - 1LL * (i + 1) * a[i]);
  }
  ch.a.clear();
  for (int i = n - 1; i >= 0; --i) {
    ch.add(Line(-(i + 1), -sum(0, i)));
    ans = max(ans, second + ch.get(-a[i]) + sum(0, i) - 1LL * (i + 1) * a[i]);
  }
  cout << ans << endl;
  return 0;
}
