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<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#define debug(x) cerr<<#x<<"="<<x<<endl
#define INF 0x7f7f7f7f
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
inline int init()
{
    int now=0,ju=1;char c;bool flag=false;
    while(1)
    {
        c=getchar();
        if(c=='-')ju=-1;
        else if(c>='0'&&c<='9')
        {
            now=now*10+c-'0';
            flag=true;
        }
        else if(flag)return now*ju;
    }
}
inline long long llinit()
{
    long long now=0,ju=1;char c;bool flag=false;
    while(1)
    {
        c=getchar();
        if(c=='-')ju=-1;
        else if(c>='0'&&c<='9')
        {
            now=now*10+c-'0';
            flag=true;
        }
        else if(flag)return now*ju;
    }
}
ll next[300005];
ll dp[3][300005];
int a[3][300005];
int n;
ll ans=0; 
int main()
{
	n=init();
	for(int i=1;i<=n;i++)
	{
		a[1][i]=init();
	}
	for(int i=1;i<=n;i++)
	{
		a[2][i]=init();
	}
	int now;
	for(int i=n;i>=1;i--)
	{
		next[i]=next[i+1]+a[2][i]+a[1][i]; 
	}
	for(int i=n;i>=1;i--)
	{
		now=(i-1)*2;
		dp[1][i]=dp[1][i+1]-next[i+1]+(now*a[1][i])+(((2*n)-1)*a[2][i]);
		dp[2][i]=dp[2][i+1]-next[i+1]+(now*a[2][i])+(((2*n)-1)*a[1][i]);
	}
	ll ans=0;
	ll nowans=0;
	now=0;
	ans=max(ans,dp[1][1]);
	for(int i=1;i<=n;i++)
	{
		if(i&1)
		{
			nowans+=a[1][i]*now;
			now++;
			nowans+=a[2][i]*now;
			now++;
			ans=max(ans,dp[2][i+1]+nowans);
		}
		else
		{
			nowans+=a[2][i]*now;
			now++;
			nowans+=a[1][i]*now;
			now++;
			ans=max(ans,dp[1][i+1]+nowans);
		}
	}
	printf("%I64d",ans);
	return 0;
}
/*
srO xudyh davidlee1999WTK linkct1999 zlser Orz
*/
