#include <bits/stdc++.h>
using namespace std;
inline long long next_int() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
const long long maxn = 2e5 + 10;
long long a[maxn], init, pref[maxn];
struct line {
  long long x, b;
  inline long long get_val(long long a) { return a * x + b; }
};
struct CHT {
  line STACK[maxn];
  long long sz = 0;
  inline long long val(pair<long long, long long> line, long long x) {
    return line.first + x * line.second;
  }
  inline bool ok(line &a, line &b, line &c) {
    return (b.b - a.b) * (b.x - c.x) <= (c.b - b.b) * (a.x - b.x);
  }
  inline void add_line(long long x, long long b) {
    STACK[sz++] = {x, b};
    while (sz > 2 && ok(STACK[sz - 1], STACK[sz - 2], STACK[sz - 3])) {
      STACK[sz - 2] = STACK[sz - 1];
      sz--;
    }
  }
  inline long long get_maxi(long long x) {
    long long l = -1, r = sz - 1;
    while (l + 1 < r) {
      long long mid = (l + r) >> 1;
      if (STACK[mid].get_val(x) <= STACK[mid + 1].get_val(x))
        l = mid;
      else
        r = mid;
    }
    return STACK[r].get_val(x);
  }
} A, B;
long long addition = 0;
int32_t main() {
  long long n = next_int();
  for (long long i = 1; i <= n; i++) {
    a[i] = next_int();
    pref[i] = pref[i - 1] + a[i];
    init += a[i] * i;
  }
  for (long long r = 2; r <= n; r++) {
    A.add_line(r - 1, -pref[r - 2]);
    addition = max(addition, A.get_maxi(a[r]) + pref[r - 1] - a[r] * r);
  }
  for (long long l = n - 1; l >= 1; l--) {
    B.add_line(-(l + 1), -pref[l + 1]);
    addition = max(addition, B.get_maxi(-a[l]) + pref[l] - a[l] * l);
  }
  cout << addition + init << endl;
}
