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.*;
import java.lang.*;
public class Solution {
	static Scanner in = new Scanner(System.in);
	
	public static void main(String []args){
		int cell = in.nextInt();
 		int a[] = new int[cell];
 		int b[] = new int[cell];
 		boolean check[][] = new boolean[2][cell];
 		for(int i = 0; i < cell; i++){
 			a[i] = in.nextInt();
  		}
 		for(int i =0;i < cell; i++){
 			b[i] = in.nextInt();
 		}
 		int count = 0, flag = 0, i = 0;
 		long ans = 0;
 		for(i = 0; i < cell-2; i++){
 			if(flag == 0){
 				if(a[i+1]+a[i+2] > b[i]+b[i+1]){
 					ans += (count+1)*b[i]+(count+2)*b[i+1];
 					count = count+2;
 					flag = 1;
 				}
 				else{
 					for(int j = i+1; j < cell; j++){
 						ans += (count+1)*a[j];
 						count++;
 					}
 					for(int j = cell-1; j >= i; j--){
 						ans += (count+1)*b[j];
 						count++;
 					}
 					break;
 				}
 			}
 			else{
 				if(b[i+1]+b[i+2] > a[i]+a[i+1]){
 					ans += (count+1)*a[i]+(count+2)*a[i+1];
 					count = count+2;
 					flag = 0;
 				}
 				else{
 					for(int j = i+1; j < cell; j++){
 						ans += (count+1)*b[j];
 						count++;
 					}
 					for(int j = cell-1; j >= i; j--){
 						ans += (count+1)*a[j];
 						count++;
 					}
 					break;
 				}
 			}
 		}
 		if(i >= cell-2){
 			if(flag == 0){
 				if(a[cell-1]  > b[cell-2])
 					ans += (count+1)*b[cell-2] + (count+2)* b[cell-1] + (count+3)*a[cell-1];
 				else
 					ans += (count+3)*b[cell-2] + (count+2)* b[cell-1] + (count+1)*a[cell-1];
 			}
 			else{
 				if(b[cell-1]  > a[cell-2])
 					ans += (count+1)*a[cell-2] + (count+2)* a[cell-1] + (count+3)*b[cell-1];
 				else
 					ans += (count+3)*a[cell-2] + (count+2)* a[cell-1] + (count+1)*b[cell-1];
 			}
 		}
 		System.out.println(ans);
	}
}
