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;
const int MAXN = 3e5 + 5;
int n;
long long a[MAXN], b[MAXN], ans, sum;
long long p[MAXN], q[MAXN], r[MAXN], s[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int j = 1; j <= n; j++) scanf("%I64d", &b[j]);
  for (int i = 1; i <= n; i++) sum += a[i] * (i - 1);
  for (int i = 1; i <= n; i++) sum += b[n - i + 1] * (n + i - 1);
  ans = max(ans, sum);
  sum = 0;
  for (int i = 1; i <= n; i++) sum += b[i] * i;
  for (int i = 1; i < n; i++) sum += a[n - i + 1] * (n + i);
  ans = max(ans, sum);
  sum = 0;
  for (int i = 1; i <= n; i++) {
    p[i] = p[i - 1];
    if (i & 1) {
      p[i] += a[i] * (i * 2 - 2);
      p[i] += b[i] * (i * 2 - 1);
    } else {
      p[i] += a[i] * (i * 2 - 1);
      p[i] += b[i] * (i * 2 - 2);
    }
  }
  for (int i = n; i >= 1; i--) s[i] = s[i + 1] + a[i] + b[i];
  for (int i = n; i >= 1; i--) {
    q[i] = q[i + 1] + s[i + 1] + a[i] + b[i] * (n - i + 1) * 2;
    r[i] = r[i + 1] + s[i + 1] + b[i] + a[i] * (n - i + 1) * 2;
  }
  for (int i = 1; i <= n; i++) {
    if (i & 1)
      ans = max(ans, p[i] + r[i + 1] + s[i + 1] * (2 * i - 1));
    else
      ans = max(ans, p[i] + q[i + 1] + s[i + 1] * (2 * i - 1));
  }
  printf("%I64d\n", ans);
}
