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.io.*;
import java.util.*;
public class HelloWorld{

     public static void main(String []args)throws IOException
     {
        //System.out.println("Hello World");
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        HashMap<String,Integer> map=new HashMap<String,Integer>();
        int a[]=new int[n];
        int b[]=new int[n];
        int u,d;u=0;d=-1;int p=0; 
        StringTokenizer st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            a[i]=Integer.parseInt(st.nextToken());
           // map.put(("a"+i,0);
        }
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            b[i]=Integer.parseInt(st.nextToken());
            //map.put(("b"+i,0);
        }
        int cost=0;int t=0;
        for(int i=0;i<2*n-1;i++)
        {
           // System.out.println("i="+i+" u="+u+" d="+d);
            if(t==1)
            {
                while(u<n)
                {
                    cost+=(i+1)*a[u];u++;i++;
                }
                u=n-1;
                while(u>d)
                {
                    //System.out.println(i);
                    cost+=(i+1)*b[u];u--;i++;
                }
                break;
            }
            else if(t==2)
            {
                while(d<n)
                {
                    cost+=(i+1)*b[d];d++;i++;
                }
                d=n-1;
                while(d>u)
                {
                    cost+=(i+1)*a[d];d--;i++;
                }
                break;
            }
            else
            {
                if(p==0)
                {
                    if(u-d==1)
                    {
                        if(u<n-1)
                        {
                            if(a[u+1]>=b[d+1])
                            {
                                d++;
                                cost+=(i+1)*b[d];p=1;
                            }
                            else
                            {
                                t=1;u++;cost+=(i+1)*a[u];u++;
                            }
                        }
                        else
                        {
                            d++;
                            cost+=(i+1)*b[d];p=1;
                        }
                    }
                    else if(u==d)
                    {
                        u++;cost+=(i+1)*a[u];
                    }
                }
                else if(p==1)
                {
                    if(d-u==1)
                    {
                        if(d<n-1)
                        {
                            if(b[d+1]>=a[u+1])
                            {
                                u++;
                                cost+=(i+1)*a[u];p=0;
                            }
                            else
                            {
                                t=2;d++;cost+=(i+1)*b[d];d++;
                            }
                        }
                        else
                        {
                            u++;
                            cost+=(i+1)*a[u];p=0;
                        }
                    }
                    else if(u==d)
                    {
                                   // System.out.println("i="+i+" u="+u+" d="+d+"yes");

                        d++;cost+=(i+1)*b[d];
                    }
                }
            }
        }
        System.out.println(cost);
     }
}