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

//package sudo_plac;
import java.util.*;
public class mushroom {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[][] a=new int[2][n];
		for(int i=0;i<2;i++) {
			for(int j=0;j<n;j++)
				a[i][j]=sc.nextInt();
		}
		long sum=0;
		int rd=1,x=0,y=0;
		int[][] vis=new int[2][n];
		while(rd<2*n) {
			vis[x][y]=-1;
			int s1=Integer.MAX_VALUE,s2=s1,s3=s1,s4=s1;
			if(x==0 && vis[x+1][y]==0)
				s1=a[x+1][y];
			if(x==1 && vis[x-1][y]==0)
				s2=a[x-1][y];
			if(y>0 && vis[x][y-1]==0)
				s3=a[x][y-1];
			if(y<n-1 && vis[x][y+1]==0)
				s4=a[x][y+1];
			if(s1<=s2 && s1<=s3 && s1<=s4) {
				sum+=rd*s1;
				x++;
			}	
			else if(s2<=s1 && s2<=s3 && s2<=s4) {
				sum+=rd*s2;
				x--;
			}	
			else if(s3<=s2 && s1>=s3 && s3<=s4) {
				sum+=rd*s3;
				y--;
			}	
			else if(s4<=s2 && s4<=s3 && s1>=s4) {
				sum+=rd*s4;
				y++;
			}	
			rd++;
				
		}
		System.out.println(sum);
		
		
		
	}
	
}
