满江红
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int n,a[10][N],sum1[10][N],sum2[10][N],sum[10][N],ans=0;
void dfs(int x,int y,int tot,int sm){
if(tot==n*2)return;
int l1=sum1[x][n]-sum1[1][y]+(tot/2*2)*(sum[x][n]-sum[x][y]);
int l2;
if(y%2==1){
l2=sum2[x^3][n]-sum2[x^3][y]+(n+tot/2-1)*(sum[x^3][n]-sum[x^3][y]);
}else{
l2=sum2[x^3][n]-sum2[x^3][y-1]+(n+tot/2-1)*(sum[x^3][n]-sum[x^3][y]);
}
cerr<<x<<" "<<y<<" "<<tot<<endl;
cerr<<sm<<" ";
cerr<<l1<<" ";
cerr<<l2<<" ";
cerr<<sm+l1+l2<<" ";
cerr<<endl;
ans=max(ans,sm+l1+l2);
int next_sm=sm+tot*a[x][y];
tot++;
if(x==1&&y%2==1){
cerr<<"Running well! ";
cerr<<"We are going to ("<<2<<","<<y<<")."<<endl;
dfs(2,y,tot,next_sm);
return;
}
if(x==1&&y%2==0){
cerr<<"Running well! ";
cerr<<"We are going to ("<<1<<","<<y+1<<")."<<endl;
dfs(1,y+1,tot,next_sm);
return;
}
if(x==2&&y%2==1){
cerr<<"Running well! ";
cerr<<"We are going to ("<<2<<","<<y+1<<")."<<endl;
dfs(2,y+1,tot,next_sm);
return;
}
if(x==2&&y%2==0){
cerr<<"Running well! ";
cerr<<"We are going to ("<<1<<","<<y<<")."<<endl;
dfs(1,y,tot,next_sm);
return;
}
cerr<<"Runtime Error! ";
cerr<<"It\'s on ("<<x<<","<<y<<","<<tot<<")."<<endl;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[1][i];
}
for(int i=1;i<=n;i++){
cin>>a[2][i];
}
for(int i=1;i<=n;i++){
sum[1][i]=sum[1][i-1]+a[1][i];
sum[2][i]=sum[2][i-1]+a[2][i];
sum1[1][i]=sum1[1][i-1]+i*a[1][i];
sum1[2][i]=sum1[2][i-1]+i*a[2][i];
sum2[1][i]=sum2[1][i-1]+(n-i+1)*a[1][i];
sum2[2][i]=sum2[2][i-1]+(n-i+1)*a[2][i];
}
dfs(1,1,0,0);
cout<<ans<<endl;
return 0;
}
/*
n=5
(1,1,0) (1,2,3) (1,3,4) (1,4,7) (1,5,8)
(2,1,1) (2,2,2) (2,3,5) (2,4,6) (2,5,9)
(1,1,0):l1=sum1[1][n]-sum1[1][1]
l2=sum2[2][n]-sum2[2][1]+(n-1)*(sum[2][n]-sum2[2][1])
(2,1,1):l1=sum1[2][n]-sum1[2][1]
l2=sum2[1][n]-sum2[1][1]+(n)*(sum[1][n]-sum[1][1])
(2,2,2):l1=sum1[2][n]-sum1[2][2]
l2=sum2[1][n]-sum2[1][1]+(n)*(sum[1][n]-sum[1][1])
(1,2,3):l1=sum1[1][n]-sum1[1][2]+(2)*(sum[1][n]-sum[1][2])
l2=sum2[2][n]-sum2[2][2]+(n+1)*(sum[2][n]-sum[2][2])
(x,y,tot): l1=sum1[x][n]-sum1[1][y]+(tot/2*2)*(sum[x][n]-sum[x][y])
l2=sum2[x^3][n]-sum2[x^3][]
if(y%2==1){
l2=sum2[x^3][n]-sum2[x^3][y]+(n+tot/2-1)*(sum[x^3][n]-sum[x^3][y])
}else{
l2=sum2[x^3][n]-sum2[x^3][y-1]+(n+tot/2-1)*(sum[x^3][n]-sum[x^3][y])
}
*/