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 N = 300005;
int n;
int a[N], b[N];
long long ha[N], hb[N], ra[N], rb[N], sa[N], sb[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sa[i] = sa[i - 1] + a[i];
    ha[i] = ha[i - 1] + (long long)i * a[i];
    ra[i] = ra[i - 1] + (long long)(n - i + 1) * a[i];
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
    sb[i] = sb[i - 1] + b[i];
    hb[i] = hb[i - 1] + (long long)i * b[i];
    rb[i] = rb[i - 1] + (long long)(n - i + 1) * b[i];
  }
  long long ans = 0, re = 0;
  int x = 1, y = 1;
  for (int i = 1; i < n * 2; ++i) {
    if (x & 1) {
      if (y == 1) {
        long long t = (ha[n] - ha[x - 1]) + (sa[n] - sa[x - 1]) * (i - x - 1);
        t += (rb[n] - rb[x - 1]) + (sb[n] - sb[x - 1]) * (i + n - x - 1);
        ans = max(ans, re + t);
        re += (long long)(i - 1) * a[x];
        ++y;
      } else {
        long long t = (hb[n] - hb[x - 1]) + (sb[n] - sb[x - 1]) * (i - x - 1);
        t += (ra[n] - ra[x]) + (sa[n] - sa[x]) * (i + n - x - 1);
        ans = max(ans, re + t);
        re += (long long)(i - 1) * b[x];
        ++x;
      }
    } else {
      if (y == 1) {
        long long t = (ha[n] - ha[x - 1]) + (sa[n] - sa[x - 1]) * (i - x - 1);
        t += (rb[n] - rb[x]) + (sb[n] - sb[x]) * (i + n - x - 1);
        ans = max(ans, re + t);
        re += (long long)(i - 1) * a[x];
        ++x;
      } else {
        long long t = (hb[n] - hb[x - 1]) + (sb[n] - sb[x - 1]) * (i - x - 1);
        t += (ra[n] - ra[x - 1]) + (sa[n] - sa[x - 1]) * (i + n - x - 1);
        ans = max(ans, re + t);
        re += (long long)(i - 1) * b[x];
        --y;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
