#P1198D. Rectangle Painting 1

Rectangle Painting 1

Description

There is a square grid of size n×nn \times 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)\max(h, w) to color a rectangle of size h×wh \times w. You are to make all cells white for minimum total cost.

The first line contains a single integer nn (1n501 \leq n \leq 50) — the size of the square grid.

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

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

Input

The first line contains a single integer nn (1n501 \leq n \leq 50) — the size of the square grid.

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

Output

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

Sample Input 1

3
###
#.#
###

Sample Output 1

3

Sample Input 2

3
...
...
...

Sample Output 2

0

Sample Input 3

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

Sample Output 3

2

Sample Input 4

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

Sample Output 4

5

Note

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