Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being black and 0 being white. 

Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2n by 2n. You are allowed to move pieces but not allowed to rotate or flip them.

Input

The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board. 

Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.

Output

Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.

Examples

Input

1
0

0

1

0


Output

1


Input

3
101
010
101

101
000
101

010
101
011

010
101
010


Output

2
import java.util.*;

public class Main {
    public int getCount(boolean[][] board){
        boolean rowElem = true;

        int res = 0;
        for(int i = 0; i < board.length; i++){
            boolean colElem = rowElem = rowElem ^ true;
            for(int j = 0; j < board.length; j++){
                if(board[i][j] != colElem) {
                    res++;
                }
                colElem = colElem ^ true;
            }
        }

        return Math.min(res, board.length * board.length - res);
    }

    public boolean[][] getBoard(boolean[][] part1, boolean[][] part2,
                                boolean[][] part3, boolean[][] part4
    ){
        boolean[][] board = new boolean[2*part1.length][2*part1.length];

        for(int i = 0; i < part1.length; i++)
            for(int j = 0; j < part1.length; j++)
                board[i][j] = part1[i][j];
        for(int i = part1.length; i < 2*part1.length; i++)
            for(int j = 0; j < part1.length; j++)
                board[i][j] = part3[i - part1.length][j];
        for(int i = 0; i < part1.length; i++)
            for(int j = part1.length; j < 2*part1.length; j++)
                board[i][j] = part2[i][j - part1.length];
        for(int i = part1.length; i < 2*part1.length; i++)
            for(int j = part1.length; j < 2*part1.length; j++)
                board[i][j] = part4[i - part1.length][j - part1.length];
        return board;
    }

    public int getSolution(boolean[][] part1, boolean[][] part2,
                           boolean[][] part3, boolean[][] part4
    ){
        Map<Integer, boolean[][]> map = new HashMap<>();
        map.put(1, part1); map.put(2, part2); map.put(3, part3); map.put(0, part4);

        int res = Integer.MAX_VALUE;

        boolean[] taken = new boolean[4];
        for(int i = 0; i < taken.length; i++){
            if(taken[i]) continue;
            taken[i] = true;
            for(int j = 0; j < taken.length; j++){
                if (taken[j]) continue;;
                taken[j] = true;
                for(int k = 0; k < taken.length; k++){
                    if(taken[k]) continue;;
                    taken[k] = true;
                    for(int l = 0; l < taken.length; l++){
                        if (taken[l]) continue;
                        taken[l] = true;
                        boolean[][] board = getBoard(map.get(i), map.get(j), map.get(k), map.get(l));
                        res = Math.min(res, getCount(board));

                        taken[l] = false;
                    }
                    taken[k] = false;
                }
                taken[j] = false;
            }
            taken[i] = false;
        }


        return res;
    }

    public static void main(String[] arg) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        boolean[][] part1 = new boolean[n][n];
        boolean[][] part2 = new boolean[n][n];
        boolean[][] part3 = new boolean[n][n];
        boolean[][] part4 = new boolean[n][n];

        for(int i = 0; i < n; i++){
            String str = scanner.next();
            for (int j = 0; j < n; j++)
                part1[i][j] = str.charAt(j) == '1';
        }
        for(int i = 0; i < n; i++){
            String str = scanner.next();
            for (int j = 0; j < n; j++)
                part2[i][j] = str.charAt(j) == '1';
        }
        for(int i = 0; i < n; i++){
            String str = scanner.next();
            for (int j = 0; j < n; j++)
                part3[i][j] = str.charAt(j) == '1';
        }
        for(int i = 0; i < n; i++){
            String str = scanner.next();
            for (int j = 0; j < n; j++)
                part4[i][j] = str.charAt(j) == '1';
        }


        Main main = new Main();
        int res = main.getSolution(part1, part2, part3, part4);
        System.out.println(res);
    }
}
