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>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll dp[300005][2], suffix[300005];
ll a[300005][2];
int main(){
	fastio;
	ll n; cin >> n;
	for (ll i = 0; i < n; i++) cin >> a[i][0];
	for (ll i = 0; i < n; i++) cin >> a[i][1];
	for (ll i = n - 1; i >= 0; i--){
		if (i == n - 1) suffix[i] = a[i][0] + a[i][1];
		else suffix[i] = suffix[i + 1] + a[i][0] + a[i][1];
	}
	suffix[n] = 0;
	dp[n][0] = 0, dp[n][1] = 0;
	for (ll i = n - 1; i >= 0; i--){
		dp[i][1] = max(dp[i + 1][1] + suffix[i + 1] + (2 * (n - i) - 1) * a[i][0], dp[i + 1][0] + suffix[i + 1] * 2 + a[i][0]);
		dp[i][0] = max(dp[i + 1][0] + suffix[i + 1] + (2 * (n - i) - 1) * a[i][1], dp[i + 1][1] + suffix[i + 1] * 2 + a[i][1]); 
	}
	cout << dp[0][0] << endl;
}