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

# from math import ceil
#from sys import stdout

t = 1#int(input())
for test in range(1,t+1):
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    visitedA = [0 for i in range(n+2)]
    visitedA[0] = 1
    visitedA[-1] = 1
    visitedB = [0 for i in range(n+2)]
    visitedB[0] = 1
    visitedB[-1] = 1
    inA = 1
    ans = 0
    index = 1
    for i in range(0, 2*n):
        if inA==1:
            visitedA[index] = 1
            ans+=i*a[index-1]
            tmp = 1000001
            if visitedA[index+1]==0:
                if tmp>a[index]:
                    newInd = index+1
                    tmp = min(tmp, a[newInd-1])
            if visitedA[index-1]==0:
                if tmp>a[index-2]:
                    newInd = index-1
                    tmp = min(tmp, a[newInd-1])
            if visitedB[index]==0:
                if tmp>b[index-1]:
                    inA = 0
                    newInd = index
            index = newInd
        else:
            visitedB[index] = 1
            ans+=i*b[index-1]
            tmp = 1000001
            if visitedB[index+1]==0:
                if tmp>b[index]:
                    newInd = index+1
                    tmp = min(tmp, b[newInd-1])
            if visitedB[index-1]==0:
                if tmp>b[index-2]:
                    newInd = index-1
                    tmp = min(tmp, b[newInd-1])
            if visitedA[index]==0:
                if tmp>a[index-1]:
                    inA = 1
                    newInd = index
            index = newInd
    print(ans)

    
        




    














    
    