#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
int a[N];
int n;
struct line {
  long long m, b;
  line() {}
  line(long long _a, long long _b) {
    m = _a;
    b = _b;
  };
  long long get(long long x) { return m * x + b; }
};
struct CHT {
  int size;
  int cnt = 0;
  line a[N];
  CHT() {
    size = 0;
    cnt = 0;
  }
  bool isbad(int i1, int i2, int i3) {
    return (a[i3].b - a[i1].b) * 1.0 * (a[i1].m - a[i2].m) <
           (a[i2].b - a[i1].b) * 1.0 * (a[i1].m - a[i3].m);
  }
  void addline(long long m, long long b) {
    a[size++] = line(m, b);
    while (size > 2 && isbad(size - 3, size - 2, size - 1)) {
      size--;
      a[size - 1] = a[size];
    }
  }
  long long get(long long x) {
    int l = -1;
    int r = size - 1;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (a[mid].get(x) <= a[mid + 1].get(x)) {
        l = mid;
      } else {
        r = mid;
      }
    }
    return a[r].get(x);
  }
};
CHT cht;
long long pref[N], ans, ans1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pref[i] = pref[i - 1] + a[i];
    ans += a[i] * 1LL * i;
  }
  for (int r = 2; r <= n; r++) {
    cht.addline(r - 1, -pref[r - 2]);
    ans1 = max(ans1, cht.get(a[r]) + pref[r - 1] - r * 1LL * a[r]);
  }
  cht = CHT();
  for (int l = n - 1; l >= 1; l--) {
    cht.addline(-(l + 1), -pref[l + 1]);
    ans1 = max(ans1, cht.get(-a[l]) + pref[l] - l * 1LL * a[l]);
  }
  printf("%I64d", ans + ans1);
}
