There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid.

Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white.

Output

Print a single integer — the minimum total cost to paint all cells in white.

Examples

Input


3
###
#.#
###


Output


3


Input


3
...
...
...


Output


0


Input


4
#...
....
....
#...


Output


2


Input


5
#...#
.#.#.
.....
.#...
#....


Output


5

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>

import java.util.Scanner;

public class Rectangle_painting {
	public static int solve(String[][] grid ,int n){
		
		
		int[][][][] dp=new int[n][n][n][n];
		//base case
		// initializing values corresponding to values when i==r
		for(int i=0;i<n;i++) {
			if(grid[i][n-1].equals("#")){
				dp[i][n-1][i][n-1]=1;
			}
		for(int j=n-2;j>=0;j--) {
			for(int c=j;c<n;c++) {
				dp[i][j][i][c]=Math.max(1, c-j+1);
				if(c==j) {
					if(grid[i][j].equals("#"))
					dp[i][j][i][c]=1;
					if(grid[i][j].equals("."))
						dp[i][j][i][c]=0;
					continue;
				}
				// dividing the answer column wise
				for(int c_c=j;c_c<c;c_c++) {
					int sub_ans=dp[i][j][i][c_c]+dp[i][c_c+1][i][c];
					dp[i][j][i][c]=Math.min(dp[i][j][i][c], sub_ans);
				}
				
			}
		}}
		// initializing values corresponding j==c
		for(int j=0;j<n;j++) {
			if(grid[n-1][j].equals("#")) {
				dp[n-1][j][n-1][n-1]=1;
			}
		for(int i=n-2;i>=0;i--) {
			for(int r=i;r<n;r++) {
				dp[i][j][r][j]=Math.max(r-i+1,1 );
				if(r==i) {
					if(grid[i][j].equals("#"))
					dp[i][j][r][j]=1;
					if(grid[i][j].equals("."))
						dp[i][j][r][j]=0;
					continue;
				}
				// dividing the answer row wise
				for(int c_r=i;c_r<r;c_r++) {
					int sub_ans=dp[i][j][c_r][j]+dp[c_r+1][j][r][j];
					dp[i][j][r][j]=Math.min(dp[i][j][r][j],sub_ans);
				}
			}
		}}
		 
		
		// general case
		for(int i=n-2;i>=0;i--) {
			for(int j=n-2;j>=0;j--) {
				for(int r=i+1;r<n;r++) {
					for(int c=j+1;c<n;c++) {
						dp[i][j][r][c]=Math.max(r-i+1, c-j+1);
					// dividing the answer row wise
						for(int c_r=i;c_r<r;c_r++) {
							int sub_ans=dp[i][j][c_r][c]+dp[c_r+1][j][r][c];
							dp[i][j][r][c]=Math.min(dp[i][j][r][c],sub_ans);
						}
					 // dividing the answer column wise
						for(int c_c=j;c_c<c;c_c++) {
							int sub_ans=dp[i][j][r][c_c]+dp[i][c_c+1][r][c];
							dp[i][j][r][c]=Math.min(dp[i][j][r][c], sub_ans);
						}
						
					}
				}
			}
		}
		return dp[0][0][n-1][n-1];
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		String[][] grid=new String[n][n];
		for(int i=0;i<n;i++) {
			String curr=s.next();
			for(int j=0;j<n;j++) {
				grid[i][j]=curr.substring(j,j+1);
			}
			
		}
		System.out.println(solve(grid, n));
		

	}

}
