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 java.util.*;

public class new1{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int b;
		b = sc.nextInt();
		int x[] = new int[b];
		int y[] = new int[b];
		int a[][] = new int[2][b];
		for(int j =0 ;j<2;j++){
		for(int i=0;i<b;i++){
			a[j][i] = sc.nextInt();
		}}
		long tot = 0;
		int count = 0;
		int ri = 0;
		int rj = 0;
		int flag[][] = new int[2][b];
		for(int i=0;i<2;i++){
			for(int j=0;j<b;j++){
				flag[i][j] = 0;
			}
		}
		flag[0][0] = 1;
		while(count<=2*b-1){
			if(rj>0 && rj<b-1){
				int count1[] = {0,0,0};
				if(flag[ri][rj-1]==0){
					count1[0] = a[ri][rj-1];
				}
				if(ri == 0){if(flag[ri+1][rj]==0 )
					count1[1] = a[ri+1][rj];
				}else if( ri == 1){if(flag[ri-1][rj]==0 )
					count1[1] = a[ri-1][rj];
				}
				if(flag[ri][rj+1] == 0){
					count1[2] = a[ri][rj+1];
				}
				int max = 1000000,num = 0;
				for(int i=0;i<3;i++){
					
					if(count1[i]<max && count1[i]!=0) {
						max = count1[i];
						num= i;
					}
					
				}
				if(num == 0){
					tot += count*a[ri][rj];
					rj = rj-1;
					flag[ri][rj] = 1;
					count++;
				}else if(num == 1){
					if(ri == 0){
						tot += count*a[ri][rj];
						ri = ri+1;
						flag[ri][rj] = 1;
						count++;
					}
					else{
						tot += count*a[ri][rj];
						ri = ri-1;
						flag[ri][rj] = 1;
						count++;
					}
				}else{
					tot += count*a[ri][rj];
					rj = rj+1;
					flag[ri][rj] = 1;
					count++;
				}
			}else if(rj == 0){
				if(ri == 0){
					if(flag[ri+1][rj] == 1){
						tot += count*a[ri][rj];
						rj = rj+1;
						flag[ri][rj] = 1;
						count++;
					}
					else if(flag[ri][rj+1] == 1){
						tot += count*a[ri][rj];
						ri = ri+1;
						flag[ri][rj] = 1;
						count++;
					}
					else if(a[ri+1][rj] < a[ri][rj+1]){
						tot += count*a[ri][rj];
						ri = ri+1;
						flag[ri][rj] = 1;
						count++;
					}
					else{
						tot += count*a[ri][rj];
						rj = rj+1;
						flag[ri][rj] = 1;
						count++;
					}
				}else{
					if(flag[ri-1][rj] == 1){
						tot += count*a[ri][rj];
						rj = rj+1;
						flag[ri][rj] = 1;
						count++;
					}
					else if(flag[ri][rj+1] == 1){
						tot += count*a[ri][rj];
						ri = ri-1;
						flag[ri][rj] = 1;
						count++;
					}
					else if(a[ri-1][rj] < a[ri][rj+1]){
						tot += count*a[ri][rj];
						ri = ri-1;
						flag[ri][rj] = 1;
						count++;
					}
					else{
						tot += count*a[ri][rj];
						rj = rj+1;
						flag[ri][rj] = 1;
						count++;
					}
				}
			}else{
				if(ri == 0){
					if(flag[ri+1][rj] == 1){
						rj = rj-1;
						flag[ri][rj] = 1;
						tot += count*a[ri][rj+1];
						count++;
					}
					else if(flag[ri][rj-1] == 1){
						ri = ri+1;
						flag[ri][rj] = 1;
						tot += count*a[ri-1][rj];
						count++;
					}
					else if( a[ri+1][rj] < a[ri][rj-1]){
						ri = ri+1;
						flag[ri][rj] = 1;
						tot += count*a[ri-1][rj];
						count++;
					}
					else{
						rj = rj-1;
						flag[ri][rj] = 1;
						tot += count*a[ri][rj+1];
						count++;
					}
				}else{
					if(flag[ri-1][rj] == 1){
						rj = rj-1;
						flag[ri][rj] = 1;
						tot += count*a[ri][rj+1];
						count++;
					}
					else if(flag[ri][rj-1] == 1){
						ri = ri-1;
						flag[ri][rj] = 1;
						tot += count*a[ri+1][rj];
						count++;
					}
					else if(a[ri-1][rj] >  a[ri][rj-1]){
						ri = ri-1;
						flag[ri][rj] = 1;
						tot += count*a[ri+1][rj];
						count++;
					}
					else{
						rj = rj-1;
						flag[ri][rj] = 1;
						tot += count*a[ri][rj+1];
						count++;
					}
				}
			}
		}
		System.out.println(tot);
	}
}