#include <bits/stdc++.h>
using namespace std;
struct Line {
  long long m, n, x;
  long long eval(long long x) { return m * x + n; }
  long double intersectX(Line l) {
    long double dn = n - l.n;
    long double dm = l.m - m;
    return dn / dm;
  }
};
struct ConvexHull {
  vector<Line> lines;
  void add(Line l) {
    l.x = LLONG_MIN;
    while (lines.size() >= 1) {
      l.x = l.intersectX(lines.back());
      if (l.x < lines.back().x) {
        lines.pop_back();
      } else {
        break;
      }
    }
    lines.push_back(l);
  }
  long long max(long long x) {
    int lo = 0;
    int hi = lines.size() - 1;
    if (x >= lines[hi].x) return lines[hi].eval(x);
    while (lo + 1 < hi) {
      int m = (lo + hi) / 2;
      if (lines[m].x <= x)
        lo = m;
      else
        hi = m;
    }
    return lines[lo].eval(x);
  }
};
int main() {
  int n;
  scanf("%d", &n);
  long long N[n], s = 0, b = 0, v, sol = 0;
  ConvexHull hull;
  for (int i = 0; i < n; i++) {
    scanf("%lld", N + i);
    sol += N[i] * (i + 1);
    if (i) {
      long long v = s - N[i] * (i + 1) + hull.max(N[i]);
      b = max(v, b);
    }
    hull.add({i + 1, -s});
    s += N[i];
  }
  hull.lines.clear();
  s = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (i != n - 1) {
      long long v = 0 - s - N[i] * (i + 1) + hull.max(-N[i]);
      b = max(v, b);
    }
    hull.add({-(i + 1), s});
    s += N[i];
  }
  cout << sol + b << endl;
  return 0;
}
