#include<iostream> #include <queue> #define x first #define y second using namespace std; typedef pair<int,int> PII; const int N = 1010; char s[N][N]; bool t[N][N]; int n; int ans; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; bool bfs(PII cod) { queue<PII>q; q.push(cod); t[cod.x][cod.y] = true; bool land = false; while(q.size()) { PII r = q.front(); q.pop(); bool sea = false; for(int i = 0; i < 4; i ++) { int x = dx[i] + r. x, y = dy[i] + r.y; if(x < 1 || x > n || y < 1 || y > n)continue; if(t[x][y])continue; if(s[x][y] == '.') { sea = true; continue; } if(s[x][y]=='#') { t[x][y] = true; q.push({x, y}); } } if(sea == false) { land = true; } } return land; } int main() { cin >>n; int cnt = 0; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { cin >> s[i][j]; } } for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { if(t[i][j] == false && s[i][j] == '#') { bool f = bfs({i, j}); if(f) ans ++; cnt ++; } } } cout << cnt - ans << endl; }