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 a[500010], b[500010], n;
int main() {
  cin >> n;
  long long sum = 0, qsum = 0, nsum = 0, rsum = 0, nb = 0, ans = 0;
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%I64d", &b[i]);
  for (int i = 0; i < n; i++) {
    sum += (a[i] + b[i]);
  }
  for (int i = 0; i < n; i++) {
    qsum += (a[i] * i + b[i] * (2 * n - i - 1));
  }
  nsum = sum;
  rsum = qsum;
  for (int i = 0; i < n; i += 2) {
    ans = max(ans, rsum + nb);
    nb += (a[i] * (i * 2) + a[i + 1] * (i * 2 + 3) + b[i] * (i * 2 + 1) +
           b[i + 1] * (i * 2 + 2));
    nsum -= (a[i] + a[i + 1] + b[i] + b[i + 1]);
    rsum -= (a[i] * (i * 2) + a[i + 1] * (i * 2 + 1) + b[i] * (2 * n - 1) +
             b[i + 1] * (2 * n - 2));
    rsum += nsum * 2;
  }
  ans = max(ans, rsum + nb);
  sum = 0;
  qsum = 0;
  for (int i = 1; i < n; i++) {
    sum += (a[i] + b[i]);
  }
  for (int i = 1; i < n; i++) {
    qsum += (a[i] * (2 * n - i) + b[i] * (i + 1));
  }
  nsum = sum;
  rsum = qsum;
  nb = b[0];
  for (int i = 1; i < n; i += 2) {
    ans = max(ans, rsum + nb);
    nb += (a[i] * (i * 2 + 1) + a[i + 1] * (i * 2 + 2) + b[i] * (i * 2) +
           b[i + 1] * (i * 2 + 3));
    nsum -= (a[i] + a[i + 1] + b[i] + b[i + 1]);
    rsum -= (a[i] * (2 * n - 1) + a[i + 1] * (2 * n - 2) + b[i] * (i * 2) +
             b[i + 1] * (i * 2 + 1));
    rsum += nsum * 2;
  }
  ans = max(ans, rsum + nb);
  cout << ans << endl;
}
