#include <bits/stdc++.h>
using namespace std;
struct line {
  long long int m, c;
  line() {}
  line(long long int _m, long long int _c) {
    m = _m;
    c = _c;
  }
} ara[200010];
long long int n, a[200010], cst, cost[200010], cum[200010], sz;
bool chknthSeg(bool tp, long long int m1, long long int c1, long long int m2,
               long long int c2, long long int m3, long long int c3) {
  if (tp == true) {
    return (double(c2 - c1) / (m1 - m2)) <= (double(c3 - c1) / (m1 - m3));
  } else {
    return (double(c2 - c1) / (m1 - m2)) >= (double(c3 - c1) / (m1 - m3));
  }
}
void insert(bool tp, long long int m3, long long int c3) {
  long long int i, j;
  if (sz == 0) {
    ara[sz++] = line(m3, c3);
  } else if (sz == 1) {
    ara[sz++] = line(m3, c3);
  } else {
    while (chknthSeg(tp, ara[sz - 1].m, ara[sz - 1].c, ara[sz - 2].m,
                     ara[sz - 2].c, m3, c3) &&
           sz > 1) {
      sz--;
    }
    ara[sz++] = line(m3, c3);
  }
}
bool chkmid(bool tp, long long int mid, long long int x) {
  long long int m1, c1, m2, c2;
  m1 = ara[mid].m;
  c1 = ara[mid].c;
  m2 = ara[mid - 1].m;
  c2 = ara[mid - 1].c;
  if (tp == true) {
    return (double)(c2 - c1) / (m1 - m2) >= (double)x;
  } else {
    return (double)(c2 - c1) / (m1 - m2) <= (double)x;
  }
}
long long int query(bool tp, long long int x) {
  if (sz == 1) {
    return ara[0].m * x + ara[0].c;
  }
  long long int lo = 0, hi = sz - 1, mid;
  while (lo < hi) {
    mid = (lo + hi + 1) / 2;
    if (chkmid(tp, mid, x)) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  return ara[lo].m * x + ara[lo].c;
}
void input() {
  long long int i, j, mx1, mx2;
  scanf("%lld", &n);
  cum[0] = 0;
  cst = 0;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    cum[i] = cum[i - 1] + a[i];
    cst += (i * a[i]);
  }
  sz = 0;
  for (i = n; i >= 1; i--) {
    insert(true, i, -cum[i]);
    cost[i] = query(true, a[i]) + cst - (a[i] * i) + cum[i];
    if (i == n) {
      mx1 = cost[i];
    } else {
      mx1 = max(mx1, cost[i]);
    }
  }
  sz = 0;
  for (i = 1; i <= n; i++) {
    insert(false, i, -cum[i - 1]);
    cost[i] = query(false, a[i]) + cst - (a[i] * i) + cum[i - 1];
    if (i == 1) {
      mx2 = cost[i];
    } else {
      mx2 = max(mx2, cost[i]);
    }
  }
  long long int mx = max(mx1, mx2);
  printf("%lld", mx);
  puts("");
}
int main() {
  long long int i, j;
  input();
  return 0;
}
