#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 11, K = 20;
const int mod = 1e9 + 7;
long long dp[N];
long long arr[N][2], idx = 0;
deque<pair<long long, long long>> st;
long long sum = 0, fullsum;
void rev(pair<long long, long long> r, long long tr) {
  sum -= r.first;
  fullsum -= r.second + 1LL * r.first * tr;
}
void fill(long long s) {
  long long tr = 0;
  while (st.size()) {
    dp[s] = fullsum;
    for (int i = 0; i < 2; i++) {
      if (st.size()) {
        rev(st.back(), tr);
        st.pop_back();
      }
    }
    for (int i = 0; i < 2; i++) {
      if (st.size()) {
        rev(st.front(), tr);
        st.pop_front();
      }
    }
    fullsum += 2 * sum;
    tr += 2, s += 2;
  }
  sum = 0;
  fullsum = 0;
  idx = 0;
  st.clear();
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i][0]);
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i][1]);
  for (int i = 0; i < n; i++, idx++) {
    st.push_back(make_pair(arr[i][0], 1LL * idx * arr[i][0]));
    sum += arr[i][0];
    fullsum += 1LL * idx * arr[i][0];
  }
  for (int i = n - 1; i >= 0; i--, idx++) {
    st.push_back(make_pair(arr[i][1], 1LL * idx * arr[i][1]));
    sum += arr[i][1];
    fullsum += 1LL * idx * arr[i][1];
  }
  fill(0);
  idx = 2;
  for (int i = 1; i < n; i++, idx++) {
    st.push_back(make_pair(arr[i][1], 1LL * idx * arr[i][1]));
    sum += arr[i][1];
    fullsum += 1LL * idx * arr[i][1];
  }
  for (int i = n - 1; i >= 1; i--, idx++) {
    st.push_back(make_pair(arr[i][0], 1LL * idx * arr[i][0]));
    sum += arr[i][0];
    fullsum += 1LL * idx * arr[i][0];
  }
  fill(1);
  long long mx = 0, sum = 0;
  long long a = 0, b = 1;
  for (int i = 0; i < n; i++) {
    mx = max(mx, sum + dp[i]);
    sum += 1LL * a * arr[i][0] + 1LL * b * arr[i][1];
    a += 2, b += 2;
    swap(a, b);
  }
  cout << max(mx, sum);
}
