#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long double inf = 1e17;
typedef struct line {
  long long m;
  long long c;
} line;
line newline(long long m, long long c) {
  line l;
  l.m = m;
  l.c = c;
  return l;
}
long double inters(line a, line b) {
  return (long double)(a.c - b.c) / (b.m - a.m);
}
bool reldec(line now, line fir, line snd) {
  return (inters(now, snd) < inters(fir, snd));
}
bool relinc(line now, line fir, line snd) {
  return (inters(now, snd) > inters(fir, snd));
}
long long A[maxn];
line S[maxn];
long long p[maxn];
int n;
int N;
pair<long double, long double> getbounds(int x) {
  if (N == 1) {
    return make_pair(-inf, inf);
  } else if (x == 1) {
    return make_pair(inters(S[x], S[x + 1]), inf);
  } else if (x == N) {
    return make_pair(-inf, inters(S[x], S[x - 1]));
  } else {
    return make_pair(inters(S[x + 1], S[x]), inters(S[x], S[x - 1]));
  }
}
pair<long double, long double> getbounds_2(int x) {
  if (N == 1) {
    return make_pair(-inf, inf);
  } else if (x == 1) {
    return make_pair(-inf, inters(S[x], S[x + 1]));
  } else if (x == N) {
    return make_pair(inters(S[x], S[x - 1]), inf);
  } else {
    return make_pair(inters(S[x - 1], S[x]), inters(S[x], S[x + 1]));
  }
}
long long getbest(long long x) {
  int l = 1, r = N;
  while (l <= r) {
    int mid = (l + r) / 2;
    pair<long double, long double> z = getbounds(mid);
    if (z.first <= x && x <= z.second) {
      return x * S[mid].m + S[mid].c;
    }
    if (x <= z.first) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
}
long long getbest_2(long long x) {
  int l = 1, r = N;
  while (l <= r) {
    int mid = (l + r) / 2;
    pair<long double, long double> z = getbounds_2(mid);
    if (z.first <= x && x <= z.second) {
      return x * S[mid].m + S[mid].c;
    }
    if (x <= z.first) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
}
void addline(line l) {
  while (N >= 2) {
    if (!reldec(l, S[N], S[N - 1])) {
      N--;
    } else {
      break;
    }
  }
  N++;
  S[N] = l;
}
void addline_2(line l) {
  while (N >= 2) {
    if (!relinc(l, S[N], S[N - 1])) {
      N--;
    } else {
      break;
    }
  }
  N++;
  S[N] = l;
}
int main() {
  long long sum = 0;
  p[0] = 0;
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%lld", &A[i]);
    sum += A[i] * i;
    p[i] = p[i - 1] + A[i];
  }
  N = 0;
  long long ans = 0;
  for (int i = (n); i >= (1); i--) {
    addline(newline(i, -p[i]));
    long long cur = getbest(A[i]) - A[i] * i + p[i];
    ans = (((ans) > (cur)) ? (ans) : (cur));
  }
  N = 0;
  for (int i = (1); i <= (n); i++) {
    addline_2(newline(i, -p[i - 1]));
    long long cur = getbest_2(A[i]) - A[i] * i + p[i - 1];
    ans = (((ans) > (cur)) ? (ans) : (cur));
  }
  printf("%lld", ans + sum);
  printf("\n");
}
