#include <bits/stdc++.h>
using namespace std;
struct Line {
  long long m, b;
};
struct HullDynamic {
  vector<Line> a;
  void clear() { a.clear(); }
  bool empty() { return a.empty(); }
  bool bad(long long y) {
    auto z = y + 1;
    if (y == 0) {
      if (z == (long long)a.size()) return 0;
      return a[y].m == a[z].m && a[y].b <= a[z].b;
    }
    auto x = y - 1;
    if (z == (long long)a.size()) return a[y].m == a[x].m && a[y].b <= a[x].b;
    return (double)(a[x].b - a[y].b) * (a[z].m - a[y].m) >=
           (double)(a[y].b - a[z].b) * (a[y].m - a[x].m);
  }
  void insert_line(long long m, long long b) {
    a.push_back({m, b});
    while (a.size() >= 2 && bad((long long)a.size() - 2))
      a.erase(a.begin() + a.size() - 2);
  }
  long long query(long long x) {
    long long low = 0, high = (long long)a.size() - 1;
    while (low < high) {
      long long mid = (low + high) >> 1;
      Line &me = a[mid];
      Line &s = a[mid + 1];
      if (me.b - s.b < (s.m - me.m) * x) {
        low = mid + 1;
      } else {
        high = mid;
      }
    }
    return a[low].m * x + a[low].b;
  }
};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long b[n];
  for (long long i = 0; i < n; i++) {
    b[i] = 0;
    if (i > 0) b[i] += b[i - 1] + a[i - 1];
  }
  long long ORIG_ANS = 0;
  for (long long i = 0; i < n; i++) {
    ORIG_ANS += (i + 1) * a[i];
  }
  long long ans = ORIG_ANS;
  HullDynamic HD1;
  HD1.insert_line(1, -b[0]);
  for (long long i = 1; i < n; i++) {
    ans = max(ans, ORIG_ANS - a[i] * (i + 1) + b[i] + HD1.query(a[i]));
    HD1.insert_line(i + 1, -b[i]);
  }
  long long reva[n];
  for (long long i = 0; i < n; i++) {
    reva[i] = a[n - i - 1];
  }
  long long revb[n];
  for (long long i = 0; i < n; i++) {
    revb[i] = 0;
    if (i > 0) revb[i] = revb[i - 1] + reva[i - 1];
  }
  HullDynamic HD2;
  HD2.insert_line(1, revb[0]);
  for (long long i = 1; i < n; i++) {
    ans =
        max(ans, ORIG_ANS + reva[i] * (i + 1) - revb[i] + HD2.query(-reva[i]));
    HD2.insert_line(i + 1, revb[i]);
  }
  cout << ans << endl;
  return 0;
}
