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

import sys
import math
n=int(sys.stdin.readline())
arrup=list(map(int,sys.stdin.readline().split()))
arrd=list(map(int,sys.stdin.readline().split()))
preup=[0]
pred=[0]
s=0
cnt=0
for i in range(n):
    s+=arrup[i]
    cnt+=arrd[i]
    preup.append(s)
    pred.append(cnt)
#print(preup,'preup')
#print(pred,'pred')
dp=[[0,0] for x in range(n)]
dp[n-1][0]=arrd[n-1]
dp[n-1][1]=arrup[n-1]
for i in range(n-2,-1,-1):
    x,y=preup[n]-preup[i+1],pred[n]-pred[i+1]
    dp[i][0]=dp[i+1][0]+x+y+arrd[i]*(2*(n-i)-1)
    dp[i][1]=dp[i+1][1]+x+y+arrup[i]*(2*(n-i)-1)
#print(dp,'dp')
s=0
t=0
ans=dp[0][0]
for i in range(n-1):
    if i%2==0:
        s+=t*arrup[i]
        t+=1
        s+=t*arrd[i]
        t+=1
        c,d=(preup[n]-preup[i+1]),(pred[n]-pred[i+1])
        #print(c,'c',d,'d',t,'t')
        cost=s+(dp[i+1][1])+c*t+d*t
        #print(cost,'cost',i,'i')
        #t+=1
        ans=max(ans,cost)
    else:
        s+=t*arrd[i]
        t+=1
        s+=t*arrup[i]
        t+=1
        c,d=(preup[n]-preup[i+1]),(pred[n]-pred[i+1])
        cost=s+(dp[i+1][0])+c*t+d*t
        #t+=1
        #print(c,'c',d,'d',cost,'cost',i,'i',s,'s',t,'t')
        ans=max(ans,cost)
print(ans)
