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

/*
TASK: template
LANG: JAVA
 */
import java.io.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.util.*;

public class C1016 {
    public static void main(String[] args) throws IOException{
        StringBuffer ans = new StringBuffer();
        StringTokenizer st;
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        long[][] arr = new long[n][2];
        for(int i = 0; i < 2; i++){
            st = new StringTokenizer(f.readLine());
            for(int x = 0; x < n; x++){
                arr[x][i] = Integer.parseInt(st.nextToken());
            }
        }
        f.close();

        long[][] psums = new long[n][2];
        long[][] psums1 = new long[n][2];
        long[][] psums2 = new long[n][2];
        long[][] psums3 = new long[n][2];
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if (i != 0){
                psums[i][0] = psums[i - 1][0];
                psums2[i][0] = psums2[i-1][0];
                psums1[i][1] = psums1[i - 1][1];
                psums3[i][1] = psums3[i-1][1];
            }
            psums[i][0]+= arr[i][0];
            psums2[i][0]+= arr[i][0] * cnt;
            psums1[i][1]+= arr[i][1];
            psums3[i][1]+= arr[i][1] * (cnt+1);
            cnt++;
        }

        for(int i = n-1; i > -1; i--){
            if(i == n-1){
                psums[i][1] = psums[n-1][0];
                psums2[i][1] = psums2[n-1][0];
                psums1[i][0] = psums1[n-1][1];
                psums3[i][0] = psums3[n-1][1];
            }else{
                psums[i][1] = psums[i+1][1];
                psums2[i][1] = psums2[i+1][1];
                psums1[i][0] = psums1[i+1][0];
                psums3[i][0] = psums3[i+1][0];
            }
            psums[i][1]+= arr[i][1];
            psums2[i][1]+= arr[i][1] * cnt;
            psums1[i][0]+= arr[i][0];
            psums3[i][0]+= arr[i][0] * (cnt+1);
            cnt++;
        }

//        for(long[] i : psums){
//            System.out.println(Arrays.toString(i));
//        }
//        System.out.println();
//        for(long[] i : psums2){
//            System.out.println(Arrays.toString(i));
//        }
//        System.out.println();
//        for(long[] i : psums1){
//            System.out.println(Arrays.toString(i));
//        }
//        System.out.println();
//        for(long[] i : psums3){
//            System.out.println(Arrays.toString(i));
//        }

        boolean[][] visited = new boolean[n][2];
        int[] dx = new int[]{0,1,0,1};
        int[] dy = new int[]{1,0,-1,0};
        int x = 0;
        int y = 0;
        int v = 0;
        int i = 0;
        long best = 0;
        long curr = 0;
        while (v < 2*n){
            curr+=v*arr[x][y];
            v++;
            visited[x][y] = true;
            if(y == 0 && !visited[x][1]){
                long r = psums1[x][1];
                long r1 = psums3[x][1];
                if(x < n-1){
                    r = psums1[x+1][0];
                    r1 = psums3[x+1][0];
                }
                if(x != 0){r-=psums1[x-1][1]; r1-=psums3[x-1][1];}

                long chk = curr + (v-x-1)*r + r1;
                best = Math.max(chk, best);

                r = psums[x][1] - psums[x][0];
                r1 = psums2[x][1] - psums2[x][0];
                chk = curr + (v-x-1)*r + r1;
                best = Math.max(chk, best);
            }
            x+=dx[i];
            y+=dy[i];
            i++;
            i%=4;
        }
        System.out.println(best);
        //System.out.println(ans);

    }
}