n=int(input())
h=input().split( )
c=input().split( )
p=0
for i in range(len(h)):
    h[i]=int(h[i])
for i in range(len(c)):
    c[i]=int(c[i])
St=0
mv=h[0]
mc=c[0]
if n==1:
    St=c[0]+St
for i in range(1,n):
    if h[i]>mv:
        St=c[i]+St
        p=p+2
    elif h[i]<mv and c[i]<mc and p==i:
        St=St+c[i]
        p=p+1
    else:
        St=St+mc
        p=p+2
    mv=h[i]
    mc=c[i]
    
print(St)         

    


    
