#include <bits/stdc++.h>   using namespace std;   namespace Flandle_Scarlet {   int n;   int a[51][51];   char tmp[51];   int s[51][51];   void Input() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %s , tmp);       for (int j = 1; j <= n; ++j) {         if (tmp[j - 1] ==  # )           a[i][j] = 1;         else           a[i][j] = 0;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + a[i][j];       }     }   }   int RSum(int a1, int b1, int a2, int b2) {     return s[a2][b2] - s[a1 - 1][b2] - s[a2][b1 - 1] + s[a1 - 1][b1 - 1];   }   int dp[51][51][51][51];   int DFS(int a1, int b1, int a2, int b2) {     if (dp[a1][b1][a2][b2]) {       return dp[a1][b1][a2][b2];     }     if (a1 == a2 and b1 == b2) {       dp[a1][b1][a2][b2] = a[a1][b1];       return dp[a1][b1][a2][b2];     }     if (RSum(a1, b1, a2, b2) == 0) {       return (dp[a1][b1][a2][b2] = 0);     }     dp[a1][b1][a2][b2] = max(a2 - a1 + 1, b2 - b1 + 1);     for (int i = a1; i < a2; ++i) {       int newans = DFS(a1, b1, i, b2) + DFS(i + 1, b1, a2, b2);       dp[a1][b1][a2][b2] = min(dp[a1][b1][a2][b2], newans);     }     for (int i = b1; i < b2; ++i) {       int newans = DFS(a1, b1, a2, i) + DFS(a1, i + 1, a2, b2);       dp[a1][b1][a2][b2] = min(dp[a1][b1][a2][b2], newans);     }     return dp[a1][b1][a2][b2];   }   void Soviet() {     DFS(1, 1, n, n);     printf( %d n , dp[1][1][n][n]);   }   void IsMyWife() {     if (0) {       freopen(  ,  r , stdin);       freopen(  ,  w , stdout);     }     Input();     Soviet();   }   };  // namespace Flandle_Scarlet   int main() {     Flandle_Scarlet::IsMyWife();     return 0;   }   