#include <bits/stdc++.h>
using namespace std;
struct line {
  long long k;
  long long b;
  line(long long k, long long b) : k(k), b(b) {}
  long long get(long long x) { return k * x + b; }
  long double x_intersect(line arg) {
    return ((long double)(arg.b - b)) / ((long double)(k - arg.k));
  }
};
struct convex_hull_trick {
  vector<line> st;
  void add_line_ascending(line a) {
    int n = st.size();
    while (st.size() > 1 &&
           a.x_intersect(st[n - 2]) < st[n - 2].x_intersect(st[n - 1])) {
      st.pop_back();
      n--;
    }
    st.push_back(a);
  }
  void add_line_descending(line a) {
    int n = st.size();
    while (st.size() > 1 &&
           a.x_intersect(st[n - 2]) > st[n - 2].x_intersect(st[n - 1])) {
      st.pop_back();
      n--;
    }
    st.push_back(a);
  }
  long long get_max(long long x) {
    int l = 0;
    int r = st.size() - 1;
    while (l < r) {
      int m = (l + r) / 2;
      if (st[m].get(x) <= st[m + 1].get(x)) {
        l = m + 1;
      } else {
        r = m;
      }
    }
    return st[l].get(x);
  }
  void clean() { st.clear(); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long total = 0;
  vector<long long> a(n + 1);
  vector<long long> prsum(n + 1);
  prsum[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    prsum[i] = prsum[i - 1] + a[i];
    total += a[i] * i;
  }
  convex_hull_trick cht;
  long long maxans1 = -2000000000000000000;
  for (int i = 1; i <= n; i++) {
    cht.add_line_ascending(line(i, -prsum[i - 1]));
    maxans1 = max(maxans1, total - a[i] * i + cht.get_max(a[i]) + prsum[i - 1]);
  }
  cht.clean();
  long long maxans2 = -2000000000000000000;
  for (int i = n; i >= 1; i--) {
    cht.add_line_descending(line(i, -prsum[i]));
    maxans2 = max(maxans2, total - a[i] * i + cht.get_max(a[i]) + prsum[i]);
  }
  cout << max(maxans1, maxans2);
}
