#ABC233G. [ABC233G] Strongest Takahashi

[ABC233G] Strongest Takahashi

Score : 600600 points

Problem Statement

There is a N×NN \times N grid, with blocks on some squares. The grid is described by NN strings S1,S2,,SNS_1,S_2,\dots,S_N, as follows.

  • If the jj-th character of SiS_i is #, there is a block on the square at the ii-th row from the top and jj-th column from the left.
  • If the jj-th character of SiS_i is ., there is not a block on the square at the ii-th row from the top and jj-th column from the left.

Takahashi can do the operation below zero or more times.

  • First, choose an integer DD between 11 and NN (inclusive), and a D×DD \times D subsquare within the grid.
  • Then, consume DD stamina points to destroy all blocks within the subsquare.

Find the minimum number of stamina points needed to destroy all the blocks.

Constraints

  • NN is an integer.
  • 1N501 \le N \le 50
  • SiS_i consists of # and ..
  • Si=N|S_i|=N

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the answer as an integer.

5
##...
.##..
#.#..
.....
....#
4

By choosing the subsquares below, Takahashi will consume 44 stamina points, which is optimal.

  • The 3×33 \times 3 subsquare whose top-left square is at the 11-st row from the top and 11-st column from the left.
  • The 1×11 \times 1 subsquare whose top-left square is at the 55-th row from the top and 55-th column from the left.
3
...
...
...
0

There may be no block on the grid.

21
.....................
.....................
...#.#...............
....#.............#..
...#.#...........#.#.
..................#..
.....................
.....................
.....................
..........#.....#....
......#..###.........
........#####..#.....
.......#######.......
.....#..#####........
.......#######.......
......#########......
.......#######..#....
......#########......
..#..###########.....
.........###.........
.........###.........
19