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;
#pragma comment(linker, "/STACK:2073741824")
int main() {
  int n;
  int a[300005][2];
  long long sp[300005][2];
  long long *last = new long long[300005];
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%d", &a[i][0]);
    for (int i = 0; i < n; i++) scanf("%d", &a[i][1]);
    long long result = 0;
    long long result1 = 0;
    long long times = 2;
    long long tmp = 0;
    long long sum;
    sp[0][0] = 0;
    sp[0][1] = a[0][1];
    for (int i = 1; i < n; ++i) {
      if (i & 1) {
        sp[i][1] = (times++) * a[i][1] + sp[i - 1][1];
        sp[i][0] = (times++) * a[i][0] + sp[i][1];
      } else {
        sp[i][0] = (times++) * a[i][0] + sp[i - 1][0];
        sp[i][1] = (times++) * a[i][1] + sp[i][0];
      }
    }
    if (n & 1) {
      sum = sp[n - 1][1];
    } else {
      sum = sp[n - 1][0];
    }
    last[n] = 0;
    for (int i = n - 1; i >= 0; --i) last[i] = last[i + 1] + a[i][0] + a[i][1];
    times = 0;
    for (int i = 0; i < n; ++i) {
      result += (times++) * a[i][0];
    }
    for (int i = n - 1; i >= 0; --i) {
      result += (times++) * a[i][1];
    }
    if (result > sum) sum = result;
    times = 3;
    for (int i = 2; i < n; ++i) {
      result1 += (times++) * a[i][1];
    }
    for (int i = n - 1; i > 0; --i) {
      result1 += (times++) * a[i][0];
    }
    if (result1 + sp[1][1] > sum) sum = result1 + sp[1][1];
    for (int i = 1; i < n - 1; ++i) {
      if (i & 1) {
        tmp = result - (2 * i - 1) * a[i][0] - (2 * n - 1) * a[i - 1][1] -
              (2 * n - 2) * a[i][1] + 2 * last[i + 1];
        result = tmp;
        if (tmp + sp[i][0] > sum) sum = tmp + sp[i][0];
      } else {
        tmp = result1 - (2 * i - 1) * a[i][1] - (2 * n - 1) * a[i - 1][0] -
              (2 * n - 2) * a[i][0] + 2 * last[i + 1];
        result1 = tmp;
        if (tmp + sp[i][1] > sum) sum = tmp + sp[i][1];
      }
    }
    printf("%lld\n", sum);
  }
  delete[] last;
}
