#include <bits/stdc++.h>
using namespace std;
struct line {
  long double k, b;
  line(){};
  line(long long _a, long long _b) : k(_a), b(_b){};
  long long get(long long x) { return k * x + b; }
};
vector<line> cht;
long double intersect(line a, line b) {
  return (a.b * 1.0 - b.b) / (b.k - a.k);
}
void add_line(line a) {
  while ((long long)(cht.size()) > 1) {
    long long n = (long long)(cht.size());
    long double x1 = intersect(cht[n - 2], a),
                x2 = intersect(cht[n - 2], cht[n - 1]);
    if (x1 <= x2)
      cht.pop_back();
    else
      break;
  }
  cht.push_back(a);
}
long long get(long long x) {
  long long l = 0, r = (long long)(cht.size());
  while (r - l != 1) {
    long long m = (r + l) / 2;
    long double xi = intersect(cht[m - 1], cht[m]);
    if (xi <= 1.0 * x)
      l = m;
    else
      r = m;
  }
  return cht[l].get(x);
}
long long n;
const long long N = 2e5 + 10;
long long S = 0;
long long a[N], sum[N];
void solve() {
  cin >> n;
  for (long long i = (1); i < (n + 1); ++i) {
    cin >> a[i];
    sum[i] = a[i] + sum[i - 1];
    S += a[i] * (i);
  }
  long long res = 0;
  for (long long i = (2); i < (n + 1); ++i) {
    add_line(line(i - 1, -sum[i - 2]));
    res = max(res, get(a[i]) + sum[i - 1] - a[i] * i);
  }
  cht.clear();
  for (long long i = n - 1; i >= 1; --i) {
    add_line(line(-(i + 1), -sum[i + 1]));
    res = max(res, get(-a[i]) + sum[i] - a[i] * i);
  }
  cout << res + S << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
