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 <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)

const int MAX=3e5+5;

int n;
ll mush[3][MAX],f[MAX],g[MAX],tot,rec,ans;

inline int read();

int main(){
	#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	#endif

	n=read();
	lor(i,1,n) scanf("%lld",&mush[1][i]);
	lor(i,1,n) scanf("%lld",&mush[2][i]);

	lor(i,1,n){
		if(i&1) f[i]=f[i-1]+(((i-1)<<1))*mush[1][i]+(((i-1)<<1)+1)*mush[2][i];
		else f[i]=f[i-1]+(((i-1)<<1))*mush[2][i]+(((i-1)<<1)+1)*mush[1][i];
	}
	tot=0; rec=0;
	lor(i,1,n) rec+=mush[1][i]+mush[2][i];
	lor(i,1,n) g[1]=g[1]+(i-1)*mush[1][i]; ror(i,1,n) g[1]=g[1]+((n<<1)-i)*mush[2][i];
	tot=rec;
	lor(i,3,n) if(i&1){
		tot-=mush[1][i-2]+mush[1][i-1]+mush[2][i-2]+mush[2][i-1];
		g[i]=g[i-2]-(i-2)*mush[1][i-2]-(i-2)*mush[1][i-1]-((n<<1)-1)*mush[2][i-2]-((n<<1)-2)*mush[2][i-1]+(tot<<1);
	}
	lor(i,2,n) g[2]=g[2]+(i)*mush[2][i]; ror(i,2,n) g[2]=g[2]+((n<<1)+1-i)*mush[1][i];
	tot=rec-mush[1][1]-mush[2][1];
	lor(i,4,n) if((i&1)==0){
		tot-=mush[1][i-2]+mush[1][i-1]+mush[2][i-2]+mush[2][i-1];
		g[i]=g[i-2]-(i-2)*mush[2][i-2]-(i-1)*mush[2][i-1]-((n<<1)-1)*mush[1][i-2]-((n<<1)-2)*mush[1][i-1]+(tot<<1);
	}

	lor(i,0,n) ans=max(ans,f[i]+g[i+1]);
	printf("%I64d\n",ans);

	return 0;
}

inline int read(){
	char tmp=getchar(); int sum=0; bool flag=false;
	while(tmp<'0'||tmp>'9'){
		if(tmp=='-') flag=true;
		tmp=getchar();
	}
	while(tmp>='0'&&tmp<='9'){
		sum=(sum<<1)+(sum<<3)+tmp-'0';
		tmp=getchar();
	}
	return flag?-sum:sum;
}