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 n;
long long int a[1000007];
long long int b[1000007];
long long int acca[1000007];
long long int accb[1000007];
int main(int argc, char const *argv[]) {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    acca[i] += a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    accb[i] += b[i];
  }
  long long int ans = 0;
  long long int cc = 0;
  long long int curr = 0, blk = 0;
  for (int i = 1; i <= n; i++) {
    curr += cc * a[i];
    cc++;
    blk += a[i];
  }
  for (int i = n; i >= 1; i--) {
    curr += cc * b[i];
    cc++;
    blk += b[i];
  }
  ans = curr;
  for (int i = 3; i <= n; i += 2) {
    blk -= (a[i - 2] + a[i - 1] + b[i - 2] + b[i - 1]);
    curr += 2 * blk;
    curr += 2 * a[i - 1];
    curr -= b[i - 2] * 2 * n;
    curr -= b[i - 1] * (2 * n - 1);
    curr += b[i - 2] * (((i - 3) / 2) * 4 + 2);
    curr += b[i - 1] * (((i - 3) / 2) * 4 + 3);
    ans = max(ans, curr);
  }
  if (n == 1) {
    cout << ans << endl;
    return 0;
  }
  cc = 1;
  curr = 0, blk = 0;
  for (int i = 1; i <= n; i++) {
    curr += cc * b[i];
    cc++;
    blk += b[i];
  }
  for (int i = n; i >= 2; i--) {
    curr += cc * a[i];
    cc++;
    blk += a[i];
  }
  blk -= b[1];
  ans = max(ans, curr);
  for (int i = 4; i <= n; i += 2) {
    blk -= (a[i - 2] + a[i - 1] + b[i - 2] + b[i - 1]);
    curr += 2 * blk;
    curr += 2 * b[i - 1];
    curr -= a[i - 2] * 2 * n;
    curr -= a[i - 1] * (2 * n - 1);
    curr += a[i - 2] * (((i - 4) / 2) + 1) * 4;
    curr += a[i - 1] * ((((i - 4) / 2) + 1) * 4 + 1);
    ans = max(ans, curr);
  }
  cout << ans << endl;
  return 0;
}
