#include <bits/stdc++.h>
using namespace std;
int N;
long long int A[200000 + 3], S[200000 + 3], C, ans;
vector<long long int> M, B;
bool good(int l1, int l2, int l3) {
  return (B[l2] - B[l1]) * (M[l1] - M[l3]) > (B[l3] - B[l1]) * (M[l1] - M[l2]);
}
void insert(long long int m, long long int b, int type) {
  M.push_back(m);
  B.push_back(b);
  if (type == 0) return;
  while (M.size() >= 3 && good(M.size() - 3, M.size() - 2, M.size() - 1)) {
    M.erase(M.end() - 2);
    B.erase(B.end() - 2);
  }
}
long long int query(long long int a) {
  int sz = M.size();
  int lo = 0, mid, hi = sz - 1;
  while (hi >= lo) {
    mid = (lo + hi) / 2;
    if (mid + 1 == sz) break;
    if (a * (M[mid + 1] - M[mid]) <= B[mid] - B[mid + 1])
      hi = mid - 1;
    else
      lo = mid + 1;
  }
  return M[lo] * a + B[lo];
}
int main(void) {
  cin >> N;
  S[0] = 0;
  C = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    S[i] = S[i - 1] + A[i];
    C += (long long int)i * A[i];
  }
  ans = C;
  insert(N, C - S[N], 0);
  for (int i = N - 1; i >= 1; i--) {
    long long int temp = query(A[i]) + S[i] - (long long int)i * A[i];
    ans = max(ans, temp);
    insert(i, C - S[i], 0);
  }
  M.clear();
  B.clear();
  insert(1, C - S[0], 1);
  for (int i = 2; i <= N; i++) {
    long long int temp = query(A[i]) + S[i - 1] - (long long int)i * A[i];
    ans = max(ans, temp);
    insert(i, C - S[i - 1], 1);
  }
  cout << ans << endl;
}
