#include <bits/stdc++.h>
using namespace std;
template <typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {
  ofs << "( " << p.first << " , " << p.second << " )";
  return ofs;
}
template <typename T>
void update_max(T last, T& mx) {
  mx = max(mx, last);
}
template <typename T>
void update_min(T last, T& mx) {
  mx = min(mx, last);
}
template <typename T>
void update_sum(T last, T& mx) {
  mx += last;
}
template <typename T>
void print_one(T a) {
  cout << a << ' ';
}
template <typename T, typename... Args>
T max(Args&&... args) {
  T mx = -1e17;
  T dummy[] = {0, ((void)update_max(std::forward<Args>(args), mx), 0)...};
  return mx;
}
template <typename T, typename... Args>
T min(Args&&... args) {
  T mx = 1e17;
  T dummy[] = {0, ((void)update_min(std::forward<Args>(args), mx), 0)...};
  return mx;
}
template <typename T, typename... Args>
T sum(Args&&... args) {
  T mx = 0;
  T dummy[] = {0, ((void)update_sum(std::forward<Args>(args), mx), 0)...};
  return mx;
}
template <typename... Args>
void print(Args&&... args) {
  int dummy[] = {0, ((void)print_one(std::forward<Args>(args)), 0)...};
  cout << '\n';
}
template <typename T>
void print(vector<T> a) {
  for (auto i : a) cout << i << ' ';
  cout << '\n';
}
template <typename T>
T max(vector<T> a) {
  T mx = -1e17;
  for (auto i : a) mx = max(i, mx);
  return (T)mx;
}
template <typename T>
T min(vector<T> a) {
  T mx = 1e17;
  for (auto i : a) mx = min(i, mx);
  return (T)mx;
}
template <typename T>
T sum(vector<T> a) {
  T mx = 0;
  for (auto i : a) mx += i;
  return mx;
}
vector<long long> a;
vector<long long> prefA;
int n;
long long ans = -1e17;
vector<long long> prefAI;
long long mov(long long i, long long j) {
  long long x = prefAI.back() - (prefA[j] - prefA[i]) + ((j - i) * a[i]);
  ans = max(ans, x);
  return x;
}
int main() {
  cin >> n;
  a = prefA = prefAI = vector<long long>(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  prefA[1] = prefAI[1] = a[1];
  for (int i = 2; i <= n; i++) {
    prefA[i] = prefA[i - 1] + a[i];
    prefAI[i] = prefAI[i - 1] + a[i] * (i);
  }
  for (int i = 1; i <= n; i++) {
    int l = 0, r = n;
    while (r - l > 5) {
      int m1 = l + (r - l) / 3;
      int m2 = r - (r - l) / 3;
      if (mov(i, m1) < mov(i, m2))
        l = m1;
      else
        r = m2;
    }
    for (int j = l; j <= r; j++) mov(i, j);
    mov(i, 0);
    mov(i, n - 1);
  }
  cout << ans << '\n';
}
