#include <bits/stdc++.h>
struct Line {
  int32_t k;
  int64_t b;
  int32_t ind;
  Line(int32_t k_, int64_t b_, int32_t ind_) : k(k_), b(b_), ind(ind_){};
  double isect(Line other) { return (double)(other.b - b) / (k - other.k); }
};
struct CHT {
 private:
  std::vector<Line> lines;
  std::vector<double> line_starts;

 public:
  void add(int32_t k, int64_t b, int32_t ind) {
    while (lines.size() > 0 &&
           lines.back().isect(Line(k, b, ind)) < line_starts.back()) {
      lines.pop_back();
      line_starts.pop_back();
    }
    line_starts.emplace_back(
        lines.size() == 0 ? -DBL_MAX : lines.back().isect(Line(k, b, ind)));
    lines.emplace_back(k, b, ind);
  }
  std::pair<int64_t, int32_t> get_max(int32_t x) {
    int32_t ind = std::lower_bound(line_starts.begin(), line_starts.end(), x) -
                  line_starts.begin() - 1;
    return {(int64_t)lines[ind].k * x + lines[ind].b, lines[ind].ind};
  }
};
CHT* segtree = nullptr;
void build(int32_t node, int32_t left, int32_t right, int64_t* pref_sums) {
  if (right - left > 1) {
    int32_t m = (left + right) / 2;
    build(node * 2 + 1, left, m, pref_sums);
    build(node * 2 + 2, m, right, pref_sums);
  }
  for (int32_t i = left; i < right; i++)
    segtree[node].add(i - 1, -pref_sums[i], i);
}
std::pair<int64_t, int32_t> combine(std::pair<int64_t, int32_t> p1,
                                    std::pair<int64_t, int32_t> p2) {
  return p1.first > p2.first ? p1 : p2;
}
std::pair<int64_t, int32_t> get_suf_max(int32_t node, int32_t left,
                                        int32_t right, int32_t query_left,
                                        int32_t x) {
  if (right <= query_left) return {INT64_MIN, -1};
  if (left >= query_left) return segtree[node].get_max(x);
  int32_t m = (left + right) / 2;
  return combine(get_suf_max(node * 2 + 1, left, m, query_left, x),
                 get_suf_max(node * 2 + 2, m, right, query_left, x));
}
int64_t get_boost(int32_t* arr, int32_t n) {
  int64_t* pref_sums = new int64_t[n + 1];
  pref_sums[0] = 0;
  for (int32_t i = 1; i <= n; i++) pref_sums[i] = pref_sums[i - 1] + arr[i - 1];
  delete[] segtree;
  segtree = new CHT[4 * (n + 1)];
  build(0, 0, n + 1, pref_sums);
  int64_t ans_boost = INT64_MIN;
  for (int32_t i = 0; i < n - 1; i++) {
    int64_t best_boost = INT64_MIN;
    int32_t best_pos = i + 2;
    best_pos = get_suf_max(0, 0, n + 1, i + 2, arr[i]).second;
    best_boost = (int64_t)arr[i] * (best_pos - i - 1) -
                 (pref_sums[best_pos] - pref_sums[i + 1]);
    ans_boost = std::max(ans_boost, best_boost);
  }
  return ans_boost;
}
int main() {
  int32_t n;
  std::cin >> n;
  int32_t* arr = new int32_t[n];
  for (int32_t i = 0; i < n; i++) std::cin >> arr[i];
  int64_t answer = 0;
  for (int32_t i = 0; i < n; i++) answer += arr[i] * (int64_t)(i + 1);
  int64_t ans_boost = std::max((int64_t)0, get_boost(arr, n));
  std::reverse(arr, arr + n);
  for (int32_t i = 0; i < n; i++) arr[i] = -arr[i];
  ans_boost = std::max(ans_boost, get_boost(arr, n));
  std::cout << answer + ans_boost;
  return 0;
}
