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;
int main() {
  long long int n;
  cin >> n;
  vector<vector<long long int> > arr(n, vector<long long int>(2));
  for (int i = 0; i < n; ++i) {
    cin >> arr[i][0];
  }
  for (int i = 0; i < n; ++i) {
    cin >> arr[i][1];
  }
  vector<long long int> above(n, 0), below(n, 0);
  vector<long long int> acc_above(n, 0), acc_below(n, 0);
  above[n - 1] = arr[n - 1][1];
  below[n - 1] = arr[n - 1][0];
  acc_above[n - 1] = arr[n - 1][0];
  acc_below[n - 1] = arr[n - 1][1];
  for (int i = n - 2; i > -1; --i) {
    acc_above[i] = acc_above[i + 1] + arr[i][0];
    acc_below[i] = acc_below[i + 1] + arr[i][1];
    above[i] = above[i + 1] + acc_above[i + 1] + acc_below[i + 1] +
               (2 * (n - i) - 1) * arr[i][1];
    below[i] = below[i + 1] + acc_above[i + 1] + acc_below[i + 1] +
               (2 * (n - i) - 1) * arr[i][0];
  }
  int time = 0;
  long long int maxres = 0, curr = 0;
  for (int i = 0; i < n;) {
    maxres =
        max(maxres, curr + time * (acc_above[i] + acc_below[i]) + above[i]);
    curr += arr[i][0] * time;
    time++;
    curr += arr[i][1] * time;
    time++;
    i++;
    if (i < n) {
      maxres =
          max(maxres, curr + time * (acc_above[i] + acc_below[i]) + below[i]);
      curr += arr[i][1] * time;
      time++;
      curr += arr[i][0] * time;
      time++;
      i++;
    }
  }
  maxres = max(maxres, curr);
  cout << maxres << endl;
  return 0;
}
