6
12 8 12 17 20 5
17 4 8 8 8 4
 6
4 1 12 9 3 11
12 20 19 12 19 11
 1
1
1
 2
1 2
1 1
 1
7
5
 6
16 20 18 7 14 2
17 12 4 10 7 4

705
 917
 1
 9
 5
 741

#include <bits/stdc++.h>
using namespace std;
long long func(int i, int j, int time, vector<int>& arr1, vector<int>& arr2,
               vector<int>& arr3, vector<int>& a, vector<int>& b) {
  if (i == (arr1.size() - 1)) {
    long long prev = time * (a[i] + b[i]);
    if (j == 0) return prev + b[i];
    return prev + a[i];
  }
  if (j == 0) {
    long long prev1 = arr1[i] + (time - i) * arr3[i], prev2;
    prev2 = func(i + 1, 1, time + 2, arr1, arr2, arr3, a, b) + time * a[i] +
            (time + 1) * b[i];
    if (prev1 > prev2) return prev1;
    return prev2;
  } else {
    long long prev1 = arr2[i] + (time - i) * arr3[i], prev2;
    prev2 = func(i + 1, 0, time + 2, arr1, arr2, arr3, a, b) + time * b[i] +
            (time + 1) * a[i];
    if (prev1 > prev2) return prev1;
    return prev2;
  }
}
int main() {
  int n, count;
  cin >> n;
  vector<int> a(n, 0), b(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<int> arr1(n, 0), arr2(n, 0), arr3(n, 0);
  for (int i = 1; i < n; i++) arr1[i] = arr1[i - 1] + i * a[i];
  count = n + 1;
  arr1[n - 1] += n * b[n - 1];
  for (int i = n - 2; i >= 0; i--, count++)
    arr1[i] = arr1[i + 1] + count * b[i];
  arr2[0] = b[0];
  for (int i = 1; i < n; i++) arr2[i] = arr2[i - 1] + (i + 1) * b[i];
  count = n + 2;
  arr2[n - 1] += (n + 1) * a[n - 1];
  for (int i = n - 2; i > 0; i--, count++) arr2[i] = arr2[i + 1] + count * a[i];
  arr2[0] = arr2[1];
  arr3[n - 1] = a[n - 1] + b[n - 1];
  for (int i = n - 2; i >= 0; i--) arr3[i] = arr3[i + 1] + a[i] + b[i];
  cout << func(0, 0, 0, arr1, arr2, arr3, a, b);
}
