#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
class cht {
 public:
  int type;
  explicit cht(int type) : type(type) {}
  struct Line {
    long long int a, b;
    double xLeft;
    int type;
    long long int val;
    Line(long long int _a = 0, long long int _b = 0) {
      a = _a, b = _b, xLeft = -INFINITY, type = 0, val = 0;
    }
    long long int valueAt(long long int first) const {
      return a * 1LL * first + b;
    }
    friend bool areParallel(const Line& l1, const Line& l2) {
      return l1.a == l2.a;
    }
    friend double intersectX(const Line& l1, const Line& l2) {
      return areParallel(l1, l2) ? INFINITY
                                 : 1.0 * (l2.b - l1.b) / (l1.a - l2.a);
    }
    bool operator<(const Line& l2) const {
      if (l2.type == 0)
        return a < l2.a;
      else if (l2.type == 1)
        return xLeft < l2.val;
      else
        return xLeft > l2.val;
    }
  };
  set<Line> hull;
  void destroy() { hull.clear(); }
  bool hasPrev(set<Line>::iterator it) { return it != hull.begin(); }
  bool hasNext(set<Line>::iterator it) {
    return it != hull.end() && next(it) != hull.end();
  }
  bool irrelevant(const Line& l1, const Line& l2, const Line& l3) {
    return intersectX(l1, l3) <= intersectX(l1, l2);
  }
  bool irrelevant(set<Line>::iterator it) {
    return hasPrev(it) && hasNext(it) &&
           (this->type == 1 && irrelevant(*prev(it), *it, *next(it)) ||
            this->type == 2 && irrelevant(*next(it), *it, *prev(it)));
  }
  set<Line>::iterator updateLeftBorder(set<Line>::iterator it) {
    if (this->type == 1 && !hasPrev(it) || this->type == 2 && !hasNext(it))
      return it;
    double val = intersectX(*it, this->type == 1 ? *prev(it) : *next(it));
    Line buf(*it);
    it = hull.erase(it);
    buf.xLeft = val;
    it = hull.insert(it, buf);
    return it;
  }
  void addLine(long long int a, long long int b) {
    Line l3 = Line(a, b);
    auto it = hull.lower_bound(l3);
    if (it != hull.end() && areParallel(*it, l3)) {
      if (this->type == 1 && it->b < b || this->type == 2 && it->b > b)
        it = hull.erase(it);
      else
        return;
    }
    it = hull.insert(it, l3);
    if (irrelevant(it)) {
      hull.erase(it);
      return;
    }
    while (hasPrev(it) && irrelevant(prev(it))) hull.erase(prev(it));
    while (hasNext(it) && irrelevant(next(it))) hull.erase(next(it));
    it = updateLeftBorder(it);
    if (hasPrev(it)) updateLeftBorder(prev(it));
    if (hasNext(it)) updateLeftBorder(next(it));
  }
  long long int getBest(long long int first) const {
    Line q;
    q.val = first;
    q.type = this->type;
    auto bestLine = hull.lower_bound(q);
    if (type == 1) bestLine--;
    return bestLine->valueAt(first);
  }
};
const int N = 2e5 + 100;
long long int a[N], sum[N], pre[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (__typeof(n + 1) i = (1) - ((1) > (n + 1));
       i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    pre[i] = pre[i - 1] + i * a[i];
  }
  cht hull(1);
  long long int ans = pre[n];
  hull.addLine(a[1], sum[1] - 1 * a[1]);
  for (__typeof(n + 1) i = (2) - ((2) > (n + 1));
       i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {
    ans = max(ans, pre[n] - sum[i] + hull.getBest(i));
    hull.addLine(a[i], sum[i] - i * a[i]);
  }
  hull.destroy();
  hull.addLine(a[n], sum[n] - n * a[n]);
  for (__typeof(0) i = (n) - ((n) > (0)); i != (0) - ((n) > (0));
       i += 1 - 2 * ((n) > (0))) {
    ans = max(ans, pre[n] - sum[i] + hull.getBest(i));
    hull.addLine(a[i], sum[i] - i * a[i]);
  }
  cout << ans << endl;
}
