#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
struct CHT {
  vector<long long> m, c;
  bool decSlope, askMin;
  CHT(bool slopeType, bool queryType) {
    decSlope = slopeType;
    askMin = queryType;
  }
  bool throwLine(long long l1, long long l2, long long l3) {
    if (decSlope) {
      if (askMin)
        return (double)(c[l2] - c[l1]) * (m[l1] - m[l3]) >=
               (double)(c[l3] - c[l1]) * (m[l1] - m[l2]);
      else
        return (c[l2] - c[l1]) * (m[l1] - m[l3]) <=
               (c[l3] - c[l1]) * (m[l1] - m[l2]);
    } else {
      if (!askMin)
        return (c[l2] - c[l1]) * (m[l1] - m[l3]) >=
               (c[l3] - c[l1]) * (m[l1] - m[l2]);
      else
        return (c[l2] - c[l1]) * (m[l1] - m[l3]) <=
               (c[l3] - c[l1]) * (m[l1] - m[l2]);
    }
  }
  void add(long long M, long long C) {
    m.push_back(M);
    c.push_back(C);
    while (((long long)m.size()) >= 3 &&
           throwLine(((long long)m.size()) - 3, ((long long)m.size()) - 2,
                     ((long long)m.size()) - 1)) {
      m.erase(m.end() - 2);
      c.erase(c.end() - 2);
    }
  }
  long long f(long long i, long long x) { return m[i] * x + c[i]; }
  long long query(long long x) {
    long long l = 0, r = ((long long)m.size()) - 1, ret;
    if (askMin)
      ret = inf;
    else
      ret = -inf;
    while (l <= r) {
      long long m1 = l + (r - l) / 3;
      long long m2 = r - (r - l) / 3;
      if (f(m1, x) == f(m2, x)) {
        ret = f(m1, x);
        r = m2 - 1;
        l = m1 + 1;
      } else if (f(m1, x) < f(m2, x)) {
        if (askMin) {
          ret = f(m1, x);
          r = m2 - 1;
        } else {
          ret = f(m2, x);
          l = m1 + 1;
        }
      } else {
        if (askMin) {
          ret = f(m2, x);
          l = m1 + 1;
        } else {
          ret = f(m1, x);
          r = m2 - 1;
        }
      }
    }
    return ret;
  }
};
const long long lim = 2e5 + 10;
long long a[lim];
long long s[lim];
long long p[lim];
int main() {
  CHT machine(true, false);
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    p[i] = p[i - 1] + a[i];
    s[i] = s[i - 1] + i * a[i];
  }
  long long ans = s[n], ans2 = s[n];
  for (long long i = n; i; i--) {
    machine.add(i, -p[i]);
    long long tmp = machine.query(a[i]) + p[i] - i * a[i] + s[n];
    ans = max(ans, tmp);
  }
  CHT machine2(false, false);
  for (long long i = 1; i <= n; i++) {
    machine2.add(i, -p[i - 1]);
    long long tmp = machine2.query(a[i]) + p[i - 1] - i * a[i] + s[n];
    ans2 = max(ans2, tmp);
  }
  cout << max(ans, ans2) << endl;
  return 0;
}
